]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/UefiHiiLib/HiiLib.c
MdeModulePkg/UefiHiiLib: Fix incorrect check for string length
[mirror_edk2.git] / MdeModulePkg / Library / UefiHiiLib / HiiLib.c
CommitLineData
08e4b3cf 1/** @file\r
2 HII Library implementation that uses DXE protocols and services.\r
3\r
9f4048f7 4 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
cd5ebaa0 5 This program and the accompanying materials\r
08e4b3cf 6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "InternalHiiLib.h"\r
16\r
84f9a9ec
LG
17#define GUID_CONFIG_STRING_TYPE 0x00\r
18#define NAME_CONFIG_STRING_TYPE 0x01\r
19#define PATH_CONFIG_STRING_TYPE 0x02\r
20\r
21#define ACTION_SET_DEFAUTL_VALUE 0x01\r
22#define ACTION_VALIDATE_SETTING 0x02\r
23\r
24#define HII_LIB_DEFAULT_VARSTORE_SIZE 0x200\r
25\r
26typedef struct {\r
27 LIST_ENTRY Entry; // Link to Block array\r
28 UINT16 Offset;\r
29 UINT16 Width;\r
30 UINT8 OpCode;\r
31 UINT8 Scope;\r
32} IFR_BLOCK_DATA;\r
33\r
82e8c138
ED
34typedef struct {\r
35 EFI_VARSTORE_ID VarStoreId;\r
36 UINT16 Size;\r
37} IFR_VARSTORAGE_DATA;\r
38\r
7e3bcccb
LG
39//\r
40// <ConfigHdr> Template\r
41//\r
42GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR16 mConfigHdrTemplate[] = L"GUID=00000000000000000000000000000000&NAME=0000&PATH=00";\r
08e4b3cf 43\r
cb7d01c0 44EFI_FORM_BROWSER2_PROTOCOL *mUefiFormBrowser2 = NULL;\r
45\r
7e3bcccb 46//\r
cb7d01c0 47// Template used to mark the end of a list of packages \r
7e3bcccb 48//\r
cb7d01c0 49GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_HII_PACKAGE_HEADER mEndOfPakageList = {\r
50 sizeof (EFI_HII_PACKAGE_HEADER),\r
51 EFI_HII_PACKAGE_END\r
52};\r
08e4b3cf 53\r
84f9a9ec
LG
54/**\r
55 Extract Hii package list GUID for given HII handle.\r
56\r
57 If HiiHandle could not be found in the HII database, then ASSERT.\r
58 If Guid is NULL, then ASSERT.\r
59\r
60 @param Handle Hii handle\r
61 @param Guid Package list GUID\r
62\r
63 @retval EFI_SUCCESS Successfully extract GUID from Hii database.\r
64\r
65**/\r
66EFI_STATUS\r
67EFIAPI\r
68InternalHiiExtractGuidFromHiiHandle (\r
69 IN EFI_HII_HANDLE Handle,\r
70 OUT EFI_GUID *Guid\r
71 )\r
72{\r
73 EFI_STATUS Status;\r
74 UINTN BufferSize;\r
75 EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;\r
76\r
77 ASSERT (Guid != NULL);\r
78 ASSERT (Handle != NULL);\r
79\r
80 //\r
81 // Get HII PackageList\r
82 //\r
83 BufferSize = 0;\r
84 HiiPackageList = NULL;\r
85\r
86 Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &BufferSize, HiiPackageList);\r
87 ASSERT (Status != EFI_NOT_FOUND);\r
88 \r
89 if (Status == EFI_BUFFER_TOO_SMALL) {\r
90 HiiPackageList = AllocatePool (BufferSize);\r
91 ASSERT (HiiPackageList != NULL);\r
92\r
93 Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &BufferSize, HiiPackageList);\r
94 }\r
95 if (EFI_ERROR (Status)) {\r
96 FreePool (HiiPackageList);\r
97 return Status;\r
98 }\r
99\r
100 //\r
101 // Extract GUID\r
102 //\r
103 CopyGuid (Guid, &HiiPackageList->PackageListGuid);\r
104\r
105 FreePool (HiiPackageList);\r
106\r
107 return EFI_SUCCESS;\r
108}\r
109\r
08e4b3cf 110/**\r
cb7d01c0 111 Registers a list of packages in the HII Database and returns the HII Handle\r
112 associated with that registration. If an HII Handle has already been registered\r
aa2614b7 113 with the same PackageListGuid and DeviceHandle, then NULL is returned. If there\r
114 are not enough resources to perform the registration, then NULL is returned.\r
115 If an empty list of packages is passed in, then NULL is returned. If the size of\r
116 the list of package is 0, then NULL is returned.\r
cb7d01c0 117\r
118 The variable arguments are pointers which point to package header that defined \r
119 by UEFI VFR compiler and StringGather tool.\r
08e4b3cf 120\r
121 #pragma pack (push, 1)\r
122 typedef struct {\r
123 UINT32 BinaryLength;\r
124 EFI_HII_PACKAGE_HEADER PackageHeader;\r
125 } EDKII_AUTOGEN_PACKAGES_HEADER;\r
126 #pragma pack (pop)\r
cb7d01c0 127 \r
128 @param[in] PackageListGuid The GUID of the package list.\r
129 @param[in] DeviceHandle If not NULL, the Device Handle on which \r
130 an instance of DEVICE_PATH_PROTOCOL is installed.\r
131 This Device Handle uniquely defines the device that \r
132 the added packages are associated with.\r
133 @param[in] ... The variable argument list that contains pointers \r
134 to packages terminated by a NULL.\r
135\r
136 @retval NULL A HII Handle has already been registered in the HII Database with\r
9c6595dc 137 the same PackageListGuid and DeviceHandle.\r
cb7d01c0 138 @retval NULL The HII Handle could not be created.\r
139 @retval NULL An empty list of packages was passed in.\r
140 @retval NULL All packages are empty.\r
141 @retval Other The HII Handle associated with the newly registered package list.\r
08e4b3cf 142\r
143**/\r
cb7d01c0 144EFI_HII_HANDLE\r
145EFIAPI\r
146HiiAddPackages (\r
147 IN CONST EFI_GUID *PackageListGuid,\r
148 IN EFI_HANDLE DeviceHandle OPTIONAL,\r
149 ...\r
08e4b3cf 150 )\r
151{\r
cb7d01c0 152 EFI_STATUS Status;\r
cb7d01c0 153 VA_LIST Args;\r
154 UINT32 *Package;\r
155 EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader;\r
156 EFI_HII_HANDLE HiiHandle;\r
157 UINT32 Length;\r
158 UINT8 *Data;\r
08e4b3cf 159\r
cb7d01c0 160 ASSERT (PackageListGuid != NULL);\r
08e4b3cf 161\r
08e4b3cf 162 //\r
cb7d01c0 163 // Calculate the length of all the packages in the variable argument list\r
08e4b3cf 164 //\r
cb7d01c0 165 for (Length = 0, VA_START (Args, DeviceHandle); (Package = VA_ARG (Args, UINT32 *)) != NULL; ) {\r
166 Length += (ReadUnaligned32 (Package) - sizeof (UINT32));\r
167 }\r
168 VA_END (Args);\r
08e4b3cf 169\r
08e4b3cf 170 //\r
cb7d01c0 171 // If there are no packages in the variable argument list or all the packages \r
172 // are empty, then return a NULL HII Handle\r
08e4b3cf 173 //\r
cb7d01c0 174 if (Length == 0) {\r
175 return NULL;\r
08e4b3cf 176 }\r
177\r
178 //\r
cb7d01c0 179 // Add the length of the Package List Header and the terminating Package Header \r
08e4b3cf 180 //\r
cb7d01c0 181 Length += sizeof (EFI_HII_PACKAGE_LIST_HEADER) + sizeof (EFI_HII_PACKAGE_HEADER);\r
08e4b3cf 182\r
cb7d01c0 183 //\r
184 // Allocate the storage for the entire Package List\r
185 //\r
186 PackageListHeader = AllocateZeroPool (Length);\r
08e4b3cf 187\r
cb7d01c0 188 //\r
aa2614b7 189 // If the Package List can not be allocated, then return a NULL HII Handle\r
cb7d01c0 190 //\r
191 if (PackageListHeader == NULL) {\r
192 return NULL;\r
193 }\r
08e4b3cf 194\r
cb7d01c0 195 //\r
196 // Fill in the GUID and Length of the Package List Header\r
197 //\r
198 CopyGuid (&PackageListHeader->PackageListGuid, PackageListGuid);\r
199 PackageListHeader->PackageLength = Length;\r
08e4b3cf 200\r
cb7d01c0 201 //\r
202 // Initialize a pointer to the beginning if the Package List data\r
203 //\r
204 Data = (UINT8 *)(PackageListHeader + 1);\r
08e4b3cf 205\r
cb7d01c0 206 //\r
207 // Copy the data from each package in the variable argument list\r
208 //\r
209 for (VA_START (Args, DeviceHandle); (Package = VA_ARG (Args, UINT32 *)) != NULL; ) {\r
210 Length = ReadUnaligned32 (Package) - sizeof (UINT32);\r
211 CopyMem (Data, Package + 1, Length);\r
212 Data += Length;\r
213 }\r
214 VA_END (Args);\r
08e4b3cf 215\r
cb7d01c0 216 //\r
217 // Append a package of type EFI_HII_PACKAGE_END to mark the end of the package list\r
218 //\r
219 CopyMem (Data, &mEndOfPakageList, sizeof (mEndOfPakageList));\r
08e4b3cf 220\r
cb7d01c0 221 //\r
222 // Register the package list with the HII Database\r
223 //\r
224 Status = gHiiDatabase->NewPackageList (\r
225 gHiiDatabase, \r
226 PackageListHeader, \r
227 DeviceHandle, \r
228 &HiiHandle\r
229 );\r
230 if (EFI_ERROR (Status)) {\r
231 HiiHandle = NULL;\r
08e4b3cf 232 }\r
233\r
cb7d01c0 234 //\r
235 // Free the allocated package list\r
236 //\r
08e4b3cf 237 FreePool (PackageListHeader);\r
cb7d01c0 238\r
239 //\r
240 // Return the new HII Handle\r
241 //\r
242 return HiiHandle;\r
08e4b3cf 243}\r
244\r
245/**\r
cb7d01c0 246 Removes a package list from the HII database.\r
08e4b3cf 247\r
248 If HiiHandle is NULL, then ASSERT.\r
cb7d01c0 249 If HiiHandle is not a valid EFI_HII_HANDLE in the HII database, then ASSERT.\r
08e4b3cf 250\r
cb7d01c0 251 @param[in] HiiHandle The handle that was previously registered in the HII database\r
08e4b3cf 252\r
253**/\r
254VOID\r
255EFIAPI\r
cb7d01c0 256HiiRemovePackages (\r
08e4b3cf 257 IN EFI_HII_HANDLE HiiHandle\r
258 )\r
259{\r
260 EFI_STATUS Status;\r
08e4b3cf 261\r
cb7d01c0 262 ASSERT (HiiHandle != NULL);\r
7e3bcccb 263 Status = gHiiDatabase->RemovePackageList (gHiiDatabase, HiiHandle);\r
08e4b3cf 264 ASSERT_EFI_ERROR (Status);\r
265}\r
266\r
267\r
268/**\r
7992c0b0 269 Retrieves the array of all the HII Handles or the HII handles of a specific\r
270 package list GUID in the HII Database.\r
cb7d01c0 271 This array is terminated with a NULL HII Handle.\r
272 This function allocates the returned array using AllocatePool().\r
273 The caller is responsible for freeing the array with FreePool().\r
274\r
275 @param[in] PackageListGuid An optional parameter that is used to request \r
7992c0b0 276 HII Handles associated with a specific\r
277 Package List GUID. If this parameter is NULL,\r
cb7d01c0 278 then all the HII Handles in the HII Database\r
7992c0b0 279 are returned. If this parameter is not NULL,\r
280 then zero or more HII Handles associated with \r
281 PackageListGuid are returned.\r
cb7d01c0 282\r
283 @retval NULL No HII handles were found in the HII database\r
284 @retval NULL The array of HII Handles could not be retrieved\r
285 @retval Other A pointer to the NULL terminated array of HII Handles\r
08e4b3cf 286\r
287**/\r
cb7d01c0 288EFI_HII_HANDLE *\r
08e4b3cf 289EFIAPI\r
cb7d01c0 290HiiGetHiiHandles (\r
291 IN CONST EFI_GUID *PackageListGuid OPTIONAL\r
08e4b3cf 292 )\r
293{\r
cb7d01c0 294 EFI_STATUS Status;\r
295 UINTN HandleBufferLength;\r
296 EFI_HII_HANDLE TempHiiHandleBuffer;\r
297 EFI_HII_HANDLE *HiiHandleBuffer;\r
298 EFI_GUID Guid;\r
7992c0b0 299 UINTN Index1;\r
300 UINTN Index2;\r
cb7d01c0 301\r
302 //\r
303 // Retrieve the size required for the buffer of all HII handles.\r
304 //\r
305 HandleBufferLength = 0;\r
306 Status = gHiiDatabase->ListPackageLists (\r
307 gHiiDatabase,\r
308 EFI_HII_PACKAGE_TYPE_ALL,\r
309 NULL,\r
310 &HandleBufferLength,\r
311 &TempHiiHandleBuffer\r
312 );\r
08e4b3cf 313\r
cb7d01c0 314 //\r
315 // If ListPackageLists() returns EFI_SUCCESS for a zero size, \r
316 // then there are no HII handles in the HII database. If ListPackageLists() \r
317 // returns an error other than EFI_BUFFER_TOO_SMALL, then there are no HII \r
318 // handles in the HII database.\r
319 //\r
320 if (Status != EFI_BUFFER_TOO_SMALL) {\r
321 //\r
322 // Return NULL if the size can not be retrieved, or if there are no HII \r
323 // handles in the HII Database\r
324 //\r
325 return NULL;\r
326 }\r
08e4b3cf 327\r
cb7d01c0 328 //\r
329 // Allocate the array of HII handles to hold all the HII Handles and a NULL terminator\r
330 //\r
331 HiiHandleBuffer = AllocateZeroPool (HandleBufferLength + sizeof (EFI_HII_HANDLE));\r
332 if (HiiHandleBuffer == NULL) {\r
333 //\r
334 // Return NULL if allocation fails.\r
335 //\r
336 return NULL;\r
337 }\r
08e4b3cf 338\r
339 //\r
cb7d01c0 340 // Retrieve the array of HII Handles in the HII Database\r
08e4b3cf 341 //\r
7e3bcccb 342 Status = gHiiDatabase->ListPackageLists (\r
cb7d01c0 343 gHiiDatabase,\r
344 EFI_HII_PACKAGE_TYPE_ALL,\r
345 NULL,\r
346 &HandleBufferLength,\r
347 HiiHandleBuffer\r
348 );\r
349 if (EFI_ERROR (Status)) {\r
350 //\r
351 // Free the buffer and return NULL if the HII handles can not be retrieved.\r
352 //\r
353 FreePool (HiiHandleBuffer);\r
354 return NULL;\r
fa7b3168 355 }\r
08e4b3cf 356\r
cb7d01c0 357 if (PackageListGuid == NULL) {\r
358 //\r
359 // Return the NULL terminated array of HII handles in the HII Database\r
360 //\r
361 return HiiHandleBuffer;\r
362 } else {\r
7992c0b0 363 for (Index1 = 0, Index2 = 0; HiiHandleBuffer[Index1] != NULL; Index1++) {\r
364 Status = InternalHiiExtractGuidFromHiiHandle (HiiHandleBuffer[Index1], &Guid);\r
cb7d01c0 365 ASSERT_EFI_ERROR (Status);\r
366 if (CompareGuid (&Guid, PackageListGuid)) {\r
7992c0b0 367 HiiHandleBuffer[Index2++] = HiiHandleBuffer[Index1]; \r
cb7d01c0 368 }\r
369 }\r
7992c0b0 370 if (Index2 > 0) {\r
371 HiiHandleBuffer[Index2] = NULL;\r
372 return HiiHandleBuffer;\r
373 } else {\r
374 FreePool (HiiHandleBuffer);\r
375 return NULL;\r
376 }\r
cb7d01c0 377 }\r
08e4b3cf 378}\r
379\r
8a458283
DB
380/**\r
381 This function allows a caller to extract the form set opcode form the Hii Handle.\r
382 The returned buffer is allocated using AllocatePool().The caller is responsible \r
383 for freeing the allocated buffer using FreePool().\r
384\r
385 @param Handle The HII handle.\r
3b28e744 386 @param Buffer On return, points to a pointer which point to the buffer that contain the formset opcode.\r
8a458283
DB
387 @param BufferSize On return, points to the length of the buffer.\r
388\r
389 @retval EFI_OUT_OF_RESOURCES No enough memory resource is allocated.\r
390 @retval EFI_NOT_FOUND Can't find the package data for the input Handle.\r
391 @retval EFI_INVALID_PARAMETER The input parameters are not correct.\r
3b28e744 392 @retval EFI_SUCCESS Get the formset opcode from the hii handle successfully.\r
8a458283
DB
393\r
394**/\r
395EFI_STATUS\r
396EFIAPI\r
397HiiGetFormSetFromHiiHandle(\r
398 IN EFI_HII_HANDLE Handle,\r
399 OUT EFI_IFR_FORM_SET **Buffer,\r
400 OUT UINTN *BufferSize\r
401 )\r
402{\r
403 EFI_STATUS Status;\r
404 UINTN PackageListSize;\r
405 UINTN TempSize;\r
406 EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;\r
407 UINT8 *Package;\r
408 UINT8 *OpCodeData;\r
d6cc284e
DB
409 UINT8 *FormSetBuffer;\r
410 UINT8 *TempBuffer;\r
8a458283
DB
411 UINT32 Offset;\r
412 UINT32 Offset2;\r
413 UINT32 PackageListLength;\r
414 EFI_HII_PACKAGE_HEADER PackageHeader;\r
415\r
416 TempSize = 0;\r
417 FormSetBuffer = NULL;\r
418 TempBuffer = NULL;\r
419\r
420 //\r
421 // Get HII PackageList\r
422 //\r
423 PackageListSize = 0;\r
424 HiiPackageList = NULL;\r
425 Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &PackageListSize, HiiPackageList);\r
426 if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {\r
427 return Status;\r
428 }\r
429\r
430 HiiPackageList = AllocatePool (PackageListSize);\r
431 if (HiiPackageList == NULL) {\r
432 return EFI_OUT_OF_RESOURCES;\r
433 }\r
434\r
435 Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &PackageListSize, HiiPackageList);\r
436 ASSERT_EFI_ERROR (Status);\r
437\r
438 //\r
439 // Get Form package from this HII package List\r
440 //\r
441 Status = EFI_NOT_FOUND;\r
442 Offset = sizeof (EFI_HII_PACKAGE_LIST_HEADER);\r
443 PackageListLength = ReadUnaligned32 (&HiiPackageList->PackageLength);\r
444\r
445 while (Offset < PackageListLength) {\r
446 Package = ((UINT8 *) HiiPackageList) + Offset;\r
447 CopyMem (&PackageHeader, Package, sizeof (EFI_HII_PACKAGE_HEADER));\r
448 Offset += PackageHeader.Length;\r
449\r
450 if (PackageHeader.Type != EFI_HII_PACKAGE_FORMS) {\r
451 continue;\r
452 }\r
453\r
454 //\r
455 // Search FormSet Opcode in this Form Package\r
456 //\r
457 Offset2 = sizeof (EFI_HII_PACKAGE_HEADER);\r
458 while (Offset2 < PackageHeader.Length) {\r
459 OpCodeData = Package + Offset2;\r
460 Offset2 += ((EFI_IFR_OP_HEADER *) OpCodeData)->Length;\r
461\r
462 if (((EFI_IFR_OP_HEADER *) OpCodeData)->OpCode != EFI_IFR_FORM_SET_OP) {\r
463 continue;\r
464 }\r
465\r
466 if (FormSetBuffer != NULL){\r
467 TempBuffer = AllocateCopyPool (TempSize + ((EFI_IFR_OP_HEADER *) OpCodeData)->Length, FormSetBuffer);\r
8a458283 468 FreePool(FormSetBuffer);\r
ae9026dd
BD
469 FormSetBuffer = NULL;\r
470 if (TempBuffer == NULL) {\r
471 Status = EFI_OUT_OF_RESOURCES;\r
472 goto Done;\r
473 }\r
474 CopyMem (TempBuffer + TempSize, OpCodeData, ((EFI_IFR_OP_HEADER *) OpCodeData)->Length);\r
8a458283
DB
475 } else {\r
476 TempBuffer = AllocateCopyPool (TempSize + ((EFI_IFR_OP_HEADER *) OpCodeData)->Length, OpCodeData);\r
ae9026dd
BD
477 if (TempBuffer == NULL) {\r
478 Status = EFI_OUT_OF_RESOURCES;\r
479 goto Done;\r
480 }\r
8a458283
DB
481 }\r
482 TempSize += ((EFI_IFR_OP_HEADER *) OpCodeData)->Length;\r
483 FormSetBuffer = TempBuffer;\r
484\r
485 Status = EFI_SUCCESS;\r
486 //\r
487 //One form package has one formset, exit current form package to search other form package in the packagelist.\r
488 //\r
489 break;\r
490 }\r
491 }\r
ae9026dd 492Done:\r
8a458283
DB
493 FreePool (HiiPackageList);\r
494\r
495 *BufferSize = TempSize;\r
d6cc284e 496 *Buffer = (EFI_IFR_FORM_SET *)FormSetBuffer;\r
8a458283
DB
497\r
498 return Status;\r
499}\r
500\r
7e3bcccb
LG
501/**\r
502 Converts all hex dtring characters in range ['A'..'F'] to ['a'..'f'] for \r
503 hex digits that appear between a '=' and a '&' in a config string.\r
504\r
84213069 505 If ConfigString is NULL, then ASSERT().\r
7e3bcccb 506\r
84213069 507 @param[in] ConfigString Pointer to a Null-terminated Unicode string.\r
7e3bcccb
LG
508\r
509 @return Pointer to the Null-terminated Unicode result string.\r
510\r
511**/\r
512EFI_STRING\r
513EFIAPI\r
514InternalHiiLowerConfigString (\r
515 IN EFI_STRING ConfigString\r
516 )\r
517{\r
518 EFI_STRING String;\r
519 BOOLEAN Lower;\r
520\r
521 ASSERT (ConfigString != NULL);\r
522\r
523 //\r
524 // Convert all hex digits in range [A-F] in the configuration header to [a-f]\r
525 //\r
526 for (String = ConfigString, Lower = FALSE; *String != L'\0'; String++) {\r
527 if (*String == L'=') {\r
528 Lower = TRUE;\r
529 } else if (*String == L'&') {\r
530 Lower = FALSE;\r
3e3f86e0 531 } else if (Lower && *String >= L'A' && *String <= L'F') {\r
5c1ebff6 532 *String = (CHAR16) (*String - L'A' + L'a');\r
7e3bcccb
LG
533 }\r
534 }\r
535\r
536 return ConfigString;\r
537}\r
538\r
539/**\r
540 Uses the BlockToConfig() service of the Config Routing Protocol to \r
541 convert <ConfigRequest> and a buffer to a <ConfigResp>\r
542\r
543 If ConfigRequest is NULL, then ASSERT().\r
544 If Block is NULL, then ASSERT().\r
545\r
546 @param[in] ConfigRequest Pointer to a Null-terminated Unicode string.\r
547 @param[in] Block Pointer to a block of data.\r
548 @param[in] BlockSize The zie, in bytes, of Block.\r
549\r
550 @retval NULL The <ConfigResp> string could not be generated.\r
551 @retval Other Pointer to the Null-terminated Unicode <ConfigResp> string.\r
552\r
553**/\r
554EFI_STRING\r
555EFIAPI\r
556InternalHiiBlockToConfig (\r
557 IN CONST EFI_STRING ConfigRequest,\r
558 IN CONST UINT8 *Block,\r
559 IN UINTN BlockSize\r
560 )\r
561{\r
562 EFI_STATUS Status;\r
563 EFI_STRING ConfigResp;\r
564 CHAR16 *Progress;\r
565\r
566 ASSERT (ConfigRequest != NULL);\r
567 ASSERT (Block != NULL);\r
568\r
569 //\r
570 // Convert <ConfigRequest> to <ConfigResp>\r
571 //\r
572 Status = gHiiConfigRouting->BlockToConfig (\r
573 gHiiConfigRouting,\r
574 ConfigRequest,\r
575 Block,\r
576 BlockSize,\r
577 &ConfigResp,\r
578 &Progress\r
579 );\r
580 if (EFI_ERROR (Status)) {\r
581 return NULL;\r
582 }\r
583 return ConfigResp;\r
584}\r
585\r
7e3bcccb
LG
586/**\r
587 Uses the BrowserCallback() service of the Form Browser Protocol to retrieve \r
588 or set uncommitted data. If sata i being retrieved, then the buffer is \r
589 allocated using AllocatePool(). The caller is then responsible for freeing \r
590 the buffer using FreePool().\r
591\r
7e3bcccb
LG
592 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional \r
593 parameter that may be NULL.\r
84213069
LG
594 @param[in] VariableName Pointer to a Null-terminated Unicode string. This \r
595 is an optional parameter that may be NULL.\r
7e3bcccb
LG
596 @param[in] SetResultsData If not NULL, then this parameter specified the buffer\r
597 of uncommited data to set. If this parameter is NULL,\r
598 then the caller is requesting to get the uncommited data\r
599 from the Form Browser.\r
600\r
601 @retval NULL The uncommitted data could not be retrieved.\r
602 @retval Other A pointer to a buffer containing the uncommitted data.\r
603\r
604**/\r
605EFI_STRING\r
606EFIAPI\r
607InternalHiiBrowserCallback (\r
608 IN CONST EFI_GUID *VariableGuid, OPTIONAL\r
609 IN CONST CHAR16 *VariableName, OPTIONAL\r
610 IN CONST EFI_STRING SetResultsData OPTIONAL\r
611 )\r
612{\r
613 EFI_STATUS Status;\r
614 UINTN ResultsDataSize;\r
615 EFI_STRING ResultsData;\r
616 CHAR16 TempResultsData;\r
617\r
618 //\r
619 // Locate protocols\r
620 //\r
3c7449e4
LG
621 if (mUefiFormBrowser2 == NULL) {\r
622 Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &mUefiFormBrowser2);\r
623 if (EFI_ERROR (Status) || mUefiFormBrowser2 == NULL) {\r
7e3bcccb
LG
624 return NULL;\r
625 }\r
626 }\r
627\r
628 ResultsDataSize = 0;\r
629\r
630 if (SetResultsData != NULL) {\r
631 //\r
632 // Request to to set data in the uncommitted browser state information\r
633 //\r
634 ResultsData = SetResultsData;\r
635 } else {\r
636 //\r
637 // Retrieve the length of the buffer required ResultsData from the Browser Callback\r
638 //\r
3c7449e4
LG
639 Status = mUefiFormBrowser2->BrowserCallback (\r
640 mUefiFormBrowser2,\r
7e3bcccb
LG
641 &ResultsDataSize,\r
642 &TempResultsData,\r
643 TRUE,\r
644 VariableGuid,\r
645 VariableName\r
646 );\r
6412128a
LG
647 \r
648 if (!EFI_ERROR (Status)) {\r
649 //\r
650 // No Resluts Data, only allocate one char for '\0'\r
651 //\r
652 ResultsData = AllocateZeroPool (sizeof (CHAR16));\r
653 return ResultsData;\r
654 }\r
655\r
7e3bcccb
LG
656 if (Status != EFI_BUFFER_TOO_SMALL) {\r
657 return NULL;\r
658 }\r
659\r
660 //\r
661 // Allocate the ResultsData buffer\r
662 //\r
663 ResultsData = AllocateZeroPool (ResultsDataSize);\r
664 if (ResultsData == NULL) {\r
665 return NULL;\r
666 }\r
667 }\r
668\r
669 //\r
670 // Retrieve or set the ResultsData from the Browser Callback\r
671 //\r
3c7449e4
LG
672 Status = mUefiFormBrowser2->BrowserCallback (\r
673 mUefiFormBrowser2,\r
7e3bcccb
LG
674 &ResultsDataSize,\r
675 ResultsData,\r
676 (BOOLEAN)(SetResultsData == NULL),\r
677 VariableGuid,\r
678 VariableName\r
679 );\r
680 if (EFI_ERROR (Status)) {\r
681 return NULL;\r
682 }\r
683\r
684 return ResultsData;\r
685}\r
686\r
687/**\r
688 Allocates and returns a Null-terminated Unicode <ConfigHdr> string using routing \r
689 information that includes a GUID, an optional Unicode string name, and a device\r
690 path. The string returned is allocated with AllocatePool(). The caller is \r
691 responsible for freeing the allocated string with FreePool().\r
692 \r
693 The format of a <ConfigHdr> is as follows:\r
694\r
695 GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize<Null>\r
696\r
697 @param[in] Guid Pointer to an EFI_GUID that is the routing information\r
698 GUID. Each of the 16 bytes in Guid is converted to \r
3b28e744 699 a 2 Unicode character hexadecimal string. This is\r
7e3bcccb
LG
700 an optional parameter that may be NULL.\r
701 @param[in] Name Pointer to a Null-terminated Unicode string that is \r
702 the routing information NAME. This is an optional \r
703 parameter that may be NULL. Each 16-bit Unicode \r
704 character in Name is converted to a 4 character Unicode \r
3b28e744 705 hexadecimal string.\r
7e3bcccb
LG
706 @param[in] DriverHandle The driver handle which supports a Device Path Protocol\r
707 that is the routing information PATH. Each byte of\r
708 the Device Path associated with DriverHandle is converted\r
3b28e744 709 to a 2 Unicode character hexadecimal string.\r
7e3bcccb 710\r
7e3bcccb
LG
711 @retval NULL DriverHandle does not support the Device Path Protocol.\r
712 @retval Other A pointer to the Null-terminate Unicode <ConfigHdr> string\r
713\r
714**/\r
715EFI_STRING\r
716EFIAPI\r
717HiiConstructConfigHdr (\r
718 IN CONST EFI_GUID *Guid, OPTIONAL\r
719 IN CONST CHAR16 *Name, OPTIONAL\r
720 IN EFI_HANDLE DriverHandle\r
721 )\r
722{\r
723 UINTN NameLength;\r
724 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
725 UINTN DevicePathSize;\r
726 CHAR16 *String;\r
727 CHAR16 *ReturnString;\r
728 UINTN Index;\r
729 UINT8 *Buffer;\r
5ad66ec6 730 UINTN MaxLen;\r
7e3bcccb
LG
731\r
732 //\r
733 // Compute the length of Name in Unicode characters. \r
734 // If Name is NULL, then the length is 0.\r
735 //\r
736 NameLength = 0;\r
737 if (Name != NULL) {\r
738 NameLength = StrLen (Name);\r
739 }\r
740\r
3e3f86e0
LG
741 DevicePath = NULL;\r
742 DevicePathSize = 0;\r
7e3bcccb
LG
743 //\r
744 // Retrieve DevicePath Protocol associated with DriverHandle\r
745 //\r
3e3f86e0
LG
746 if (DriverHandle != NULL) {\r
747 DevicePath = DevicePathFromHandle (DriverHandle);\r
748 if (DevicePath == NULL) {\r
749 return NULL;\r
750 }\r
751 //\r
752 // Compute the size of the device path in bytes\r
753 //\r
754 DevicePathSize = GetDevicePathSize (DevicePath);\r
7e3bcccb
LG
755 }\r
756\r
7e3bcccb
LG
757 //\r
758 // GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize <Null>\r
759 // | 5 | sizeof (EFI_GUID) * 2 | 6 | NameStrLen*4 | 6 | DevicePathSize * 2 | 1 |\r
760 //\r
5ad66ec6
DB
761 MaxLen = 5 + sizeof (EFI_GUID) * 2 + 6 + NameLength * 4 + 6 + DevicePathSize * 2 + 1;\r
762 String = AllocateZeroPool (MaxLen * sizeof (CHAR16));\r
7e3bcccb
LG
763 if (String == NULL) {\r
764 return NULL;\r
765 }\r
766\r
767 //\r
768 // Start with L"GUID="\r
769 //\r
5ad66ec6
DB
770 StrCpyS (String, MaxLen, L"GUID=");\r
771 ReturnString = String;\r
7e3bcccb
LG
772 String += StrLen (String);\r
773\r
774 if (Guid != NULL) {\r
775 //\r
776 // Append Guid converted to <HexCh>32\r
777 //\r
778 for (Index = 0, Buffer = (UINT8 *)Guid; Index < sizeof (EFI_GUID); Index++) {\r
9f4048f7
HW
779 UnicodeValueToStringS (\r
780 String,\r
781 MaxLen * sizeof (CHAR16) - ((UINTN)String - (UINTN)ReturnString),\r
782 PREFIX_ZERO | RADIX_HEX,\r
783 *(Buffer++),\r
784 2\r
785 );\r
786 String += StrnLenS (String, MaxLen - ((UINTN)String - (UINTN)ReturnString) / sizeof (CHAR16));\r
7e3bcccb
LG
787 }\r
788 }\r
789 \r
790 //\r
791 // Append L"&NAME="\r
792 //\r
2d3e4cd1 793 StrCatS (ReturnString, MaxLen, L"&NAME=");\r
7e3bcccb
LG
794 String += StrLen (String);\r
795\r
796 if (Name != NULL) {\r
797 //\r
798 // Append Name converted to <Char>NameLength\r
799 //\r
800 for (; *Name != L'\0'; Name++) {\r
9f4048f7
HW
801 UnicodeValueToStringS (\r
802 String,\r
803 sizeof (CHAR16) * MaxLen - ((UINTN)String - (UINTN)ReturnString),\r
804 PREFIX_ZERO | RADIX_HEX,\r
805 *Name,\r
806 4\r
807 );\r
808 String += StrnLenS (String, MaxLen - ((UINTN)String - (UINTN)ReturnString) / sizeof (CHAR16));\r
7e3bcccb
LG
809 }\r
810 }\r
811\r
812 //\r
813 // Append L"&PATH="\r
814 //\r
2d3e4cd1 815 StrCatS (ReturnString, MaxLen, L"&PATH=");\r
7e3bcccb
LG
816 String += StrLen (String);\r
817\r
818 //\r
819 // Append the device path associated with DriverHandle converted to <HexChar>DevicePathSize\r
820 //\r
821 for (Index = 0, Buffer = (UINT8 *)DevicePath; Index < DevicePathSize; Index++) {\r
9f4048f7
HW
822 UnicodeValueToStringS (\r
823 String,\r
824 sizeof (CHAR16) * MaxLen - ((UINTN)String - (UINTN)ReturnString),\r
825 PREFIX_ZERO | RADIX_HEX,\r
826 *(Buffer++),\r
827 2\r
828 );\r
829 String += StrnLenS (String, MaxLen - ((UINTN)String - (UINTN)ReturnString) / sizeof (CHAR16));\r
7e3bcccb
LG
830 }\r
831\r
832 //\r
833 // Null terminate the Unicode string\r
834 //\r
835 *String = L'\0';\r
836\r
837 //\r
838 // Convert all hex digits in range [A-F] in the configuration header to [a-f]\r
839 //\r
840 return InternalHiiLowerConfigString (ReturnString);\r
841}\r
842\r
84f9a9ec
LG
843/**\r
844 Convert the hex UNICODE encoding string of UEFI GUID, NAME or device path \r
845 to binary buffer from <ConfigHdr>.\r
846\r
847 This is a internal function.\r
848\r
849 @param String UEFI configuration string.\r
850 @param Flag Flag specifies what type buffer will be retrieved.\r
851 @param Buffer Binary of Guid, Name or Device path.\r
852\r
853 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.\r
854 @retval EFI_OUT_OF_RESOURCES Lake of resources to store neccesary structures.\r
855 @retval EFI_SUCCESS The buffer data is retrieved and translated to\r
856 binary format.\r
857\r
858**/\r
859EFI_STATUS\r
860InternalHiiGetBufferFromString (\r
861 IN EFI_STRING String,\r
862 IN UINT8 Flag,\r
863 OUT UINT8 **Buffer\r
864 )\r
865{\r
866 UINTN Length;\r
867 EFI_STRING ConfigHdr;\r
868 CHAR16 *StringPtr;\r
869 UINT8 *DataBuffer;\r
870 CHAR16 TemStr[5];\r
871 UINTN Index;\r
872 UINT8 DigitUint8;\r
873\r
874 if (String == NULL || Buffer == NULL) {\r
875 return EFI_INVALID_PARAMETER;\r
876 }\r
877 \r
878 DataBuffer = NULL;\r
879 StringPtr = NULL;\r
880 ConfigHdr = String;\r
881 //\r
882 // The content between 'GUID', 'NAME', 'PATH' of <ConfigHdr> and '&' of next element\r
883 // or '\0' (end of configuration string) is the UNICODE %02x bytes encoding string.\r
884 //\r
885 for (Length = 0; *String != 0 && *String != L'&'; String++, Length++);\r
886\r
887 switch (Flag) {\r
888 case GUID_CONFIG_STRING_TYPE:\r
889 case PATH_CONFIG_STRING_TYPE:\r
890 //\r
891 // The data in <ConfigHdr> is encoded as hex UNICODE %02x bytes in the same order\r
892 // as the device path and Guid resides in RAM memory.\r
893 // Translate the data into binary.\r
894 //\r
895 DataBuffer = (UINT8 *) AllocateZeroPool ((Length + 1) / 2);\r
896 if (DataBuffer == NULL) {\r
897 return EFI_OUT_OF_RESOURCES;\r
898 }\r
899 //\r
900 // Convert binary byte one by one\r
901 //\r
902 ZeroMem (TemStr, sizeof (TemStr));\r
903 for (Index = 0; Index < Length; Index ++) {\r
904 TemStr[0] = ConfigHdr[Index];\r
905 DigitUint8 = (UINT8) StrHexToUint64 (TemStr);\r
906 if ((Index & 1) == 0) {\r
907 DataBuffer [Index/2] = DigitUint8;\r
908 } else {\r
909 DataBuffer [Index/2] = (UINT8) ((DataBuffer [Index/2] << 4) + DigitUint8);\r
910 }\r
911 }\r
912 \r
913 *Buffer = DataBuffer;\r
914 break;\r
915\r
916 case NAME_CONFIG_STRING_TYPE:\r
917 //\r
918 // Convert Config String to Unicode String, e.g. "0041004200430044" => "ABCD"\r
919 // \r
920\r
921 //\r
922 // Add the tailling char L'\0'\r
923 //\r
924 DataBuffer = (UINT8 *) AllocateZeroPool ((Length/4 + 1) * sizeof (CHAR16));\r
925 if (DataBuffer == NULL) {\r
926 return EFI_OUT_OF_RESOURCES;\r
927 }\r
928 //\r
929 // Convert character one by one\r
930 //\r
931 StringPtr = (CHAR16 *) DataBuffer;\r
932 ZeroMem (TemStr, sizeof (TemStr));\r
933 for (Index = 0; Index < Length; Index += 4) {\r
5ad66ec6 934 StrnCpyS (TemStr, sizeof (TemStr) / sizeof (CHAR16), ConfigHdr + Index, 4);\r
84f9a9ec
LG
935 StringPtr[Index/4] = (CHAR16) StrHexToUint64 (TemStr);\r
936 }\r
937 //\r
938 // Add tailing L'\0' character\r
939 //\r
940 StringPtr[Index/4] = L'\0';\r
941\r
942 *Buffer = DataBuffer;\r
943 break;\r
944\r
945 default:\r
946 return EFI_INVALID_PARAMETER;\r
84f9a9ec
LG
947 }\r
948\r
949 return EFI_SUCCESS;\r
950}\r
951\r
952/**\r
953 This function checks VarOffset and VarWidth is in the block range.\r
954\r
955 @param BlockArray The block array is to be checked. \r
956 @param VarOffset Offset of var to the structure\r
957 @param VarWidth Width of var.\r
958 \r
959 @retval TRUE This Var is in the block range.\r
960 @retval FALSE This Var is not in the block range.\r
961**/\r
962BOOLEAN\r
963BlockArrayCheck (\r
964 IN IFR_BLOCK_DATA *BlockArray,\r
965 IN UINT16 VarOffset,\r
966 IN UINT16 VarWidth\r
967 )\r
968{\r
969 LIST_ENTRY *Link;\r
970 IFR_BLOCK_DATA *BlockData;\r
971 \r
972 //\r
973 // No Request Block array, all vars are got.\r
974 //\r
975 if (BlockArray == NULL) {\r
976 return TRUE;\r
977 }\r
978 \r
979 //\r
980 // Check the input var is in the request block range.\r
981 //\r
982 for (Link = BlockArray->Entry.ForwardLink; Link != &BlockArray->Entry; Link = Link->ForwardLink) {\r
983 BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry);\r
984 if ((VarOffset >= BlockData->Offset) && ((VarOffset + VarWidth) <= (BlockData->Offset + BlockData->Width))) {\r
985 return TRUE;\r
986 }\r
987 }\r
988\r
989 return FALSE;\r
990}\r
991\r
992/**\r
993 Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET\r
994 or WIDTH or VALUE.\r
995 <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>\r
996\r
997 @param ValueString String in <BlockConfig> format and points to the\r
998 first character of <Number>.\r
999 @param ValueData The output value. Caller takes the responsibility\r
1000 to free memory.\r
1001 @param ValueLength Length of the <Number>, in characters.\r
1002\r
1003 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary\r
1004 structures.\r
1005 @retval EFI_SUCCESS Value of <Number> is outputted in Number\r
1006 successfully.\r
1007\r
1008**/\r
1009EFI_STATUS\r
1010EFIAPI\r
1011InternalHiiGetValueOfNumber (\r
1012 IN EFI_STRING ValueString,\r
1013 OUT UINT8 **ValueData,\r
1014 OUT UINTN *ValueLength\r
1015 )\r
1016{\r
1017 EFI_STRING StringPtr;\r
1018 UINTN Length;\r
1019 UINT8 *Buf;\r
1020 UINT8 DigitUint8;\r
1021 UINTN Index;\r
1022 CHAR16 TemStr[2];\r
1023\r
1024 ASSERT (ValueString != NULL && ValueData != NULL && ValueLength != NULL);\r
1025 ASSERT (*ValueString != L'\0');\r
1026\r
1027 //\r
1028 // Get the length of value string\r
1029 //\r
1030 StringPtr = ValueString;\r
1031 while (*StringPtr != L'\0' && *StringPtr != L'&') {\r
1032 StringPtr++;\r
1033 }\r
1034 Length = StringPtr - ValueString;\r
1035 \r
1036 //\r
1037 // Allocate buffer to store the value\r
1038 //\r
1039 Buf = (UINT8 *) AllocateZeroPool ((Length + 1) / 2);\r
1040 if (Buf == NULL) {\r
1041 return EFI_OUT_OF_RESOURCES;\r
1042 }\r
1043 \r
1044 //\r
1045 // Convert character one by one to the value buffer\r
1046 //\r
1047 ZeroMem (TemStr, sizeof (TemStr));\r
1048 for (Index = 0; Index < Length; Index ++) {\r
1049 TemStr[0] = ValueString[Length - Index - 1];\r
1050 DigitUint8 = (UINT8) StrHexToUint64 (TemStr);\r
1051 if ((Index & 1) == 0) {\r
1052 Buf [Index/2] = DigitUint8;\r
1053 } else {\r
1054 Buf [Index/2] = (UINT8) ((DigitUint8 << 4) + Buf [Index/2]);\r
1055 }\r
1056 }\r
1057 \r
1058 //\r
1059 // Set the converted value and string length.\r
1060 //\r
1061 *ValueData = Buf;\r
1062 *ValueLength = Length;\r
1063 return EFI_SUCCESS;\r
1064}\r
1065\r
82e8c138
ED
1066/**\r
1067 Get value from config request resp string.\r
1068\r
1069 @param ConfigElement ConfigResp string contains the current setting.\r
1070 @param VarName The variable name which need to get value.\r
1071 @param VarValue The return value.\r
1072 \r
1073 @retval EFI_SUCCESS Get the value for the VarName\r
1074 @retval EFI_OUT_OF_RESOURCES The memory is not enough.\r
1075**/\r
1076EFI_STATUS\r
1077GetValueFromRequest (\r
1078 IN CHAR16 *ConfigElement,\r
1079 IN CHAR16 *VarName,\r
1080 OUT UINT64 *VarValue\r
1081 )\r
1082{\r
1083 UINT8 *TmpBuffer;\r
1084 CHAR16 *StringPtr;\r
1085 UINTN Length;\r
1086 EFI_STATUS Status;\r
1087\r
1088 //\r
1089 // Find VarName related string.\r
1090 //\r
1091 StringPtr = StrStr (ConfigElement, VarName);\r
1092 ASSERT (StringPtr != NULL);\r
1093\r
1094 //\r
1095 // Skip the "VarName=" string\r
1096 //\r
1097 StringPtr += StrLen (VarName) + 1;\r
1098\r
1099 //\r
1100 // Get Offset\r
1101 //\r
1102 Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
1103 if (EFI_ERROR (Status)) {\r
1104 return Status;\r
1105 }\r
1106\r
1107 *VarValue = 0;\r
1108 CopyMem (VarValue, TmpBuffer, (((Length + 1) / 2) < sizeof (UINT64)) ? ((Length + 1) / 2) : sizeof (UINT64));\r
1109\r
1110 FreePool (TmpBuffer);\r
1111\r
1112 return EFI_SUCCESS;\r
1113}\r
1114\r
84f9a9ec 1115/**\r
8567300a
LG
1116 This internal function parses IFR data to validate current setting.\r
1117\r
82e8c138
ED
1118 Base on the NameValueType, if it is TRUE, RequestElement and HiiHandle is valid;\r
1119 else the VarBuffer and CurrentBlockArray is valid.\r
1120\r
8567300a
LG
1121 @param HiiPackageList Point to Hii package list.\r
1122 @param PackageListLength The length of the pacakge.\r
1123 @param VarGuid Guid of the buffer storage.\r
1124 @param VarName Name of the buffer storage.\r
82e8c138
ED
1125 @param VarBuffer The data buffer for the storage.\r
1126 @param CurrentBlockArray The block array from the config Requst string.\r
1127 @param RequestElement The config string for this storage.\r
1128 @param HiiHandle The HiiHandle for this formset.\r
1129 @param NameValueType Whether current storage is name/value varstore or not.\r
84f9a9ec 1130 \r
8567300a
LG
1131 @retval EFI_SUCCESS The current setting is valid.\r
1132 @retval EFI_OUT_OF_RESOURCES The memory is not enough.\r
1133 @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid.\r
84f9a9ec
LG
1134**/\r
1135EFI_STATUS\r
82e8c138 1136ValidateQuestionFromVfr (\r
84f9a9ec
LG
1137 IN EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList,\r
1138 IN UINTN PackageListLength,\r
1139 IN EFI_GUID *VarGuid,\r
82e8c138
ED
1140 IN CHAR16 *VarName,\r
1141 IN UINT8 *VarBuffer,\r
1142 IN IFR_BLOCK_DATA *CurrentBlockArray,\r
1143 IN CHAR16 *RequestElement,\r
1144 IN EFI_HII_HANDLE HiiHandle,\r
1145 IN BOOLEAN NameValueType\r
40ae09a2
ED
1146 )\r
1147{\r
1148 IFR_BLOCK_DATA VarBlockData;\r
40ae09a2
ED
1149 UINT16 Offset;\r
1150 UINT16 Width;\r
1151 UINT64 VarValue;\r
fda93fc4 1152 EFI_IFR_TYPE_VALUE TmpValue;\r
84f9a9ec 1153 EFI_STATUS Status;\r
3b28e744 1154 EFI_HII_PACKAGE_HEADER PackageHeader;\r
84f9a9ec
LG
1155 UINT32 PackageOffset;\r
1156 UINT8 *PackageData;\r
1157 UINTN IfrOffset;\r
1158 EFI_IFR_OP_HEADER *IfrOpHdr;\r
1159 EFI_IFR_VARSTORE *IfrVarStore;\r
82e8c138
ED
1160 EFI_IFR_VARSTORE_NAME_VALUE *IfrNameValueStore;\r
1161 EFI_IFR_VARSTORE_EFI *IfrEfiVarStore;\r
1162 IFR_VARSTORAGE_DATA VarStoreData;\r
84f9a9ec
LG
1163 EFI_IFR_ONE_OF *IfrOneOf;\r
1164 EFI_IFR_NUMERIC *IfrNumeric;\r
1165 EFI_IFR_ONE_OF_OPTION *IfrOneOfOption;\r
1166 EFI_IFR_CHECKBOX *IfrCheckBox;\r
1167 EFI_IFR_STRING *IfrString;\r
1168 CHAR8 *VarStoreName;\r
1169 UINTN Index;\r
82e8c138
ED
1170 CHAR16 *QuestionName;\r
1171 CHAR16 *StringPtr;\r
84f9a9ec 1172\r
84f9a9ec
LG
1173 //\r
1174 // Initialize the local variables.\r
1175 //\r
40ae09a2
ED
1176 Index = 0;\r
1177 VarStoreName = NULL;\r
1178 Status = EFI_SUCCESS;\r
40ae09a2
ED
1179 VarValue = 0;\r
1180 IfrVarStore = NULL;\r
1181 IfrNameValueStore = NULL;\r
82e8c138
ED
1182 IfrEfiVarStore = NULL;\r
1183 ZeroMem (&VarStoreData, sizeof (IFR_VARSTORAGE_DATA));\r
1184 ZeroMem (&VarBlockData, sizeof (VarBlockData));\r
84f9a9ec
LG
1185\r
1186 //\r
82e8c138 1187 // Check IFR value is in block data, then Validate Value\r
84f9a9ec 1188 //\r
84f9a9ec
LG
1189 PackageOffset = sizeof (EFI_HII_PACKAGE_LIST_HEADER);\r
1190 while (PackageOffset < PackageListLength) {\r
3b28e744 1191 CopyMem (&PackageHeader, (UINT8 *) HiiPackageList + PackageOffset, sizeof (PackageHeader));\r
82e8c138 1192\r
84f9a9ec
LG
1193 //\r
1194 // Parse IFR opcode from the form package.\r
1195 //\r
3b28e744
GL
1196 if (PackageHeader.Type == EFI_HII_PACKAGE_FORMS) {\r
1197 IfrOffset = sizeof (PackageHeader);\r
84f9a9ec 1198 PackageData = (UINT8 *) HiiPackageList + PackageOffset;\r
3b28e744 1199 while (IfrOffset < PackageHeader.Length) {\r
84f9a9ec
LG
1200 IfrOpHdr = (EFI_IFR_OP_HEADER *) (PackageData + IfrOffset);\r
1201 //\r
1202 // Validate current setting to the value built in IFR opcode\r
1203 //\r
1204 switch (IfrOpHdr->OpCode) {\r
82e8c138 1205 case EFI_IFR_VARSTORE_OP:\r
84f9a9ec
LG
1206 //\r
1207 // VarStoreId has been found. No further found.\r
1208 //\r
82e8c138 1209 if (VarStoreData.VarStoreId != 0) {\r
84f9a9ec
LG
1210 break;\r
1211 }\r
1212 //\r
1213 // Find the matched VarStoreId to the input VarGuid and VarName\r
8567300a 1214 //\r
84f9a9ec
LG
1215 IfrVarStore = (EFI_IFR_VARSTORE *) IfrOpHdr;\r
1216 if (CompareGuid ((EFI_GUID *) (VOID *) &IfrVarStore->Guid, VarGuid)) {\r
1217 VarStoreName = (CHAR8 *) IfrVarStore->Name;\r
1218 for (Index = 0; VarStoreName[Index] != 0; Index ++) {\r
1219 if ((CHAR16) VarStoreName[Index] != VarName[Index]) {\r
1220 break;\r
1221 }\r
1222 }\r
1223 //\r
1224 // The matched VarStore is found.\r
1225 //\r
1226 if ((VarStoreName[Index] != 0) || (VarName[Index] != 0)) {\r
1227 IfrVarStore = NULL;\r
1228 }\r
1229 } else {\r
1230 IfrVarStore = NULL;\r
1231 }\r
82e8c138
ED
1232\r
1233 if (IfrVarStore != NULL) {\r
1234 VarStoreData.VarStoreId = IfrVarStore->VarStoreId;\r
1235 VarStoreData.Size = IfrVarStore->Size;\r
1236 }\r
84f9a9ec 1237 break;\r
82e8c138 1238 case EFI_IFR_VARSTORE_NAME_VALUE_OP:\r
84f9a9ec 1239 //\r
82e8c138 1240 // VarStoreId has been found. No further found.\r
84f9a9ec 1241 //\r
82e8c138
ED
1242 if (VarStoreData.VarStoreId != 0) {\r
1243 break;\r
84f9a9ec 1244 }\r
84f9a9ec 1245 //\r
82e8c138 1246 // Find the matched VarStoreId to the input VarGuid\r
84f9a9ec 1247 //\r
82e8c138
ED
1248 IfrNameValueStore = (EFI_IFR_VARSTORE_NAME_VALUE *) IfrOpHdr;\r
1249 if (!CompareGuid ((EFI_GUID *) (VOID *) &IfrNameValueStore->Guid, VarGuid)) {\r
1250 IfrNameValueStore = NULL;\r
1251 }\r
84f9a9ec 1252\r
82e8c138
ED
1253 if (IfrNameValueStore != NULL) {\r
1254 VarStoreData.VarStoreId = IfrNameValueStore->VarStoreId;\r
8567300a 1255 }\r
82e8c138
ED
1256 break;\r
1257 case EFI_IFR_VARSTORE_EFI_OP:\r
84f9a9ec 1258 //\r
82e8c138
ED
1259 // VarStore is found. Don't need to search any more.\r
1260 //\r
1261 if (VarStoreData.VarStoreId != 0) {\r
84f9a9ec
LG
1262 break;\r
1263 }\r
82e8c138
ED
1264\r
1265 IfrEfiVarStore = (EFI_IFR_VARSTORE_EFI *) IfrOpHdr;\r
1266\r
84f9a9ec 1267 //\r
82e8c138
ED
1268 // If the length is small than the structure, this is from old efi \r
1269 // varstore definition. Old efi varstore get config directly from \r
1270 // GetVariable function.\r
84f9a9ec 1271 //\r
82e8c138 1272 if (IfrOpHdr->Length < sizeof (EFI_IFR_VARSTORE_EFI)) {\r
84f9a9ec
LG
1273 break;\r
1274 }\r
82e8c138
ED
1275\r
1276 if (CompareGuid ((EFI_GUID *) (VOID *) &IfrEfiVarStore->Guid, VarGuid)) {\r
1277 VarStoreName = (CHAR8 *) IfrEfiVarStore->Name;\r
1278 for (Index = 0; VarStoreName[Index] != 0; Index ++) {\r
1279 if ((CHAR16) VarStoreName[Index] != VarName[Index]) {\r
1280 break;\r
1281 }\r
1282 }\r
84f9a9ec 1283 //\r
82e8c138 1284 // The matched VarStore is found.\r
84f9a9ec 1285 //\r
82e8c138
ED
1286 if ((VarStoreName[Index] != 0) || (VarName[Index] != 0)) {\r
1287 IfrEfiVarStore = NULL;\r
1288 }\r
1289 } else {\r
1290 IfrEfiVarStore = NULL;\r
84f9a9ec
LG
1291 }\r
1292\r
82e8c138
ED
1293 if (IfrEfiVarStore != NULL) {\r
1294 //\r
1295 // Find the matched VarStore\r
1296 //\r
1297 VarStoreData.VarStoreId = IfrEfiVarStore->VarStoreId;\r
1298 VarStoreData.Size = IfrEfiVarStore->Size;\r
1299 }\r
1300 break;\r
1301 case EFI_IFR_FORM_OP:\r
1302 case EFI_IFR_FORM_MAP_OP:\r
1303 //\r
1304 // Check the matched VarStoreId is found.\r
1305 //\r
1306 if (VarStoreData.VarStoreId == 0) {\r
1307 return EFI_SUCCESS;\r
1308 }\r
1309 break;\r
1310 case EFI_IFR_ONE_OF_OP:\r
1311 //\r
1312 // Check whether current value is the one of option.\r
1313 //\r
1314\r
1315 //\r
1316 // OneOf question is not in IFR Form. This IFR form is not valid. \r
84f9a9ec 1317 //\r
82e8c138
ED
1318 if (VarStoreData.VarStoreId == 0) {\r
1319 return EFI_INVALID_PARAMETER;\r
1320 }\r
1321 // \r
1322 // Check whether this question is for the requested varstore.\r
84f9a9ec 1323 //\r
82e8c138
ED
1324 IfrOneOf = (EFI_IFR_ONE_OF *) IfrOpHdr;\r
1325 if (IfrOneOf->Question.VarStoreId != VarStoreData.VarStoreId) {\r
1326 break;\r
1327 }\r
1328\r
1329 if (NameValueType) {\r
1330 QuestionName = HiiGetString (HiiHandle, IfrOneOf->Question.VarStoreInfo.VarName, NULL);\r
1331 ASSERT (QuestionName != NULL);\r
1332\r
1333 if (StrStr (RequestElement, QuestionName) == NULL) {\r
1334 //\r
1335 // This question is not in the current configuration string. Skip it.\r
1336 //\r
1337 break;\r
1338 }\r
1339\r
1340 Status = GetValueFromRequest (RequestElement, QuestionName, &VarValue);\r
1341 if (EFI_ERROR (Status)) {\r
1342 return Status;\r
1343 }\r
1344 } else {\r
1345 //\r
1346 // Get Offset by Question header and Width by DataType Flags\r
1347 //\r
1348 Offset = IfrOneOf->Question.VarStoreInfo.VarOffset;\r
1349 Width = (UINT16) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE));\r
1350 //\r
1351 // Check whether this question is in current block array.\r
1352 //\r
1353 if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) {\r
1354 //\r
1355 // This question is not in the current configuration string. Skip it.\r
1356 //\r
1357 break;\r
1358 }\r
1359 //\r
1360 // Check this var question is in the var storage \r
1361 //\r
1362 if ((Offset + Width) > VarStoreData.Size) {\r
1363 //\r
1364 // This question exceeds the var store size. \r
1365 //\r
1366 return EFI_INVALID_PARAMETER;\r
1367 }\r
1368\r
1369 //\r
1370 // Get the current value for oneof opcode\r
1371 //\r
1372 VarValue = 0;\r
1373 CopyMem (&VarValue, VarBuffer + Offset, Width);\r
1374 }\r
84f9a9ec
LG
1375 //\r
1376 // Set Block Data, to be checked in the following Oneof option opcode.\r
1377 //\r
84f9a9ec
LG
1378 VarBlockData.OpCode = IfrOpHdr->OpCode;\r
1379 VarBlockData.Scope = IfrOpHdr->Scope;\r
1380 break;\r
1381 case EFI_IFR_NUMERIC_OP:\r
1382 //\r
1383 // Check the current value is in the numeric range.\r
1384 //\r
1385\r
8567300a
LG
1386 //\r
1387 // Numeric question is not in IFR Form. This IFR form is not valid. \r
1388 //\r
82e8c138
ED
1389 if (VarStoreData.VarStoreId == 0) {\r
1390 return EFI_INVALID_PARAMETER;\r
8567300a 1391 }\r
84f9a9ec
LG
1392 //\r
1393 // Check whether this question is for the requested varstore.\r
1394 //\r
1395 IfrNumeric = (EFI_IFR_NUMERIC *) IfrOpHdr;\r
82e8c138 1396 if (IfrNumeric->Question.VarStoreId != VarStoreData.VarStoreId) {\r
84f9a9ec
LG
1397 break;\r
1398 }\r
82e8c138
ED
1399\r
1400 if (NameValueType) {\r
1401 QuestionName = HiiGetString (HiiHandle, IfrNumeric->Question.VarStoreInfo.VarName, NULL);\r
1402 ASSERT (QuestionName != NULL);\r
1403\r
1404 if (StrStr (RequestElement, QuestionName) == NULL) {\r
1405 //\r
1406 // This question is not in the current configuration string. Skip it.\r
1407 //\r
1408 break;\r
1409 }\r
1410 \r
1411 Status = GetValueFromRequest (RequestElement, QuestionName, &VarValue);\r
1412 if (EFI_ERROR (Status)) {\r
1413 return Status;\r
1414 }\r
1415 } else {\r
84f9a9ec 1416 //\r
82e8c138 1417 // Get Offset by Question header and Width by DataType Flags\r
84f9a9ec 1418 //\r
82e8c138
ED
1419 Offset = IfrNumeric->Question.VarStoreInfo.VarOffset;\r
1420 Width = (UINT16) (1 << (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE));\r
84f9a9ec 1421 //\r
82e8c138 1422 // Check whether this question is in current block array.\r
84f9a9ec 1423 //\r
82e8c138
ED
1424 if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) {\r
1425 //\r
1426 // This question is not in the current configuration string. Skip it.\r
1427 //\r
1428 break;\r
1429 }\r
1430 //\r
1431 // Check this var question is in the var storage \r
1432 //\r
1433 if ((Offset + Width) > VarStoreData.Size) {\r
1434 //\r
1435 // This question exceeds the var store size. \r
1436 //\r
1437 return EFI_INVALID_PARAMETER;\r
1438 }\r
84f9a9ec 1439\r
82e8c138
ED
1440 //\r
1441 // Check the current value is in the numeric range.\r
1442 //\r
1443 VarValue = 0;\r
1444 CopyMem (&VarValue, VarBuffer + Offset, Width);\r
1445 }\r
afc9bf79
ED
1446 if ((IfrNumeric->Flags & EFI_IFR_DISPLAY) == 0) {\r
1447 switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) {\r
1448 case EFI_IFR_NUMERIC_SIZE_1:\r
1449 if ((INT8) VarValue < (INT8) IfrNumeric->data.u8.MinValue || (INT8) VarValue > (INT8) IfrNumeric->data.u8.MaxValue) {\r
1450 //\r
1451 // Not in the valid range.\r
1452 //\r
1453 return EFI_INVALID_PARAMETER;\r
1454 }\r
1455 break;\r
1456 case EFI_IFR_NUMERIC_SIZE_2:\r
1457 if ((INT16) VarValue < (INT16) IfrNumeric->data.u16.MinValue || (INT16) VarValue > (INT16) IfrNumeric->data.u16.MaxValue) {\r
1458 //\r
1459 // Not in the valid range.\r
1460 //\r
1461 return EFI_INVALID_PARAMETER;\r
1462 }\r
1463 break;\r
1464 case EFI_IFR_NUMERIC_SIZE_4:\r
1465 if ((INT32) VarValue < (INT32) IfrNumeric->data.u32.MinValue || (INT32) VarValue > (INT32) IfrNumeric->data.u32.MaxValue) {\r
1466 //\r
1467 // Not in the valid range.\r
1468 //\r
1469 return EFI_INVALID_PARAMETER;\r
1470 }\r
1471 break;\r
1472 case EFI_IFR_NUMERIC_SIZE_8:\r
1473 if ((INT64) VarValue < (INT64) IfrNumeric->data.u64.MinValue || (INT64) VarValue > (INT64) IfrNumeric->data.u64.MaxValue) {\r
1474 //\r
1475 // Not in the valid range.\r
1476 //\r
1477 return EFI_INVALID_PARAMETER;\r
1478 }\r
1479 break;\r
84f9a9ec 1480 }\r
afc9bf79
ED
1481 } else {\r
1482 switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) {\r
1483 case EFI_IFR_NUMERIC_SIZE_1:\r
1484 if ((UINT8) VarValue < IfrNumeric->data.u8.MinValue || (UINT8) VarValue > IfrNumeric->data.u8.MaxValue) {\r
1485 //\r
1486 // Not in the valid range.\r
1487 //\r
1488 return EFI_INVALID_PARAMETER;\r
1489 }\r
1490 break;\r
1491 case EFI_IFR_NUMERIC_SIZE_2:\r
1492 if ((UINT16) VarValue < IfrNumeric->data.u16.MinValue || (UINT16) VarValue > IfrNumeric->data.u16.MaxValue) {\r
1493 //\r
1494 // Not in the valid range.\r
1495 //\r
1496 return EFI_INVALID_PARAMETER;\r
1497 }\r
1498 break;\r
1499 case EFI_IFR_NUMERIC_SIZE_4:\r
1500 if ((UINT32) VarValue < IfrNumeric->data.u32.MinValue || (UINT32) VarValue > IfrNumeric->data.u32.MaxValue) {\r
1501 //\r
1502 // Not in the valid range.\r
1503 //\r
1504 return EFI_INVALID_PARAMETER;\r
1505 }\r
1506 break;\r
1507 case EFI_IFR_NUMERIC_SIZE_8:\r
1508 if ((UINT64) VarValue < IfrNumeric->data.u64.MinValue || (UINT64) VarValue > IfrNumeric->data.u64.MaxValue) {\r
1509 //\r
1510 // Not in the valid range.\r
1511 //\r
1512 return EFI_INVALID_PARAMETER;\r
1513 }\r
1514 break;\r
84f9a9ec 1515 }\r
84f9a9ec 1516 }\r
84f9a9ec
LG
1517 break;\r
1518 case EFI_IFR_CHECKBOX_OP:\r
1519 //\r
1520 // Check value is BOOLEAN type, only 0 and 1 is valid.\r
1521 //\r
1522\r
8567300a
LG
1523 //\r
1524 // CheckBox question is not in IFR Form. This IFR form is not valid. \r
1525 //\r
82e8c138
ED
1526 if (VarStoreData.VarStoreId == 0) {\r
1527 return EFI_INVALID_PARAMETER;\r
8567300a
LG
1528 }\r
1529\r
84f9a9ec
LG
1530 //\r
1531 // Check whether this question is for the requested varstore.\r
1532 //\r
1533 IfrCheckBox = (EFI_IFR_CHECKBOX *) IfrOpHdr;\r
82e8c138 1534 if (IfrCheckBox->Question.VarStoreId != VarStoreData.VarStoreId) {\r
84f9a9ec
LG
1535 break;\r
1536 }\r
82e8c138
ED
1537\r
1538 if (NameValueType) {\r
1539 QuestionName = HiiGetString (HiiHandle, IfrCheckBox->Question.VarStoreInfo.VarName, NULL);\r
1540 ASSERT (QuestionName != NULL);\r
1541\r
1542 if (StrStr (RequestElement, QuestionName) == NULL) {\r
1543 //\r
1544 // This question is not in the current configuration string. Skip it.\r
1545 //\r
1546 break;\r
1547 }\r
1548 \r
1549 Status = GetValueFromRequest (RequestElement, QuestionName, &VarValue);\r
1550 if (EFI_ERROR (Status)) {\r
1551 return Status;\r
1552 }\r
1553 } else {\r
84f9a9ec 1554 //\r
82e8c138 1555 // Get Offset by Question header\r
84f9a9ec 1556 //\r
82e8c138
ED
1557 Offset = IfrCheckBox->Question.VarStoreInfo.VarOffset;\r
1558 Width = (UINT16) sizeof (BOOLEAN);\r
84f9a9ec 1559 //\r
82e8c138 1560 // Check whether this question is in current block array.\r
84f9a9ec 1561 //\r
82e8c138
ED
1562 if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) {\r
1563 //\r
1564 // This question is not in the current configuration string. Skip it.\r
1565 //\r
1566 break;\r
1567 }\r
1568 //\r
1569 // Check this var question is in the var storage \r
1570 //\r
1571 if ((Offset + Width) > VarStoreData.Size) {\r
1572 //\r
1573 // This question exceeds the var store size. \r
1574 //\r
1575 return EFI_INVALID_PARAMETER;\r
1576 }\r
1577 //\r
1578 // Check the current value is in the numeric range.\r
1579 //\r
1580 VarValue = 0;\r
1581 CopyMem (&VarValue, VarBuffer + Offset, Width);\r
84f9a9ec 1582 }\r
84f9a9ec
LG
1583 //\r
1584 // Boolean type, only 1 and 0 is valid.\r
1585 //\r
82e8c138
ED
1586 if (VarValue > 1) {\r
1587 return EFI_INVALID_PARAMETER;\r
84f9a9ec 1588 }\r
84f9a9ec
LG
1589 break;\r
1590 case EFI_IFR_STRING_OP:\r
1591 //\r
1592 // Check current string length is less than maxsize\r
1593 //\r
1594\r
8567300a
LG
1595 //\r
1596 // CheckBox question is not in IFR Form. This IFR form is not valid. \r
1597 //\r
82e8c138
ED
1598 if (VarStoreData.VarStoreId == 0) {\r
1599 return EFI_INVALID_PARAMETER;\r
8567300a
LG
1600 }\r
1601\r
84f9a9ec
LG
1602 //\r
1603 // Check whether this question is for the requested varstore.\r
1604 //\r
1605 IfrString = (EFI_IFR_STRING *) IfrOpHdr;\r
82e8c138 1606 if (IfrString->Question.VarStoreId != VarStoreData.VarStoreId) {\r
84f9a9ec
LG
1607 break;\r
1608 }\r
84f9a9ec 1609 //\r
1696b221 1610 // Get the Max size of the string.\r
84f9a9ec 1611 //\r
84f9a9ec 1612 Width = (UINT16) (IfrString->MaxSize * sizeof (UINT16));\r
82e8c138
ED
1613 if (NameValueType) {\r
1614 QuestionName = HiiGetString (HiiHandle, IfrString->Question.VarStoreInfo.VarName, NULL);\r
1615 ASSERT (QuestionName != NULL);\r
1616\r
1617 StringPtr = StrStr (RequestElement, QuestionName);\r
1618 if (StringPtr == NULL) {\r
1619 //\r
1620 // This question is not in the current configuration string. Skip it.\r
1621 //\r
1622 break;\r
1623 }\r
1696b221
BD
1624 //\r
1625 // Skip the VarName.\r
1626 //\r
1627 StringPtr += StrLen (QuestionName);\r
82e8c138 1628\r
84f9a9ec 1629 //\r
82e8c138
ED
1630 // Skip the "=".\r
1631 // \r
1632 StringPtr += 1;\r
1633 \r
84f9a9ec 1634 //\r
82e8c138 1635 // Check current string length is less than maxsize\r
1696b221
BD
1636 // e.g Config String: "0041004200430044", Unicode String: "ABCD". Unicode String length = Config String length / 4.\r
1637 // Config string format in UEFI spec.\r
1638 // <NvConfig> ::= <Label>'='<String>\r
1639 // <String> ::= [<Char>]+\r
1640 // <Char> ::= <HexCh>4\r
84f9a9ec 1641 //\r
1696b221 1642 if (StrLen (StringPtr) / 4 > IfrString->MaxSize) {\r
82e8c138
ED
1643 return EFI_INVALID_PARAMETER;\r
1644 }\r
1645 } else {\r
84f9a9ec 1646 //\r
82e8c138
ED
1647 // Get Offset/Width by Question header and OneOf Flags\r
1648 //\r
1649 Offset = IfrString->Question.VarStoreInfo.VarOffset;\r
1650 //\r
1651 // Check whether this question is in current block array.\r
1652 //\r
1653 if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) {\r
1654 //\r
1655 // This question is not in the current configuration string. Skip it.\r
1656 //\r
1657 break;\r
1658 }\r
1659 //\r
1660 // Check this var question is in the var storage \r
1661 //\r
1662 if ((Offset + Width) > VarStoreData.Size) {\r
1663 //\r
1664 // This question exceeds the var store size. \r
1665 //\r
1666 return EFI_INVALID_PARAMETER;\r
1667 }\r
1668\r
1669 //\r
1670 // Check current string length is less than maxsize\r
1671 //\r
1696b221 1672 if (StrLen ((CHAR16 *) (VarBuffer + Offset)) > IfrString->MaxSize) {\r
82e8c138
ED
1673 return EFI_INVALID_PARAMETER;\r
1674 }\r
84f9a9ec
LG
1675 }\r
1676 break;\r
1677 case EFI_IFR_ONE_OF_OPTION_OP:\r
1678 //\r
1679 // Opcode Scope is zero. This one of option is not to be checked. \r
1680 //\r
1681 if (VarBlockData.Scope == 0) {\r
1682 break;\r
1683 }\r
1684\r
1685 //\r
1686 // Only check for OneOf and OrderList opcode\r
1687 //\r
1688 IfrOneOfOption = (EFI_IFR_ONE_OF_OPTION *) IfrOpHdr;\r
1689 if (VarBlockData.OpCode == EFI_IFR_ONE_OF_OP) {\r
1690 //\r
1691 // Check current value is the value of one of option.\r
1692 //\r
5ecab660 1693 ASSERT (IfrOneOfOption->Type <= EFI_IFR_TYPE_NUM_SIZE_64);\r
fda93fc4 1694 ZeroMem (&TmpValue, sizeof (EFI_IFR_TYPE_VALUE));\r
a7f87053 1695 CopyMem (&TmpValue, &IfrOneOfOption->Value, IfrOneOfOption->Header.Length - OFFSET_OF (EFI_IFR_ONE_OF_OPTION, Value));\r
fda93fc4 1696 if (VarValue == TmpValue.u64) {\r
84f9a9ec
LG
1697 //\r
1698 // The value is one of option value.\r
1699 // Set OpCode to Zero, don't need check again.\r
1700 //\r
1701 VarBlockData.OpCode = 0;\r
1702 }\r
1703 }\r
84f9a9ec
LG
1704 break;\r
1705 case EFI_IFR_END_OP:\r
1706 //\r
1707 // Decrease opcode scope for the validated opcode\r
1708 //\r
1709 if (VarBlockData.Scope > 0) {\r
1710 VarBlockData.Scope --;\r
1711 }\r
1712\r
1713 //\r
1714 // OneOf value doesn't belong to one of option value. \r
1715 //\r
62b658dd 1716 if ((VarBlockData.Scope == 0) && (VarBlockData.OpCode == EFI_IFR_ONE_OF_OP)) {\r
82e8c138 1717 return EFI_INVALID_PARAMETER;\r
84f9a9ec
LG
1718 }\r
1719 break;\r
1720 default:\r
1721 //\r
1722 // Increase Scope for the validated opcode\r
1723 //\r
1724 if (VarBlockData.Scope > 0) {\r
1725 VarBlockData.Scope = (UINT8) (VarBlockData.Scope + IfrOpHdr->Scope);\r
1726 }\r
1727 break;\r
1728 }\r
1729 //\r
1730 // Go to the next opcode\r
1731 //\r
1732 IfrOffset += IfrOpHdr->Length;\r
1733 }\r
1734 //\r
1735 // Only one form is in a package list.\r
1736 //\r
1737 break;\r
1738 }\r
82e8c138 1739\r
84f9a9ec
LG
1740 //\r
1741 // Go to next package.\r
1742 //\r
3b28e744 1743 PackageOffset += PackageHeader.Length;\r
84f9a9ec
LG
1744 }\r
1745\r
82e8c138
ED
1746 return EFI_SUCCESS;\r
1747}\r
1748\r
1749/**\r
1750 This internal function parses IFR data to validate current setting.\r
1751\r
1752 @param ConfigElement ConfigResp element string contains the current setting.\r
1753 @param CurrentBlockArray Current block array.\r
1754 @param VarBuffer Data buffer for this varstore.\r
1755 \r
1756 @retval EFI_SUCCESS The current setting is valid.\r
1757 @retval EFI_OUT_OF_RESOURCES The memory is not enough.\r
1758 @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid.\r
1759**/\r
1760EFI_STATUS\r
1761GetBlockDataInfo (\r
1762 IN CHAR16 *ConfigElement,\r
1763 OUT IFR_BLOCK_DATA **CurrentBlockArray,\r
1764 OUT UINT8 **VarBuffer\r
1765 )\r
1766{\r
1767 IFR_BLOCK_DATA *BlockData;\r
1768 IFR_BLOCK_DATA *NewBlockData;\r
1769 EFI_STRING StringPtr;\r
1770 UINTN Length;\r
1771 UINT8 *TmpBuffer;\r
1772 UINT16 Offset;\r
1773 UINT16 Width;\r
40ae09a2
ED
1774 LIST_ENTRY *Link;\r
1775 UINTN MaxBufferSize;\r
1776 EFI_STATUS Status;\r
40ae09a2
ED
1777 IFR_BLOCK_DATA *BlockArray;\r
1778 UINT8 *DataBuffer;\r
1779 \r
1780 //\r
1781 // Initialize the local variables.\r
1782 //\r
40ae09a2
ED
1783 Status = EFI_SUCCESS;\r
1784 BlockData = NULL;\r
1785 NewBlockData = NULL;\r
82e8c138
ED
1786 TmpBuffer = NULL;\r
1787 BlockArray = NULL;\r
1788 MaxBufferSize = HII_LIB_DEFAULT_VARSTORE_SIZE;\r
1789 DataBuffer = AllocateZeroPool (MaxBufferSize);\r
1790 if (DataBuffer == NULL) {\r
1791 return EFI_OUT_OF_RESOURCES;\r
1792 }\r
1793\r
1794 //\r
1795 // Init BlockArray\r
1796 //\r
1797 BlockArray = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA));\r
1798 if (BlockArray == NULL) {\r
1799 Status = EFI_OUT_OF_RESOURCES;\r
1800 goto Done;\r
1801 }\r
1802 InitializeListHead (&BlockArray->Entry);\r
1803\r
1804 StringPtr = StrStr (ConfigElement, L"&OFFSET=");\r
1805 ASSERT (StringPtr != NULL);\r
1806\r
1807 //\r
1808 // Parse each <RequestElement> if exists\r
1809 // Only <BlockName> format is supported by this help function.\r
1810 // <BlockName> ::= &'OFFSET='<Number>&'WIDTH='<Number>\r
1811 //\r
1812 while (*StringPtr != 0 && StrnCmp (StringPtr, L"&OFFSET=", StrLen (L"&OFFSET=")) == 0) {\r
1813 //\r
1814 // Skip the &OFFSET= string\r
1815 // \r
1816 StringPtr += StrLen (L"&OFFSET=");\r
1817\r
1818 //\r
1819 // Get Offset\r
1820 //\r
1821 Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
1822 if (EFI_ERROR (Status)) {\r
1823 goto Done;\r
1824 }\r
1825 Offset = 0;\r
1826 CopyMem (\r
1827 &Offset,\r
1828 TmpBuffer,\r
1829 (((Length + 1) / 2) < sizeof (UINT16)) ? ((Length + 1) / 2) : sizeof (UINT16)\r
1830 );\r
1831 FreePool (TmpBuffer);\r
1832 TmpBuffer = NULL;\r
1833\r
1834 StringPtr += Length;\r
1835 if (StrnCmp (StringPtr, L"&WIDTH=", StrLen (L"&WIDTH=")) != 0) {\r
1836 Status = EFI_INVALID_PARAMETER;\r
1837 goto Done;\r
1838 }\r
1839 StringPtr += StrLen (L"&WIDTH=");\r
1840\r
1841 //\r
1842 // Get Width\r
1843 //\r
1844 Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
1845 if (EFI_ERROR (Status)) {\r
1846 goto Done;\r
1847 }\r
1848 Width = 0;\r
1849 CopyMem (\r
1850 &Width,\r
1851 TmpBuffer,\r
1852 (((Length + 1) / 2) < sizeof (UINT16)) ? ((Length + 1) / 2) : sizeof (UINT16)\r
1853 );\r
1854 FreePool (TmpBuffer);\r
1855 TmpBuffer = NULL;\r
1856\r
1857 StringPtr += Length;\r
1858 if (*StringPtr != 0 && *StringPtr != L'&') {\r
1859 Status = EFI_INVALID_PARAMETER;\r
1860 goto Done;\r
1861 }\r
1862\r
1863 if (StrnCmp (StringPtr, L"&VALUE=", StrLen (L"&VALUE=")) != 0) {\r
1864 Status = EFI_INVALID_PARAMETER;\r
1865 goto Done;\r
1866 }\r
1867 StringPtr += StrLen (L"&VALUE=");\r
1868\r
1869 //\r
1870 // Get Value\r
1871 //\r
1872 Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
1873 if (EFI_ERROR (Status)) {\r
1874 goto Done;\r
1875 }\r
1876\r
1877 StringPtr += Length;\r
1878 if (*StringPtr != 0 && *StringPtr != L'&') {\r
1879 Status = EFI_INVALID_PARAMETER;\r
1880 goto Done;\r
1881 }\r
1882\r
1883 //\r
1884 // Check whether VarBuffer is enough\r
1885 //\r
16f69227 1886 if ((UINT32)Offset + Width > MaxBufferSize) {\r
82e8c138
ED
1887 DataBuffer = ReallocatePool (\r
1888 MaxBufferSize,\r
1889 Offset + Width + HII_LIB_DEFAULT_VARSTORE_SIZE,\r
1890 DataBuffer\r
1891 );\r
1892 if (DataBuffer == NULL) {\r
1893 Status = EFI_OUT_OF_RESOURCES;\r
1894 goto Done;\r
1895 }\r
1896 MaxBufferSize = Offset + Width + HII_LIB_DEFAULT_VARSTORE_SIZE;\r
1897 }\r
1898\r
1899 //\r
1900 // Update the Block with configuration info\r
1901 //\r
1902 CopyMem (DataBuffer + Offset, TmpBuffer, Width);\r
1903 FreePool (TmpBuffer);\r
1904 TmpBuffer = NULL;\r
1905\r
1906 //\r
1907 // Set new Block Data\r
1908 //\r
1909 NewBlockData = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA));\r
1910 if (NewBlockData == NULL) {\r
1911 Status = EFI_OUT_OF_RESOURCES;\r
1912 goto Done;\r
1913 }\r
1914 NewBlockData->Offset = Offset;\r
1915 NewBlockData->Width = Width;\r
1916\r
1917 //\r
1918 // Insert the new block data into the block data array.\r
1919 //\r
1920 for (Link = BlockArray->Entry.ForwardLink; Link != &BlockArray->Entry; Link = Link->ForwardLink) {\r
1921 BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry);\r
1922 if (NewBlockData->Offset == BlockData->Offset) {\r
1923 if (NewBlockData->Width > BlockData->Width) {\r
1924 BlockData->Width = NewBlockData->Width;\r
1925 }\r
1926 FreePool (NewBlockData);\r
1927 break;\r
1928 } else if (NewBlockData->Offset < BlockData->Offset) {\r
1929 //\r
1930 // Insert new block data as the previous one of this link.\r
1931 //\r
1932 InsertTailList (Link, &NewBlockData->Entry);\r
1933 break;\r
1934 }\r
1935 }\r
1936\r
1937 //\r
1938 // Insert new block data into the array tail.\r
1939 //\r
1940 if (Link == &BlockArray->Entry) {\r
1941 InsertTailList (Link, &NewBlockData->Entry);\r
1942 }\r
1943\r
1944 //\r
1945 // If '\0', parsing is finished. \r
1946 //\r
1947 if (*StringPtr == 0) {\r
1948 break;\r
1949 }\r
1950 //\r
1951 // Go to next ConfigBlock \r
1952 //\r
1953 }\r
1954\r
1955 //\r
1956 // Merge the aligned block data into the single block data.\r
1957 //\r
1958 Link = BlockArray->Entry.ForwardLink;\r
1959 while ((Link != &BlockArray->Entry) && (Link->ForwardLink != &BlockArray->Entry)) {\r
1960 BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry);\r
1961 NewBlockData = BASE_CR (Link->ForwardLink, IFR_BLOCK_DATA, Entry);\r
1962 if ((NewBlockData->Offset >= BlockData->Offset) && (NewBlockData->Offset <= (BlockData->Offset + BlockData->Width))) {\r
1963 if ((NewBlockData->Offset + NewBlockData->Width) > (BlockData->Offset + BlockData->Width)) {\r
1964 BlockData->Width = (UINT16) (NewBlockData->Offset + NewBlockData->Width - BlockData->Offset);\r
1965 }\r
1966 RemoveEntryList (Link->ForwardLink);\r
1967 FreePool (NewBlockData);\r
1968 continue;\r
1969 }\r
1970 Link = Link->ForwardLink;\r
1971 }\r
1972\r
1973 *VarBuffer = DataBuffer;\r
1974 *CurrentBlockArray = BlockArray;\r
1975 return EFI_SUCCESS;\r
1976\r
84f9a9ec 1977Done:\r
82e8c138
ED
1978 if (DataBuffer != NULL) {\r
1979 FreePool (DataBuffer);\r
1980 }\r
1981 \r
1982 if (BlockArray != NULL) {\r
1983 //\r
1984 // Free Link Array CurrentBlockArray\r
1985 //\r
1986 while (!IsListEmpty (&BlockArray->Entry)) {\r
1987 BlockData = BASE_CR (BlockArray->Entry.ForwardLink, IFR_BLOCK_DATA, Entry);\r
1988 RemoveEntryList (&BlockData->Entry);\r
1989 FreePool (BlockData);\r
1990 }\r
1991 FreePool (BlockArray);\r
1992 }\r
1993\r
1994 return Status;\r
1995}\r
1996\r
1997/**\r
1998 This internal function parses IFR data to validate current setting.\r
1999\r
2000 @param ConfigResp ConfigResp string contains the current setting.\r
2001 @param HiiPackageList Point to Hii package list.\r
2002 @param PackageListLength The length of the pacakge.\r
2003 @param VarGuid Guid of the buffer storage.\r
2004 @param VarName Name of the buffer storage.\r
2005 @param HiiHandle The HiiHandle for this package.\r
2006 \r
2007 @retval EFI_SUCCESS The current setting is valid.\r
2008 @retval EFI_OUT_OF_RESOURCES The memory is not enough.\r
2009 @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid.\r
2010**/\r
2011EFI_STATUS\r
2012EFIAPI\r
2013InternalHiiValidateCurrentSetting (\r
2014 IN EFI_STRING ConfigResp,\r
2015 IN EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList,\r
2016 IN UINTN PackageListLength,\r
2017 IN EFI_GUID *VarGuid,\r
2018 IN CHAR16 *VarName,\r
2019 IN EFI_HII_HANDLE HiiHandle\r
2020 )\r
2021{\r
2022 CHAR16 *StringPtr;\r
2023 EFI_STATUS Status;\r
2024 IFR_BLOCK_DATA *CurrentBlockArray;\r
2025 IFR_BLOCK_DATA *BlockData;\r
2026 UINT8 *VarBuffer;\r
2027 BOOLEAN NameValueType;\r
2028\r
2029 CurrentBlockArray = NULL;\r
2030 VarBuffer = NULL;\r
2031 StringPtr = NULL;\r
2032 Status = EFI_SUCCESS;\r
2033\r
2034 //\r
2035 // If StringPtr != NULL, get the request elements.\r
2036 //\r
2037 if (StrStr (ConfigResp, L"&OFFSET=") != NULL) {\r
2038 Status = GetBlockDataInfo(ConfigResp, &CurrentBlockArray, &VarBuffer);\r
2039 if (EFI_ERROR (Status)) {\r
2040 return Status;\r
2041 }\r
2042 NameValueType = FALSE;\r
2043 } else {\r
2044 //\r
2045 // Skip header part.\r
2046 //\r
2047 StringPtr = StrStr (ConfigResp, L"PATH=");\r
2048 ASSERT (StringPtr != NULL);\r
2049\r
2050 if (StrStr (StringPtr, L"&") != NULL) {\r
2051 NameValueType = TRUE;\r
2052 } else {\r
2053 //\r
2054 // Not found Request element, return success.\r
2055 //\r
2056 return EFI_SUCCESS;\r
2057 }\r
2058 }\r
2059\r
2060 Status = ValidateQuestionFromVfr(\r
2061 HiiPackageList,\r
2062 PackageListLength,\r
2063 VarGuid,\r
2064 VarName,\r
2065 VarBuffer,\r
2066 CurrentBlockArray,\r
2067 ConfigResp,\r
2068 HiiHandle,\r
2069 NameValueType\r
2070 );\r
2071\r
84f9a9ec
LG
2072 if (VarBuffer != NULL) {\r
2073 FreePool (VarBuffer);\r
2074 }\r
2075 \r
2076 if (CurrentBlockArray != NULL) {\r
2077 //\r
2078 // Free Link Array CurrentBlockArray\r
2079 //\r
2080 while (!IsListEmpty (&CurrentBlockArray->Entry)) {\r
2081 BlockData = BASE_CR (CurrentBlockArray->Entry.ForwardLink, IFR_BLOCK_DATA, Entry);\r
2082 RemoveEntryList (&BlockData->Entry);\r
2083 FreePool (BlockData);\r
2084 }\r
82e8c138 2085 FreePool (CurrentBlockArray);\r
84f9a9ec
LG
2086 }\r
2087\r
2088 return Status;\r
2089}\r
2090\r
82e8c138
ED
2091/**\r
2092 Check whether the ConfigRequest string has the request elements.\r
2093 For EFI_HII_VARSTORE_BUFFER type, the request has "&OFFSET=****&WIDTH=****..." format.\r
2094 For EFI_HII_VARSTORE_NAME_VALUE type, the request has "&NAME1**&NAME2..." format.\r
2095\r
2096 @param ConfigRequest The input config request string.\r
2097\r
2098 @retval TRUE The input include config request elements.\r
2099 @retval FALSE The input string not includes.\r
2100 \r
2101**/\r
2102BOOLEAN\r
2103GetElementsFromRequest (\r
2104 IN EFI_STRING ConfigRequest\r
2105 )\r
2106{\r
2107 EFI_STRING TmpRequest;\r
2108\r
2109 TmpRequest = StrStr (ConfigRequest, L"PATH=");\r
2110 ASSERT (TmpRequest != NULL);\r
2111\r
2112 if ((StrStr (TmpRequest, L"&OFFSET=") != NULL) || (StrStr (TmpRequest, L"&") != NULL)) {\r
2113 return TRUE;\r
2114 }\r
2115\r
2116 return FALSE;\r
2117}\r
2118\r
84f9a9ec 2119/**\r
8567300a
LG
2120 This function parses the input ConfigRequest string and its matched IFR code\r
2121 string for setting default value and validating current setting.\r
2122\r
84f9a9ec
LG
2123 1. For setting default action, Reset the default value specified by DefaultId \r
2124 to the driver configuration got by Request string.\r
2125 2. For validating current setting, Validate the current configuration \r
2126 by parsing HII form IFR opcode.\r
2127\r
2128 NULL request string support depends on the ExportConfig interface of\r
2129 HiiConfigRouting protocol in UEFI specification.\r
2130 \r
2131 @param Request A null-terminated Unicode string in \r
2132 <MultiConfigRequest> format. It can be NULL.\r
2133 If it is NULL, all current configuration for the\r
2134 entirety of the current HII database will be validated.\r
2135 If it is NULL, all configuration for the\r
2136 entirety of the current HII database will be reset.\r
2137 @param DefaultId Specifies the type of defaults to retrieve only for setting default action.\r
2138 @param ActionType Action supports setting defaults and validate current setting.\r
2139 \r
3b28e744 2140 @retval TRUE Action runs successfully.\r
84f9a9ec
LG
2141 @retval FALSE Action is not valid or Action can't be executed successfully..\r
2142**/\r
2143BOOLEAN\r
2144EFIAPI\r
2145InternalHiiIfrValueAction (\r
2146 IN CONST EFI_STRING Request, OPTIONAL\r
76c24251 2147 IN UINT16 DefaultId,\r
84f9a9ec
LG
2148 IN UINT8 ActionType\r
2149 )\r
2150{\r
2151 EFI_STRING ConfigAltResp;\r
2152 EFI_STRING ConfigAltHdr;\r
2153 EFI_STRING ConfigResp;\r
2154 EFI_STRING Progress;\r
2155 EFI_STRING StringPtr;\r
2156 EFI_STRING StringHdr;\r
2157 EFI_STATUS Status;\r
2158 EFI_HANDLE DriverHandle;\r
2159 EFI_HANDLE TempDriverHandle;\r
2160 EFI_HII_HANDLE *HiiHandleBuffer;\r
2161 EFI_HII_HANDLE HiiHandle;\r
2162 UINT32 Index;\r
2163 EFI_GUID *VarGuid;\r
2164 EFI_STRING VarName;\r
84f9a9ec 2165\r
84f9a9ec 2166 EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;\r
84f9a9ec 2167 UINTN PackageListLength;\r
5ad66ec6 2168 UINTN MaxLen;\r
84f9a9ec
LG
2169 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
2170 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r
7538d536 2171\r
84f9a9ec
LG
2172 ConfigAltResp = NULL;\r
2173 ConfigResp = NULL;\r
2174 VarGuid = NULL;\r
2175 VarName = NULL;\r
2176 DevicePath = NULL;\r
2177 ConfigAltHdr = NULL;\r
2178 HiiHandleBuffer = NULL;\r
2179 Index = 0;\r
2180 TempDriverHandle = NULL;\r
2181 HiiHandle = NULL;\r
84f9a9ec
LG
2182 HiiPackageList = NULL;\r
2183 \r
2184 //\r
2185 // Only support set default and validate setting action.\r
2186 //\r
2187 if ((ActionType != ACTION_SET_DEFAUTL_VALUE) && (ActionType != ACTION_VALIDATE_SETTING)) {\r
2188 return FALSE;\r
2189 }\r
2190\r
2191 //\r
2192 // Get the full requested value and deault value string.\r
2193 //\r
2194 if (Request != NULL) {\r
2195 Status = gHiiConfigRouting->ExtractConfig (\r
2196 gHiiConfigRouting,\r
2197 Request,\r
2198 &Progress,\r
2199 &ConfigAltResp\r
2200 );\r
2201 } else {\r
2202 Status = gHiiConfigRouting->ExportConfig (\r
2203 gHiiConfigRouting,\r
2204 &ConfigAltResp\r
2205 );\r
2206 }\r
2207 \r
2208 if (EFI_ERROR (Status)) {\r
2209 return FALSE;\r
2210 }\r
2211 \r
2212 StringPtr = ConfigAltResp;\r
fe4a28cc
DB
2213 ASSERT (StringPtr != NULL);\r
2214\r
2215 while (*StringPtr != L'\0') {\r
84f9a9ec
LG
2216 //\r
2217 // 1. Find <ConfigHdr> GUID=...&NAME=...&PATH=...\r
2218 //\r
2219 StringHdr = StringPtr;\r
2220\r
2221 //\r
2222 // Get Guid value\r
2223 //\r
2224 if (StrnCmp (StringPtr, L"GUID=", StrLen (L"GUID=")) != 0) {\r
2225 Status = EFI_INVALID_PARAMETER;\r
2226 goto Done;\r
2227 }\r
2228 StringPtr += StrLen (L"GUID=");\r
2229 Status = InternalHiiGetBufferFromString (StringPtr, GUID_CONFIG_STRING_TYPE, (UINT8 **) &VarGuid);\r
2230 if (EFI_ERROR (Status)) {\r
2231 goto Done;\r
2232 }\r
2233\r
2234 //\r
2235 // Get Name value VarName\r
2236 //\r
2237 while (*StringPtr != L'\0' && StrnCmp (StringPtr, L"&NAME=", StrLen (L"&NAME=")) != 0) {\r
2238 StringPtr++;\r
2239 }\r
2240 if (*StringPtr == L'\0') {\r
2241 Status = EFI_INVALID_PARAMETER;\r
2242 goto Done;\r
2243 }\r
2244 StringPtr += StrLen (L"&NAME=");\r
2245 Status = InternalHiiGetBufferFromString (StringPtr, NAME_CONFIG_STRING_TYPE, (UINT8 **) &VarName);\r
2246 if (EFI_ERROR (Status)) {\r
2247 goto Done;\r
2248 }\r
2249 \r
2250 //\r
2251 // Get Path value DevicePath\r
2252 //\r
2253 while (*StringPtr != L'\0' && StrnCmp (StringPtr, L"&PATH=", StrLen (L"&PATH=")) != 0) {\r
2254 StringPtr++;\r
2255 }\r
2256 if (*StringPtr == L'\0') {\r
2257 Status = EFI_INVALID_PARAMETER;\r
2258 goto Done;\r
2259 }\r
2260 StringPtr += StrLen (L"&PATH=");\r
2261 Status = InternalHiiGetBufferFromString (StringPtr, PATH_CONFIG_STRING_TYPE, (UINT8 **) &DevicePath);\r
2262 if (EFI_ERROR (Status)) {\r
2263 goto Done;\r
2264 }\r
2265\r
2266 //\r
2267 // Get the Driver handle by the got device path.\r
2268 //\r
2269 TempDevicePath = DevicePath;\r
2270 Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &TempDevicePath, &DriverHandle);\r
2271 if (EFI_ERROR (Status)) {\r
2272 goto Done;\r
2273 }\r
2274 \r
2275 //\r
2276 // Find the matched Hii Handle for the found Driver handle\r
2277 //\r
2278 HiiHandleBuffer = HiiGetHiiHandles (NULL);\r
2279 if (HiiHandleBuffer == NULL) {\r
2280 Status = EFI_NOT_FOUND;\r
2281 goto Done;\r
2282 }\r
2283\r
2284 for (Index = 0; HiiHandleBuffer[Index] != NULL; Index ++) {\r
2285 gHiiDatabase->GetPackageListHandle (gHiiDatabase, HiiHandleBuffer[Index], &TempDriverHandle);\r
2286 if (TempDriverHandle == DriverHandle) {\r
2287 break;\r
2288 }\r
2289 }\r
2290\r
2291 HiiHandle = HiiHandleBuffer[Index];\r
2292 FreePool (HiiHandleBuffer);\r
2293\r
2294 if (HiiHandle == NULL) {\r
2295 //\r
2296 // This request string has no its Hii package.\r
2297 // Its default value and validating can't execute by parsing IFR data.\r
2298 // Directly jump into the next ConfigAltResp string for another pair Guid, Name, and Path. \r
2299 //\r
82e8c138 2300 Status = EFI_SUCCESS;\r
84f9a9ec
LG
2301 goto NextConfigAltResp;\r
2302 }\r
84f9a9ec
LG
2303\r
2304 //\r
81b618fe 2305 // 2. Get HiiPackage by HiiHandle\r
84f9a9ec
LG
2306 //\r
2307 PackageListLength = 0;\r
2308 HiiPackageList = NULL;\r
2309 Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, HiiHandle, &PackageListLength, HiiPackageList);\r
2310 \r
2311 //\r
2312 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.\r
2313 //\r
2314 if (Status != EFI_BUFFER_TOO_SMALL) {\r
2315 Status = EFI_INVALID_PARAMETER;\r
2316 goto Done;\r
2317 }\r
2318 \r
2319 HiiPackageList = AllocatePool (PackageListLength);\r
2320 if (HiiPackageList == NULL) {\r
2321 Status = EFI_OUT_OF_RESOURCES;\r
2322 goto Done;\r
2323 }\r
2324 \r
2325 //\r
2326 // Get PackageList on HiiHandle\r
2327 //\r
2328 Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, HiiHandle, &PackageListLength, HiiPackageList);\r
2329 if (EFI_ERROR (Status)) {\r
2330 goto Done;\r
2331 }\r
2332 \r
84f9a9ec
LG
2333 //\r
2334 // 3. Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, Name, DevicePath, AltCfgId, AltCfgResp)\r
81b618fe 2335 // Get the default configuration string according to the default ID.\r
84f9a9ec
LG
2336 //\r
2337 Status = gHiiConfigRouting->GetAltConfig (\r
2338 gHiiConfigRouting,\r
2339 ConfigAltResp,\r
2340 VarGuid,\r
2341 VarName,\r
2342 DevicePath,\r
81b618fe 2343 (ActionType == ACTION_SET_DEFAUTL_VALUE) ? &DefaultId:NULL, // it can be NULL to get the current setting.\r
84f9a9ec
LG
2344 &ConfigResp\r
2345 );\r
1f1cb2f2
LG
2346 \r
2347 //\r
2348 // The required setting can't be found. So, it is not required to be validated and set.\r
2349 //\r
84f9a9ec 2350 if (EFI_ERROR (Status)) {\r
76c24251
LG
2351 Status = EFI_SUCCESS;\r
2352 goto NextConfigAltResp;\r
84f9a9ec 2353 }\r
1f1cb2f2
LG
2354 //\r
2355 // Only the ConfigHdr is found. Not any block data is found. No data is required to be validated and set.\r
2356 //\r
82e8c138 2357 if (!GetElementsFromRequest (ConfigResp)) {\r
1f1cb2f2
LG
2358 goto NextConfigAltResp;\r
2359 }\r
84f9a9ec
LG
2360 \r
2361 //\r
2362 // 4. Set the default configuration information or Validate current setting by parse IFR code.\r
2363 // Current Setting is in ConfigResp, will be set into buffer, then check it again.\r
2364 //\r
2365 if (ActionType == ACTION_SET_DEFAUTL_VALUE) {\r
2366 //\r
2367 // Set the default configuration information.\r
2368 //\r
2369 Status = gHiiConfigRouting->RouteConfig (gHiiConfigRouting, ConfigResp, &Progress);\r
2370 } else {\r
2371 //\r
2372 // Current Setting is in ConfigResp, will be set into buffer, then check it again.\r
2373 //\r
82e8c138 2374 Status = InternalHiiValidateCurrentSetting (ConfigResp, HiiPackageList, PackageListLength, VarGuid, VarName, HiiHandle);\r
84f9a9ec
LG
2375 }\r
2376\r
2377 if (EFI_ERROR (Status)) {\r
2378 goto Done;\r
2379 }\r
2380\r
76c24251 2381NextConfigAltResp:\r
84f9a9ec
LG
2382 //\r
2383 // Free the allocated pacakge buffer and the got ConfigResp string.\r
2384 //\r
2385 if (HiiPackageList != NULL) {\r
2386 FreePool (HiiPackageList);\r
2387 HiiPackageList = NULL;\r
2388 }\r
76c24251 2389 \r
82e8c138
ED
2390 if (ConfigResp != NULL) {\r
2391 FreePool (ConfigResp);\r
2392 ConfigResp = NULL;\r
2393 }\r
84f9a9ec 2394\r
84f9a9ec
LG
2395 //\r
2396 // Free the allocated buffer.\r
2397 //\r
2398 FreePool (VarGuid);\r
2399 VarGuid = NULL;\r
2400 \r
2401 FreePool (VarName);\r
2402 VarName = NULL;\r
2403 \r
2404 FreePool (DevicePath);\r
2405 DevicePath = NULL;\r
2406\r
2407 //\r
2408 // 5. Jump to next ConfigAltResp for another Guid, Name, Path.\r
2409 //\r
2410\r
2411 //\r
2412 // Get and Skip ConfigHdr\r
2413 //\r
2414 while (*StringPtr != L'\0' && *StringPtr != L'&') {\r
2415 StringPtr++;\r
2416 }\r
2417 if (*StringPtr == L'\0') {\r
2418 break;\r
2419 }\r
2420 \r
2421 //\r
2422 // Construct ConfigAltHdr string "&<ConfigHdr>&ALTCFG=\0" \r
2423 // | 1 | StrLen (ConfigHdr) | 8 | 1 |\r
2424 //\r
5ad66ec6
DB
2425 MaxLen = 1 + StringPtr - StringHdr + 8 + 1;\r
2426 ConfigAltHdr = AllocateZeroPool ( MaxLen * sizeof (CHAR16));\r
84f9a9ec
LG
2427 if (ConfigAltHdr == NULL) {\r
2428 Status = EFI_OUT_OF_RESOURCES;\r
2429 goto Done;\r
2430 }\r
5ad66ec6
DB
2431 StrCpyS (ConfigAltHdr, MaxLen, L"&");\r
2432 StrnCatS (ConfigAltHdr, MaxLen, StringHdr, StringPtr - StringHdr);\r
2433 StrCatS (ConfigAltHdr, MaxLen, L"&ALTCFG=");\r
84f9a9ec
LG
2434 \r
2435 //\r
2436 // Skip all AltResp (AltConfigHdr ConfigBody) for the same ConfigHdr\r
2437 //\r
2438 while ((StringHdr = StrStr (StringPtr, ConfigAltHdr)) != NULL) {\r
2439 StringPtr = StringHdr + StrLen (ConfigAltHdr);\r
2440 if (*StringPtr == L'\0') {\r
2441 break;\r
2442 }\r
2443 }\r
2444 \r
2445 //\r
2446 // Free the allocated ConfigAltHdr string\r
2447 //\r
2448 FreePool (ConfigAltHdr);\r
2449 if (*StringPtr == L'\0') {\r
2450 break;\r
2451 }\r
2452 \r
2453 //\r
2454 // Find &GUID as the next ConfigHdr\r
2455 //\r
2456 StringPtr = StrStr (StringPtr, L"&GUID");\r
2457 if (StringPtr == NULL) {\r
2458 break;\r
2459 }\r
2460\r
2461 //\r
2462 // Skip char '&'\r
2463 //\r
2464 StringPtr ++;\r
2465 }\r
2466 \r
2467Done:\r
2468 if (VarGuid != NULL) {\r
2469 FreePool (VarGuid);\r
2470 }\r
2471\r
2472 if (VarName != NULL) {\r
2473 FreePool (VarName);\r
2474 }\r
2475\r
2476 if (DevicePath != NULL) {\r
2477 FreePool (DevicePath);\r
2478 }\r
2479\r
2480 if (ConfigResp != NULL) {\r
2481 FreePool (ConfigResp);\r
2482 }\r
2483\r
2484 if (ConfigAltResp != NULL) {\r
2485 FreePool (ConfigAltResp);\r
2486 }\r
2487 \r
2488 if (HiiPackageList != NULL) {\r
2489 FreePool (HiiPackageList);\r
2490 }\r
2491 \r
2492 if (EFI_ERROR (Status)) {\r
2493 return FALSE;\r
2494 }\r
2495\r
2496 return TRUE;\r
2497}\r
2498\r
2499/**\r
2500 Validate the current configuration by parsing HII form IFR opcode.\r
2501\r
4e069e8b 2502 NULL request string support depends on the ExportConfig interface of\r
84f9a9ec
LG
2503 HiiConfigRouting protocol in UEFI specification.\r
2504 \r
2505 @param Request A null-terminated Unicode string in \r
2506 <MultiConfigRequest> format. It can be NULL.\r
2507 If it is NULL, all current configuration for the\r
2508 entirety of the current HII database will be validated.\r
2509 \r
9035e118 2510 @retval TRUE Current configuration is valid.\r
84f9a9ec
LG
2511 @retval FALSE Current configuration is invalid.\r
2512**/\r
2513BOOLEAN\r
2514EFIAPI \r
2515HiiValidateSettings (\r
2516 IN CONST EFI_STRING Request OPTIONAL\r
2517 )\r
2518{\r
2519 return InternalHiiIfrValueAction (Request, 0, ACTION_VALIDATE_SETTING);\r
2520}\r
2521\r
2522/**\r
2523 Reset the default value specified by DefaultId to the driver\r
2524 configuration got by Request string. \r
2525\r
2526 NULL request string support depends on the ExportConfig interface of\r
2527 HiiConfigRouting protocol in UEFI specification.\r
2528 \r
2529 @param Request A null-terminated Unicode string in \r
2530 <MultiConfigRequest> format. It can be NULL.\r
2531 If it is NULL, all configuration for the\r
2532 entirety of the current HII database will be reset.\r
2533 @param DefaultId Specifies the type of defaults to retrieve.\r
2534 \r
3b28e744 2535 @retval TRUE The default value is set successfully.\r
84f9a9ec
LG
2536 @retval FALSE The default value can't be found and set.\r
2537**/\r
2538BOOLEAN\r
2539EFIAPI\r
2540HiiSetToDefaults (\r
2541 IN CONST EFI_STRING Request, OPTIONAL\r
2542 IN UINT16 DefaultId\r
2543 )\r
2544{\r
2545 return InternalHiiIfrValueAction (Request, DefaultId, ACTION_SET_DEFAUTL_VALUE);\r
2546}\r
2547\r
7e3bcccb
LG
2548/**\r
2549 Determines if two values in config strings match.\r
2550\r
2551 Compares the substring between StartSearchString and StopSearchString in \r
2552 FirstString to the substring between StartSearchString and StopSearchString \r
2553 in SecondString. If the two substrings match, then TRUE is returned. If the\r
2554 two substrings do not match, then FALSE is returned.\r
2555\r
2556 If FirstString is NULL, then ASSERT().\r
2557 If SecondString is NULL, then ASSERT().\r
2558 If StartSearchString is NULL, then ASSERT().\r
2559 If StopSearchString is NULL, then ASSERT().\r
2560\r
2561 @param FirstString Pointer to the first Null-terminated Unicode string.\r
2562 @param SecondString Pointer to the second Null-terminated Unicode string.\r
2563 @param StartSearchString Pointer to the Null-terminated Unicode string that \r
2564 marks the start of the value string to compare.\r
2565 @param StopSearchString Pointer to the Null-terminated Unicode string that \r
84213069 2566 marks the end of the value string to compare.\r
7e3bcccb
LG
2567\r
2568 @retval FALSE StartSearchString is not present in FirstString. \r
2569 @retval FALSE StartSearchString is not present in SecondString.\r
2570 @retval FALSE StopSearchString is not present in FirstString. \r
2571 @retval FALSE StopSearchString is not present in SecondString.\r
2572 @retval FALSE The length of the substring in FirstString is not the \r
2573 same length as the substring in SecondString.\r
2574 @retval FALSE The value string in FirstString does not matche the \r
2575 value string in SecondString.\r
2576 @retval TRUE The value string in FirstString matches the value \r
2577 string in SecondString.\r
2578\r
2579**/\r
2580BOOLEAN\r
2581EFIAPI\r
2582InternalHiiCompareSubString (\r
2583 IN CHAR16 *FirstString,\r
2584 IN CHAR16 *SecondString,\r
2585 IN CHAR16 *StartSearchString,\r
2586 IN CHAR16 *StopSearchString\r
2587 )\r
2588{\r
2589 CHAR16 *EndFirstString;\r
2590 CHAR16 *EndSecondString;\r
2591\r
2592 ASSERT (FirstString != NULL);\r
2593 ASSERT (SecondString != NULL);\r
2594 ASSERT (StartSearchString != NULL);\r
2595 ASSERT (StopSearchString != NULL);\r
2596\r
2597 FirstString = StrStr (FirstString, StartSearchString);\r
2598 if (FirstString == NULL) {\r
2599 return FALSE;\r
2600 }\r
2601\r
2602 SecondString = StrStr (SecondString, StartSearchString);\r
2603 if (SecondString == NULL) {\r
2604 return FALSE;\r
2605 }\r
2606\r
2607 EndFirstString = StrStr (FirstString, StopSearchString);\r
2608 if (EndFirstString == NULL) {\r
2609 return FALSE;\r
2610 }\r
2611\r
2612 EndSecondString = StrStr (SecondString, StopSearchString);\r
2613 if (EndSecondString == NULL) {\r
2614 return FALSE;\r
2615 }\r
2616\r
2617 if ((EndFirstString - FirstString) != (EndSecondString - SecondString)) {\r
2618 return FALSE;\r
2619 }\r
2620\r
2621 return (BOOLEAN)(StrnCmp (FirstString, SecondString, EndFirstString - FirstString) == 0);\r
2622}\r
2623\r
2624/**\r
2625 Determines if the routing data specified by GUID and NAME match a <ConfigHdr>.\r
2626\r
2627 If ConfigHdr is NULL, then ASSERT().\r
2628\r
2629 @param[in] ConfigHdr Either <ConfigRequest> or <ConfigResp>.\r
2630 @param[in] Guid GUID of the storage.\r
2631 @param[in] Name NAME of the storage.\r
2632\r
2633 @retval TRUE Routing information matches <ConfigHdr>.\r
2634 @retval FALSE Routing information does not match <ConfigHdr>.\r
2635\r
2636**/\r
2637BOOLEAN\r
2638EFIAPI\r
2639HiiIsConfigHdrMatch (\r
2640 IN CONST EFI_STRING ConfigHdr,\r
2641 IN CONST EFI_GUID *Guid, OPTIONAL\r
2642 IN CONST CHAR16 *Name OPTIONAL\r
2643 )\r
2644{\r
2645 EFI_STRING CompareConfigHdr;\r
2646 BOOLEAN Result;\r
2647\r
2648 ASSERT (ConfigHdr != NULL);\r
2649\r
2650 //\r
2651 // Use Guid and Name to generate a <ConfigHdr> string\r
2652 //\r
2653 CompareConfigHdr = HiiConstructConfigHdr (Guid, Name, NULL);\r
2654 if (CompareConfigHdr == NULL) {\r
2655 return FALSE;\r
2656 }\r
2657\r
2658 Result = TRUE;\r
2659 if (Guid != NULL) {\r
2660 //\r
2661 // Compare GUID value strings\r
2662 //\r
2663 Result = InternalHiiCompareSubString (ConfigHdr, CompareConfigHdr, L"GUID=", L"&NAME=");\r
2664 }\r
2665\r
2666 if (Result && Name != NULL) {\r
2667 //\r
2668 // Compare NAME value strings\r
2669 //\r
2670 Result = InternalHiiCompareSubString (ConfigHdr, CompareConfigHdr, L"&NAME=", L"&PATH=");\r
2671 }\r
2672\r
2673 //\r
2674 // Free the <ConfigHdr> string\r
2675 //\r
2676 FreePool (CompareConfigHdr);\r
2677\r
2678 return Result;\r
2679}\r
2680\r
2681/**\r
84213069 2682 Retrieves uncommitted data from the Form Browser and converts it to a binary\r
1d451ff9 2683 buffer.\r
7e3bcccb 2684\r
1d451ff9
LG
2685 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional \r
2686 parameter that may be NULL.\r
84213069
LG
2687 @param[in] VariableName Pointer to a Null-terminated Unicode string. This \r
2688 is an optional parameter that may be NULL.\r
2689 @param[in] BufferSize Length in bytes of buffer to hold retrieved data. \r
2690 @param[out] Buffer Buffer of data to be updated.\r
7e3bcccb 2691\r
1d451ff9
LG
2692 @retval FALSE The uncommitted data could not be retrieved.\r
2693 @retval TRUE The uncommitted data was retrieved.\r
7e3bcccb
LG
2694\r
2695**/\r
1d451ff9 2696BOOLEAN\r
7e3bcccb
LG
2697EFIAPI\r
2698HiiGetBrowserData (\r
2699 IN CONST EFI_GUID *VariableGuid, OPTIONAL\r
2700 IN CONST CHAR16 *VariableName, OPTIONAL\r
84213069
LG
2701 IN UINTN BufferSize,\r
2702 OUT UINT8 *Buffer\r
7e3bcccb
LG
2703 )\r
2704{\r
2705 EFI_STRING ResultsData;\r
2706 UINTN Size;\r
2707 EFI_STRING ConfigResp;\r
1d451ff9
LG
2708 EFI_STATUS Status;\r
2709 CHAR16 *Progress;\r
7e3bcccb
LG
2710\r
2711 //\r
2712 // Retrieve the results data from the Browser Callback\r
2713 //\r
2714 ResultsData = InternalHiiBrowserCallback (VariableGuid, VariableName, NULL);\r
2715 if (ResultsData == NULL) {\r
1d451ff9 2716 return FALSE;\r
7e3bcccb
LG
2717 }\r
2718\r
2719 //\r
5c1ebff6 2720 // Construct <ConfigResp> mConfigHdrTemplate L'&' ResultsData L'\0'\r
7e3bcccb 2721 //\r
5c1ebff6
LG
2722 Size = (StrLen (mConfigHdrTemplate) + 1) * sizeof (CHAR16);\r
2723 Size = Size + (StrLen (ResultsData) + 1) * sizeof (CHAR16);\r
7e3bcccb
LG
2724 ConfigResp = AllocateZeroPool (Size);\r
2725 UnicodeSPrint (ConfigResp, Size, L"%s&%s", mConfigHdrTemplate, ResultsData);\r
2726 \r
2727 //\r
2728 // Free the allocated buffer\r
2729 //\r
2730 FreePool (ResultsData);\r
2731 if (ConfigResp == NULL) {\r
1d451ff9 2732 return FALSE;\r
7e3bcccb
LG
2733 }\r
2734\r
2735 //\r
2736 // Convert <ConfigResp> to a buffer\r
2737 //\r
1d451ff9
LG
2738 Status = gHiiConfigRouting->ConfigToBlock (\r
2739 gHiiConfigRouting,\r
2740 ConfigResp,\r
84213069
LG
2741 Buffer,\r
2742 &BufferSize,\r
1d451ff9
LG
2743 &Progress\r
2744 );\r
2745 //\r
2746 // Free the allocated buffer\r
2747 //\r
7e3bcccb
LG
2748 FreePool (ConfigResp);\r
2749\r
1d451ff9
LG
2750 if (EFI_ERROR (Status)) {\r
2751 return FALSE;\r
2752 }\r
2753\r
2754 return TRUE;\r
7e3bcccb
LG
2755}\r
2756\r
2757/**\r
2758 Updates uncommitted data in the Form Browser.\r
2759\r
2760 If Buffer is NULL, then ASSERT().\r
2761\r
7e3bcccb
LG
2762 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional\r
2763 parameter that may be NULL.\r
84213069
LG
2764 @param[in] VariableName Pointer to a Null-terminated Unicode string. This\r
2765 is an optional parameter that may be NULL.\r
7e3bcccb
LG
2766 @param[in] BufferSize Length, in bytes, of Buffer.\r
2767 @param[in] Buffer Buffer of data to commit.\r
2768 @param[in] RequestElement An optional field to specify which part of the\r
2769 buffer data will be send back to Browser. If NULL,\r
2770 the whole buffer of data will be committed to\r
2771 Browser. \r
2772 <RequestElement> ::= &OFFSET=<Number>&WIDTH=<Number>*\r
2773\r
2774 @retval FALSE The uncommitted data could not be updated.\r
2775 @retval TRUE The uncommitted data was updated.\r
2776\r
2777**/\r
2778BOOLEAN\r
2779EFIAPI\r
2780HiiSetBrowserData (\r
2781 IN CONST EFI_GUID *VariableGuid, OPTIONAL\r
2782 IN CONST CHAR16 *VariableName, OPTIONAL\r
2783 IN UINTN BufferSize,\r
2784 IN CONST UINT8 *Buffer,\r
2785 IN CONST CHAR16 *RequestElement OPTIONAL\r
2786 )\r
2787{\r
2788 UINTN Size;\r
2789 EFI_STRING ConfigRequest;\r
2790 EFI_STRING ConfigResp;\r
2791 EFI_STRING ResultsData;\r
2792\r
2793 ASSERT (Buffer != NULL);\r
2794\r
2795 //\r
2796 // Construct <ConfigRequest>\r
2797 //\r
2798 if (RequestElement == NULL) {\r
2799 //\r
2800 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template \r
2801 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r
2802 //\r
2803 Size = (StrLen (mConfigHdrTemplate) + 32 + 1) * sizeof (CHAR16);\r
2804 ConfigRequest = AllocateZeroPool (Size);\r
2805 UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", mConfigHdrTemplate, (UINT64)BufferSize);\r
2806 } else {\r
2807 //\r
2808 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template \r
2809 // followed by <RequestElement> followed by a Null-terminator\r
2810 //\r
5c1ebff6
LG
2811 Size = StrLen (mConfigHdrTemplate) * sizeof (CHAR16);\r
2812 Size = Size + (StrLen (RequestElement) + 1) * sizeof (CHAR16);\r
7e3bcccb
LG
2813 ConfigRequest = AllocateZeroPool (Size);\r
2814 UnicodeSPrint (ConfigRequest, Size, L"%s%s", mConfigHdrTemplate, RequestElement);\r
2815 }\r
2816 if (ConfigRequest == NULL) {\r
2817 return FALSE;\r
2818 }\r
2819\r
2820 //\r
2821 // Convert <ConfigRequest> to <ConfigResp>\r
2822 //\r
2823 ConfigResp = InternalHiiBlockToConfig (ConfigRequest, Buffer, BufferSize);\r
2824 FreePool (ConfigRequest);\r
2825 if (ConfigResp == NULL) {\r
2826 return FALSE;\r
2827 }\r
2828\r
2829 //\r
2830 // Set data in the uncommitted browser state information\r
2831 //\r
2832 ResultsData = InternalHiiBrowserCallback (VariableGuid, VariableName, ConfigResp + StrLen(mConfigHdrTemplate) + 1);\r
2833 FreePool (ConfigResp);\r
2834\r
2835 return (BOOLEAN)(ResultsData != NULL);\r
2836}\r
2837\r
2838/////////////////////////////////////////\r
2839/////////////////////////////////////////\r
2840/// IFR Functions\r
2841/////////////////////////////////////////\r
2842/////////////////////////////////////////\r
2843\r
2844#define HII_LIB_OPCODE_ALLOCATION_SIZE 0x200\r
2845\r
2846typedef struct {\r
2847 UINT8 *Buffer;\r
2848 UINTN BufferSize;\r
2849 UINTN Position;\r
2850} HII_LIB_OPCODE_BUFFER;\r
2851\r
2852///\r
2853/// Lookup table that converts EFI_IFR_TYPE_X enum values to a width in bytes\r
2854///\r
2855GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 mHiiDefaultTypeToWidth[] = {\r
2856 1, // EFI_IFR_TYPE_NUM_SIZE_8\r
2857 2, // EFI_IFR_TYPE_NUM_SIZE_16\r
2858 4, // EFI_IFR_TYPE_NUM_SIZE_32\r
2859 8, // EFI_IFR_TYPE_NUM_SIZE_64\r
2860 1, // EFI_IFR_TYPE_BOOLEAN\r
2861 3, // EFI_IFR_TYPE_TIME\r
2862 4, // EFI_IFR_TYPE_DATE\r
2863 2 // EFI_IFR_TYPE_STRING\r
2864};\r
2865\r
2866/**\r
2867 Allocates and returns a new OpCode Handle. OpCode Handles must be freed with \r
2868 HiiFreeOpCodeHandle().\r
2869\r
2870 @retval NULL There are not enough resources to allocate a new OpCode Handle.\r
2871 @retval Other A new OpCode handle.\r
2872\r
2873**/\r
2874VOID *\r
2875EFIAPI\r
2876HiiAllocateOpCodeHandle (\r
2877 VOID\r
2878 )\r
2879{\r
2880 HII_LIB_OPCODE_BUFFER *OpCodeBuffer;\r
2881\r
2882 OpCodeBuffer = (HII_LIB_OPCODE_BUFFER *)AllocatePool (sizeof (HII_LIB_OPCODE_BUFFER));\r
2883 if (OpCodeBuffer == NULL) {\r
2884 return NULL;\r
2885 }\r
2886 OpCodeBuffer->Buffer = (UINT8 *)AllocatePool (HII_LIB_OPCODE_ALLOCATION_SIZE);\r
2887 if (OpCodeBuffer->Buffer == NULL) {\r
2888 FreePool (OpCodeBuffer);\r
2889 return NULL;\r
2890 }\r
2891 OpCodeBuffer->BufferSize = HII_LIB_OPCODE_ALLOCATION_SIZE;\r
2892 OpCodeBuffer->Position = 0;\r
2893 return (VOID *)OpCodeBuffer;\r
2894}\r
2895\r
2896/**\r
84213069 2897 Frees an OpCode Handle that was previously allocated with HiiAllocateOpCodeHandle().\r
7e3bcccb
LG
2898 When an OpCode Handle is freed, all of the opcodes associated with the OpCode\r
2899 Handle are also freed.\r
2900\r
2901 If OpCodeHandle is NULL, then ASSERT().\r
2902\r
84213069
LG
2903 @param[in] OpCodeHandle Handle to the buffer of opcodes.\r
2904\r
7e3bcccb
LG
2905**/\r
2906VOID\r
2907EFIAPI\r
2908HiiFreeOpCodeHandle (\r
2909 VOID *OpCodeHandle\r
2910 )\r
2911{\r
2912 HII_LIB_OPCODE_BUFFER *OpCodeBuffer;\r
2913\r
2914 ASSERT (OpCodeHandle != NULL);\r
2915\r
2916 OpCodeBuffer = (HII_LIB_OPCODE_BUFFER *)OpCodeHandle;\r
2917 if (OpCodeBuffer->Buffer != NULL) {\r
2918 FreePool (OpCodeBuffer->Buffer);\r
2919 }\r
2920 FreePool (OpCodeBuffer);\r
2921}\r
2922\r
84213069
LG
2923/**\r
2924 Internal function gets the current position of opcode buffer.\r
2925 \r
2926 @param[in] OpCodeHandle Handle to the buffer of opcodes.\r
2927\r
2928 @return Current position of opcode buffer.\r
2929**/\r
7e3bcccb
LG
2930UINTN\r
2931EFIAPI\r
2932InternalHiiOpCodeHandlePosition (\r
2933 IN VOID *OpCodeHandle\r
2934 )\r
2935{\r
2936 return ((HII_LIB_OPCODE_BUFFER *)OpCodeHandle)->Position;\r
2937}\r
2938\r
84213069
LG
2939/**\r
2940 Internal function gets the start pointer of opcode buffer.\r
2941 \r
2942 @param[in] OpCodeHandle Handle to the buffer of opcodes.\r
2943\r
2944 @return Pointer to the opcode buffer base.\r
2945**/\r
7e3bcccb
LG
2946UINT8 *\r
2947EFIAPI\r
2948InternalHiiOpCodeHandleBuffer (\r
2949 IN VOID *OpCodeHandle\r
2950 )\r
2951{\r
2952 return ((HII_LIB_OPCODE_BUFFER *)OpCodeHandle)->Buffer;\r
2953}\r
2954\r
84213069
LG
2955/**\r
2956 Internal function reserves the enough buffer for current opcode.\r
2957 When the buffer is not enough, Opcode buffer will be extended.\r
2958 \r
2959 @param[in] OpCodeHandle Handle to the buffer of opcodes.\r
2960 @param[in] Size Size of current opcode.\r
2961\r
2962 @return Pointer to the current opcode.\r
2963**/\r
7e3bcccb
LG
2964UINT8 *\r
2965EFIAPI\r
2966InternalHiiGrowOpCodeHandle (\r
84213069
LG
2967 IN VOID *OpCodeHandle,\r
2968 IN UINTN Size\r
7e3bcccb
LG
2969 )\r
2970{\r
2971 HII_LIB_OPCODE_BUFFER *OpCodeBuffer;\r
2972 UINT8 *Buffer;\r
2973\r
2974 ASSERT (OpCodeHandle != NULL);\r
2975\r
2976 OpCodeBuffer = (HII_LIB_OPCODE_BUFFER *)OpCodeHandle;\r
2977 if (OpCodeBuffer->Position + Size > OpCodeBuffer->BufferSize) {\r
2978 Buffer = ReallocatePool (\r
2979 OpCodeBuffer->BufferSize, \r
2980 OpCodeBuffer->BufferSize + (Size + HII_LIB_OPCODE_ALLOCATION_SIZE),\r
2981 OpCodeBuffer->Buffer\r
2982 );\r
02a758cb 2983 ASSERT (Buffer != NULL);\r
7e3bcccb
LG
2984 OpCodeBuffer->Buffer = Buffer;\r
2985 OpCodeBuffer->BufferSize += (Size + HII_LIB_OPCODE_ALLOCATION_SIZE);\r
2986 }\r
2987 Buffer = OpCodeBuffer->Buffer + OpCodeBuffer->Position;\r
2988 OpCodeBuffer->Position += Size;\r
2989 return Buffer;\r
2990}\r
2991\r
84213069
LG
2992/**\r
2993 Internal function creates opcode based on the template opcode.\r
2994 \r
2995 @param[in] OpCodeHandle Handle to the buffer of opcodes.\r
2996 @param[in] OpCodeTemplate Pointer to the template buffer of opcode.\r
2997 @param[in] OpCode OpCode IFR value.\r
2998 @param[in] OpCodeSize Size of opcode.\r
2999 @param[in] ExtensionSize Size of extended opcode.\r
3000 @param[in] Scope Scope bit of opcode.\r
3001\r
3002 @return Pointer to the current opcode with opcode data.\r
3003**/\r
7e3bcccb
LG
3004UINT8 *\r
3005EFIAPI\r
3006InternalHiiCreateOpCodeExtended (\r
3007 IN VOID *OpCodeHandle,\r
3008 IN VOID *OpCodeTemplate,\r
3009 IN UINT8 OpCode,\r
3010 IN UINTN OpCodeSize,\r
3011 IN UINTN ExtensionSize,\r
3012 IN UINT8 Scope\r
3013 )\r
3014{\r
3015 EFI_IFR_OP_HEADER *Header;\r
3016 UINT8 *Buffer;\r
3017\r
3018 ASSERT (OpCodeTemplate != NULL);\r
3019 ASSERT ((OpCodeSize + ExtensionSize) <= 0x7F);\r
3020\r
3021 Header = (EFI_IFR_OP_HEADER *)OpCodeTemplate;\r
3022 Header->OpCode = OpCode;\r
3023 Header->Scope = Scope;\r
3024 Header->Length = (UINT8)(OpCodeSize + ExtensionSize);\r
3025 Buffer = InternalHiiGrowOpCodeHandle (OpCodeHandle, Header->Length);\r
3026 return (UINT8 *)CopyMem (Buffer, Header, OpCodeSize);\r
3027}\r
3028\r
84213069
LG
3029/**\r
3030 Internal function creates opcode based on the template opcode for the normal opcode.\r
3031 \r
3032 @param[in] OpCodeHandle Handle to the buffer of opcodes.\r
3033 @param[in] OpCodeTemplate Pointer to the template buffer of opcode.\r
3034 @param[in] OpCode OpCode IFR value.\r
3035 @param[in] OpCodeSize Size of opcode.\r
3036\r
3037 @return Pointer to the current opcode with opcode data.\r
3038**/\r
7e3bcccb
LG
3039UINT8 *\r
3040EFIAPI\r
3041InternalHiiCreateOpCode (\r
3042 IN VOID *OpCodeHandle,\r
3043 IN VOID *OpCodeTemplate,\r
3044 IN UINT8 OpCode,\r
3045 IN UINTN OpCodeSize\r
3046 )\r
3047{\r
3048 return InternalHiiCreateOpCodeExtended (OpCodeHandle, OpCodeTemplate, OpCode, OpCodeSize, 0, 0);\r
3049}\r
3050\r
3051/**\r
3052 Append raw opcodes to an OpCodeHandle.\r
3053\r
3054 If OpCodeHandle is NULL, then ASSERT().\r
3055 If RawBuffer is NULL, then ASSERT();\r
3056\r
3057 @param[in] OpCodeHandle Handle to the buffer of opcodes.\r
3058 @param[in] RawBuffer Buffer of opcodes to append.\r
3059 @param[in] RawBufferSize The size, in bytes, of Buffer.\r
3060\r
3061 @retval NULL There is not enough space left in Buffer to add the opcode.\r
3062 @retval Other A pointer to the appended opcodes.\r
3063\r
3064**/\r
3065UINT8 *\r
3066EFIAPI\r
278663ab 3067HiiCreateRawOpCodes (\r
7e3bcccb
LG
3068 IN VOID *OpCodeHandle,\r
3069 IN UINT8 *RawBuffer,\r
3070 IN UINTN RawBufferSize\r
3071 )\r
3072{\r
3073 UINT8 *Buffer;\r
3074\r
3075 ASSERT (RawBuffer != NULL);\r
3076\r
3077 Buffer = InternalHiiGrowOpCodeHandle (OpCodeHandle, RawBufferSize);\r
3078 return (UINT8 *)CopyMem (Buffer, RawBuffer, RawBufferSize);\r
3079}\r
3080\r
3081/**\r
3082 Append opcodes from one OpCode Handle to another OpCode handle.\r
3083\r
3084 If OpCodeHandle is NULL, then ASSERT().\r
3085 If RawOpCodeHandle is NULL, then ASSERT();\r
3086\r
3087 @param[in] OpCodeHandle Handle to the buffer of opcodes.\r
3088 @param[in] RawOpCodeHandle Handle to the buffer of opcodes.\r
3089\r
3090 @retval NULL There is not enough space left in Buffer to add the opcode.\r
3091 @retval Other A pointer to the appended opcodes.\r
3092\r
3093**/\r
3094UINT8 *\r
3095EFIAPI\r
3096InternalHiiAppendOpCodes (\r
3097 IN VOID *OpCodeHandle,\r
3098 IN VOID *RawOpCodeHandle\r
3099 )\r
3100{\r
3101 HII_LIB_OPCODE_BUFFER *RawOpCodeBuffer;\r
3102\r
3103 ASSERT (RawOpCodeHandle != NULL);\r
3104\r
3105 RawOpCodeBuffer = (HII_LIB_OPCODE_BUFFER *)RawOpCodeHandle;\r
278663ab 3106 return HiiCreateRawOpCodes (OpCodeHandle, RawOpCodeBuffer->Buffer, RawOpCodeBuffer->Position);\r
7e3bcccb
LG
3107}\r
3108\r
3109/**\r
3110 Create EFI_IFR_END_OP opcode.\r
3111\r
3112 If OpCodeHandle is NULL, then ASSERT().\r
3113\r
3114 @param[in] OpCodeHandle Handle to the buffer of opcodes.\r
3115\r
3116 @retval NULL There is not enough space left in Buffer to add the opcode.\r
3117 @retval Other A pointer to the created opcode.\r
3118\r
3119**/\r
3120UINT8 *\r
3121EFIAPI\r
3122HiiCreateEndOpCode (\r
3123 IN VOID *OpCodeHandle\r
3124 )\r
3125{\r
3126 EFI_IFR_END OpCode;\r
3127\r
3128 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_END_OP, sizeof (OpCode));\r
3129}\r
3130\r
3131/**\r
3132 Create EFI_IFR_ONE_OF_OPTION_OP opcode.\r
3133\r
3134 If OpCodeHandle is NULL, then ASSERT().\r
3135 If Type is invalid, then ASSERT().\r
3136 If Flags is invalid, then ASSERT().\r
3137\r
3138 @param[in] OpCodeHandle Handle to the buffer of opcodes.\r
3139 @param[in] StringId StringId for the option\r
3140 @param[in] Flags Flags for the option\r
3141 @param[in] Type Type for the option\r
3142 @param[in] Value Value for the option\r
3143\r
3144 @retval NULL There is not enough space left in Buffer to add the opcode.\r
3145 @retval Other A pointer to the created opcode.\r
3146\r
3147**/\r
3148UINT8 *\r
3149EFIAPI\r
3150HiiCreateOneOfOptionOpCode (\r
3151 IN VOID *OpCodeHandle,\r
3152 IN UINT16 StringId,\r
3153 IN UINT8 Flags,\r
3154 IN UINT8 Type,\r
3155 IN UINT64 Value\r
3156 )\r
3157{\r
3158 EFI_IFR_ONE_OF_OPTION OpCode;\r
3159\r
3160 ASSERT (Type < EFI_IFR_TYPE_OTHER);\r
3161\r
3162 ZeroMem (&OpCode, sizeof (OpCode));\r
3163 OpCode.Option = StringId;\r
3164 OpCode.Flags = (UINT8) (Flags & (EFI_IFR_OPTION_DEFAULT | EFI_IFR_OPTION_DEFAULT_MFG));\r
3165 OpCode.Type = Type;\r
3166 CopyMem (&OpCode.Value, &Value, mHiiDefaultTypeToWidth[Type]);\r
3167\r
a7f87053 3168 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_ONE_OF_OPTION_OP, OFFSET_OF(EFI_IFR_ONE_OF_OPTION, Value) + mHiiDefaultTypeToWidth[Type]);\r
7e3bcccb
LG
3169}\r
3170\r
3171/**\r
3172 Create EFI_IFR_DEFAULT_OP opcode.\r
3173\r
3174 If OpCodeHandle is NULL, then ASSERT().\r
3175 If Type is invalid, then ASSERT().\r
3176\r
3177 @param[in] OpCodeHandle Handle to the buffer of opcodes.\r
3178 @param[in] DefaultId DefaultId for the default\r
3179 @param[in] Type Type for the default\r
3180 @param[in] Value Value for the default\r
3181\r
3182 @retval NULL There is not enough space left in Buffer to add the opcode.\r
3183 @retval Other A pointer to the created opcode.\r
3184\r
3185**/\r
3186UINT8 *\r
3187EFIAPI\r
3188HiiCreateDefaultOpCode (\r
3189 IN VOID *OpCodeHandle,\r
3190 IN UINT16 DefaultId,\r
3191 IN UINT8 Type,\r
3192 IN UINT64 Value\r
3193 )\r
3194{\r
3195 EFI_IFR_DEFAULT OpCode;\r
3196\r
3197 ASSERT (Type < EFI_IFR_TYPE_OTHER);\r
3198\r
3199 ZeroMem (&OpCode, sizeof (OpCode));\r
3200 OpCode.Type = Type;\r
3201 OpCode.DefaultId = DefaultId;\r
3202 CopyMem (&OpCode.Value, &Value, mHiiDefaultTypeToWidth[Type]);\r
3203\r
23fe74dc 3204 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_DEFAULT_OP, OFFSET_OF(EFI_IFR_DEFAULT, Value) + mHiiDefaultTypeToWidth[Type]);\r
7e3bcccb
LG
3205}\r
3206\r
3207/**\r
3208 Create EFI_IFR_GUID opcode.\r
3209\r
3210 If OpCodeHandle is NULL, then ASSERT().\r
3211 If Guid is NULL, then ASSERT().\r
3212 If OpCodeSize < sizeof (EFI_IFR_GUID), then ASSERT().\r
3213\r
3214 @param[in] OpCodeHandle Handle to the buffer of opcodes.\r
3215 @param[in] Guid Pointer to EFI_GUID of this guided opcode.\r
3216 @param[in] GuidOpCode Pointer to an EFI_IFR_GUID opcode. This is an \r
3217 optional parameter that may be NULL. If this\r
3218 parameter is NULL, then the GUID extension \r
3219 region of the created opcode is filled with zeros.\r
3220 If this parameter is not NULL, then the GUID \r
3221 extension region of GuidData will be copied to \r
3222 the GUID extension region of the created opcode.\r
3223 @param[in] OpCodeSize The size, in bytes, of created opcode. This value \r
3224 must be >= sizeof(EFI_IFR_GUID).\r
3225\r
3226 @retval NULL There is not enough space left in Buffer to add the opcode.\r
3227 @retval Other A pointer to the created opcode.\r
3228\r
3229**/\r
3230UINT8 *\r
3231EFIAPI\r
3232HiiCreateGuidOpCode (\r
3233 IN VOID *OpCodeHandle,\r
3234 IN CONST EFI_GUID *Guid,\r
3235 IN CONST VOID *GuidOpCode, OPTIONAL\r
3236 IN UINTN OpCodeSize\r
3237 )\r
3238{\r
3239 EFI_IFR_GUID OpCode;\r
3240 EFI_IFR_GUID *OpCodePointer;\r
3241\r
3242 ASSERT (Guid != NULL);\r
3243 ASSERT (OpCodeSize >= sizeof (OpCode));\r
3244\r
3245 ZeroMem (&OpCode, sizeof (OpCode));\r
5c1ebff6 3246 CopyGuid ((EFI_GUID *)(VOID *)&OpCode.Guid, Guid);\r
7e3bcccb
LG
3247\r
3248 OpCodePointer = (EFI_IFR_GUID *)InternalHiiCreateOpCodeExtended (\r
3249 OpCodeHandle, \r
3250 &OpCode,\r
3251 EFI_IFR_GUID_OP,\r
3252 sizeof (OpCode),\r
3253 OpCodeSize - sizeof (OpCode),\r
3254 0\r
3255 );\r
3256 if (OpCodePointer != NULL && GuidOpCode != NULL) {\r
3257 CopyMem (OpCodePointer + 1, (EFI_IFR_GUID *)GuidOpCode + 1, OpCodeSize - sizeof (OpCode));\r
3258 }\r
3259 return (UINT8 *)OpCodePointer;\r
3260}\r
3261\r
3262/**\r
3263 Create EFI_IFR_ACTION_OP opcode.\r
3264\r
3265 If OpCodeHandle is NULL, then ASSERT().\r
3266 If any reserved bits are set in QuestionFlags, then ASSERT().\r
3267\r
3268 @param[in] OpCodeHandle Handle to the buffer of opcodes.\r
3269 @param[in] QuestionId Question ID\r
3270 @param[in] Prompt String ID for Prompt\r
3271 @param[in] Help String ID for Help\r
3272 @param[in] QuestionFlags Flags in Question Header\r
3273 @param[in] QuestionConfig String ID for configuration\r
3274\r
3275 @retval NULL There is not enough space left in Buffer to add the opcode.\r
3276 @retval Other A pointer to the created opcode.\r
3277\r
3278**/\r
3279UINT8 *\r
3280EFIAPI\r
3281HiiCreateActionOpCode (\r
3282 IN VOID *OpCodeHandle,\r
3283 IN EFI_QUESTION_ID QuestionId,\r
3284 IN EFI_STRING_ID Prompt,\r
3285 IN EFI_STRING_ID Help,\r
3286 IN UINT8 QuestionFlags,\r
3287 IN EFI_STRING_ID QuestionConfig\r
3288 )\r
3289{\r
3290 EFI_IFR_ACTION OpCode;\r
3291\r
e22812c7 3292 ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0);\r
7e3bcccb
LG
3293\r
3294 ZeroMem (&OpCode, sizeof (OpCode));\r
3295 OpCode.Question.QuestionId = QuestionId;\r
3296 OpCode.Question.Header.Prompt = Prompt;\r
3297 OpCode.Question.Header.Help = Help;\r
3298 OpCode.Question.Flags = QuestionFlags;\r
3299 OpCode.QuestionConfig = QuestionConfig;\r
3300\r
3301 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_ACTION_OP, sizeof (OpCode));\r
3302}\r
3303\r
3304/**\r
3305 Create EFI_IFR_SUBTITLE_OP opcode.\r
3306\r
3307 If OpCodeHandle is NULL, then ASSERT().\r
3308 If any reserved bits are set in Flags, then ASSERT().\r
3309 If Scope > 1, then ASSERT().\r
3310\r
3311 @param[in] OpCodeHandle Handle to the buffer of opcodes.\r
3312 @param[in] Prompt String ID for Prompt\r
3313 @param[in] Help String ID for Help\r
3314 @param[in] Flags Subtitle opcode flags\r
3315 @param[in] Scope 1 if this opcpde is the beginning of a new scope.\r
3316 0 if this opcode is within the current scope.\r
3317\r
3318 @retval NULL There is not enough space left in Buffer to add the opcode.\r
3319 @retval Other A pointer to the created opcode.\r
3320\r
3321**/\r
3322UINT8 *\r
3323EFIAPI\r
3324HiiCreateSubTitleOpCode (\r
3325 IN VOID *OpCodeHandle,\r
3326 IN EFI_STRING_ID Prompt,\r
3327 IN EFI_STRING_ID Help,\r
3328 IN UINT8 Flags,\r
3329 IN UINT8 Scope\r
3330 )\r
3331{\r
3332 EFI_IFR_SUBTITLE OpCode;\r
3333\r
3334 ASSERT (Scope <= 1);\r
3335 ASSERT ((Flags & (~(EFI_IFR_FLAGS_HORIZONTAL))) == 0);\r
3336\r
3337 ZeroMem (&OpCode, sizeof (OpCode));\r
3338 OpCode.Statement.Prompt = Prompt;\r
3339 OpCode.Statement.Help = Help;\r
3340 OpCode.Flags = Flags;\r
3341\r
3342 return InternalHiiCreateOpCodeExtended (\r
3343 OpCodeHandle, \r
3344 &OpCode,\r
3345 EFI_IFR_SUBTITLE_OP, \r
3346 sizeof (OpCode), \r
3347 0, \r
3348 Scope\r
3349 );\r
3350}\r
3351\r
3352/**\r
3353 Create EFI_IFR_REF_OP opcode.\r
3354\r
3355 If OpCodeHandle is NULL, then ASSERT().\r
3356 If any reserved bits are set in QuestionFlags, then ASSERT().\r
3357\r
3358 @param[in] OpCodeHandle Handle to the buffer of opcodes.\r
3359 @param[in] FormId Destination Form ID\r
3360 @param[in] Prompt String ID for Prompt\r
3361 @param[in] Help String ID for Help\r
3362 @param[in] QuestionFlags Flags in Question Header\r
3363 @param[in] QuestionId Question ID\r
3364\r
3365 @retval NULL There is not enough space left in Buffer to add the opcode.\r
3366 @retval Other A pointer to the created opcode.\r
3367\r
3368**/\r
3369UINT8 *\r
3370EFIAPI\r
3371HiiCreateGotoOpCode (\r
3372 IN VOID *OpCodeHandle,\r
3373 IN EFI_FORM_ID FormId,\r
3374 IN EFI_STRING_ID Prompt,\r
3375 IN EFI_STRING_ID Help,\r
3376 IN UINT8 QuestionFlags,\r
3377 IN EFI_QUESTION_ID QuestionId\r
3378 )\r
3379{\r
3380 EFI_IFR_REF OpCode;\r
3381\r
e22812c7 3382 ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0);\r
7e3bcccb
LG
3383\r
3384 ZeroMem (&OpCode, sizeof (OpCode));\r
3385 OpCode.Question.Header.Prompt = Prompt;\r
3386 OpCode.Question.Header.Help = Help;\r
3387 OpCode.Question.QuestionId = QuestionId;\r
3388 OpCode.Question.Flags = QuestionFlags;\r
3389 OpCode.FormId = FormId;\r
3390\r
3391 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_REF_OP, sizeof (OpCode));\r
3392}\r
3393\r
e8654a1a
LG
3394/**\r
3395 Create EFI_IFR_REF_OP, EFI_IFR_REF2_OP, EFI_IFR_REF3_OP and EFI_IFR_REF4_OP opcode.\r
3396\r
3397 When RefDevicePath is not zero, EFI_IFR_REF4 opcode will be created. \r
3398 When RefDevicePath is zero and RefFormSetId is not NULL, EFI_IFR_REF3 opcode will be created.\r
3399 When RefDevicePath is zero, RefFormSetId is NULL and RefQuestionId is not zero, EFI_IFR_REF2 opcode will be created.\r
3400 When RefDevicePath is zero, RefFormSetId is NULL and RefQuestionId is zero, EFI_IFR_REF opcode will be created.\r
3401\r
3402 If OpCodeHandle is NULL, then ASSERT().\r
3403 If any reserved bits are set in QuestionFlags, then ASSERT().\r
3404\r
3405 @param[in] OpCodeHandle The handle to the buffer of opcodes.\r
3406 @param[in] RefFormId The Destination Form ID.\r
3407 @param[in] Prompt The string ID for Prompt.\r
3408 @param[in] Help The string ID for Help.\r
3409 @param[in] QuestionFlags The flags in Question Header\r
3410 @param[in] QuestionId Question ID.\r
3411 @param[in] RefQuestionId The question on the form to which this link is referring. \r
3412 If its value is zero, then the link refers to the top of the form.\r
3413 @param[in] RefFormSetId The form set to which this link is referring. If its value is NULL, and RefDevicePath is \r
3414 zero, then the link is to the current form set.\r
3415 @param[in] RefDevicePath The string identifier that specifies the string containing the text representation of \r
3416 the device path to which the form set containing the form specified by FormId.\r
3417 If its value is zero, then the link refers to the current page.\r
3418\r
3419 @retval NULL There is not enough space left in Buffer to add the opcode.\r
3420 @retval Other A pointer to the created opcode.\r
3421\r
3422**/\r
3423UINT8 *\r
3424EFIAPI\r
3425HiiCreateGotoExOpCode (\r
3426 IN VOID *OpCodeHandle,\r
3427 IN EFI_FORM_ID RefFormId,\r
3428 IN EFI_STRING_ID Prompt,\r
3429 IN EFI_STRING_ID Help,\r
3430 IN UINT8 QuestionFlags,\r
3431 IN EFI_QUESTION_ID QuestionId,\r
3432 IN EFI_QUESTION_ID RefQuestionId,\r
3433 IN EFI_GUID *RefFormSetId, OPTIONAL\r
3434 IN EFI_STRING_ID RefDevicePath\r
3435 )\r
3436{\r
3437 EFI_IFR_REF4 OpCode;\r
3438 UINTN OpCodeSize;\r
3439\r
3440 ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0);\r
3441\r
3442 ZeroMem (&OpCode, sizeof (OpCode));\r
3443 OpCode.Question.Header.Prompt = Prompt;\r
3444 OpCode.Question.Header.Help = Help;\r
3445 OpCode.Question.QuestionId = QuestionId;\r
3446 OpCode.Question.Flags = QuestionFlags;\r
3447 OpCode.FormId = RefFormId;\r
3448 OpCode.QuestionId = RefQuestionId;\r
3449 OpCode.DevicePath = RefDevicePath;\r
3450 if (RefFormSetId != NULL) {\r
3451 CopyMem (&OpCode.FormSetId, RefFormSetId, sizeof (OpCode.FormSetId));\r
3452 }\r
3453\r
3454 //\r
3455 // Cacluate OpCodeSize based on the input Ref value.\r
3456 // Try to use the small OpCode to save size.\r
3457 //\r
3458 OpCodeSize = sizeof (EFI_IFR_REF);\r
3459 if (RefDevicePath != 0) {\r
3460 OpCodeSize = sizeof (EFI_IFR_REF4);\r
3461 } else if (RefFormSetId != NULL) {\r
3462 OpCodeSize = sizeof (EFI_IFR_REF3);\r
3463 } else if (RefQuestionId != 0) {\r
3464 OpCodeSize = sizeof (EFI_IFR_REF2);\r
3465 }\r
3466\r
3467 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_REF_OP, OpCodeSize);\r
3468}\r
3469\r
7e3bcccb
LG
3470/**\r
3471 Create EFI_IFR_CHECKBOX_OP opcode.\r
3472\r
3473 If OpCodeHandle is NULL, then ASSERT().\r
3474 If any reserved bits are set in QuestionFlags, then ASSERT().\r
3475 If any reserved bits are set in CheckBoxFlags, then ASSERT().\r
3476\r
3477 @param[in] OpCodeHandle Handle to the buffer of opcodes.\r
3478 @param[in] QuestionId Question ID\r
3479 @param[in] VarStoreId Storage ID\r
09acdc0b
ED
3480 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)\r
3481 for this name/value pair.\r
7e3bcccb
LG
3482 @param[in] Prompt String ID for Prompt\r
3483 @param[in] Help String ID for Help\r
3484 @param[in] QuestionFlags Flags in Question Header\r
3485 @param[in] CheckBoxFlags Flags for checkbox opcode\r
3486 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This\r
3487 is an optional parameter that may be NULL.\r
3488\r
3489 @retval NULL There is not enough space left in Buffer to add the opcode.\r
3490 @retval Other A pointer to the created opcode.\r
3491\r
3492**/\r
3493UINT8 *\r
3494EFIAPI\r
3495HiiCreateCheckBoxOpCode (\r
3496 IN VOID *OpCodeHandle,\r
3497 IN EFI_QUESTION_ID QuestionId,\r
3498 IN EFI_VARSTORE_ID VarStoreId,\r
3499 IN UINT16 VarOffset,\r
3500 IN EFI_STRING_ID Prompt,\r
3501 IN EFI_STRING_ID Help,\r
3502 IN UINT8 QuestionFlags,\r
3503 IN UINT8 CheckBoxFlags,\r
3504 IN VOID *DefaultsOpCodeHandle OPTIONAL\r
3505 )\r
3506{\r
3507 EFI_IFR_CHECKBOX OpCode;\r
3508 UINTN Position;\r
3509\r
e22812c7 3510 ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0);\r
7e3bcccb
LG
3511\r
3512 ZeroMem (&OpCode, sizeof (OpCode));\r
3513 OpCode.Question.QuestionId = QuestionId;\r
3514 OpCode.Question.VarStoreId = VarStoreId;\r
3515 OpCode.Question.VarStoreInfo.VarOffset = VarOffset;\r
3516 OpCode.Question.Header.Prompt = Prompt;\r
3517 OpCode.Question.Header.Help = Help;\r
3518 OpCode.Question.Flags = QuestionFlags;\r
3519 OpCode.Flags = CheckBoxFlags;\r
3520\r
3521 if (DefaultsOpCodeHandle == NULL) {\r
3522 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_CHECKBOX_OP, sizeof (OpCode));\r
3523 }\r
3524\r
3525 Position = InternalHiiOpCodeHandlePosition (OpCodeHandle);\r
3526 InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_CHECKBOX_OP, sizeof (OpCode), 0, 1);\r
3527 InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle);\r
3528 HiiCreateEndOpCode (OpCodeHandle);\r
3529 return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position;\r
3530}\r
3531\r
3532/**\r
3533 Create EFI_IFR_NUMERIC_OP opcode.\r
3534\r
3535 If OpCodeHandle is NULL, then ASSERT().\r
3536 If any reserved bits are set in QuestionFlags, then ASSERT().\r
3537 If any reserved bits are set in NumericFlags, then ASSERT().\r
3538\r
3539 @param[in] OpCodeHandle Handle to the buffer of opcodes.\r
3540 @param[in] QuestionId Question ID\r
3541 @param[in] VarStoreId Storage ID\r
09acdc0b
ED
3542 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)\r
3543 for this name/value pair.\r
7e3bcccb
LG
3544 @param[in] Prompt String ID for Prompt\r
3545 @param[in] Help String ID for Help\r
3546 @param[in] QuestionFlags Flags in Question Header\r
3547 @param[in] NumericFlags Flags for numeric opcode\r
3548 @param[in] Minimum Numeric minimum value\r
3549 @param[in] Maximum Numeric maximum value\r
3550 @param[in] Step Numeric step for edit\r
3551 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This\r
3552 is an optional parameter that may be NULL.\r
3553\r
3554 @retval NULL There is not enough space left in Buffer to add the opcode.\r
3555 @retval Other A pointer to the created opcode.\r
3556\r
3557**/\r
3558UINT8 *\r
3559EFIAPI\r
3560HiiCreateNumericOpCode (\r
3561 IN VOID *OpCodeHandle,\r
3562 IN EFI_QUESTION_ID QuestionId,\r
3563 IN EFI_VARSTORE_ID VarStoreId,\r
3564 IN UINT16 VarOffset,\r
3565 IN EFI_STRING_ID Prompt,\r
3566 IN EFI_STRING_ID Help,\r
3567 IN UINT8 QuestionFlags,\r
3568 IN UINT8 NumericFlags,\r
3569 IN UINT64 Minimum,\r
3570 IN UINT64 Maximum,\r
3571 IN UINT64 Step,\r
3572 IN VOID *DefaultsOpCodeHandle OPTIONAL\r
3573 )\r
3574{\r
3575 EFI_IFR_NUMERIC OpCode;\r
3576 UINTN Position;\r
d5931219 3577 UINTN Length;\r
7e3bcccb 3578\r
e22812c7 3579 ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0);\r
7e3bcccb 3580\r
d5931219 3581 Length = 0;\r
7e3bcccb
LG
3582 ZeroMem (&OpCode, sizeof (OpCode));\r
3583 OpCode.Question.QuestionId = QuestionId;\r
3584 OpCode.Question.VarStoreId = VarStoreId;\r
3585 OpCode.Question.VarStoreInfo.VarOffset = VarOffset;\r
3586 OpCode.Question.Header.Prompt = Prompt;\r
3587 OpCode.Question.Header.Help = Help;\r
3588 OpCode.Question.Flags = QuestionFlags;\r
3589 OpCode.Flags = NumericFlags;\r
3590\r
3591 switch (NumericFlags & EFI_IFR_NUMERIC_SIZE) {\r
3592 case EFI_IFR_NUMERIC_SIZE_1:\r
3593 OpCode.data.u8.MinValue = (UINT8)Minimum;\r
3594 OpCode.data.u8.MaxValue = (UINT8)Maximum;\r
3595 OpCode.data.u8.Step = (UINT8)Step;\r
d5931219 3596 Length = 3;\r
7e3bcccb
LG
3597 break;\r
3598\r
3599 case EFI_IFR_NUMERIC_SIZE_2:\r
3600 OpCode.data.u16.MinValue = (UINT16)Minimum;\r
3601 OpCode.data.u16.MaxValue = (UINT16)Maximum;\r
3602 OpCode.data.u16.Step = (UINT16)Step;\r
d5931219 3603 Length = 6;\r
7e3bcccb
LG
3604 break;\r
3605\r
3606 case EFI_IFR_NUMERIC_SIZE_4:\r
3607 OpCode.data.u32.MinValue = (UINT32)Minimum;\r
3608 OpCode.data.u32.MaxValue = (UINT32)Maximum;\r
3609 OpCode.data.u32.Step = (UINT32)Step;\r
d5931219 3610 Length = 12;\r
7e3bcccb
LG
3611 break;\r
3612\r
3613 case EFI_IFR_NUMERIC_SIZE_8:\r
3614 OpCode.data.u64.MinValue = Minimum;\r
3615 OpCode.data.u64.MaxValue = Maximum;\r
3616 OpCode.data.u64.Step = Step;\r
d5931219 3617 Length = 24;\r
7e3bcccb
LG
3618 break;\r
3619 }\r
3620\r
d5931219
ED
3621 Length += OFFSET_OF (EFI_IFR_NUMERIC, data);\r
3622\r
7e3bcccb 3623 if (DefaultsOpCodeHandle == NULL) {\r
d5931219 3624 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_NUMERIC_OP, Length);\r
7e3bcccb
LG
3625 }\r
3626\r
3627 Position = InternalHiiOpCodeHandlePosition (OpCodeHandle);\r
d5931219 3628 InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_NUMERIC_OP, Length, 0, 1);\r
7e3bcccb
LG
3629 InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle);\r
3630 HiiCreateEndOpCode (OpCodeHandle);\r
3631 return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position;\r
3632}\r
3633\r
3634/**\r
3635 Create EFI_IFR_STRING_OP opcode.\r
3636\r
3637 If OpCodeHandle is NULL, then ASSERT().\r
3638 If any reserved bits are set in QuestionFlags, then ASSERT().\r
3639 If any reserved bits are set in StringFlags, then ASSERT().\r
3640\r
3641 @param[in] OpCodeHandle Handle to the buffer of opcodes.\r
3642 @param[in] QuestionId Question ID\r
3643 @param[in] VarStoreId Storage ID\r
09acdc0b
ED
3644 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)\r
3645 for this name/value pair.\r
7e3bcccb
LG
3646 @param[in] Prompt String ID for Prompt\r
3647 @param[in] Help String ID for Help\r
3648 @param[in] QuestionFlags Flags in Question Header\r
3649 @param[in] StringFlags Flags for string opcode\r
3650 @param[in] MinSize String minimum length\r
3651 @param[in] MaxSize String maximum length\r
3652 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This\r
3653 is an optional parameter that may be NULL.\r
3654\r
3655 @retval NULL There is not enough space left in Buffer to add the opcode.\r
3656 @retval Other A pointer to the created opcode.\r
3657\r
3658**/\r
3659UINT8 *\r
3660EFIAPI\r
3661HiiCreateStringOpCode (\r
3662 IN VOID *OpCodeHandle,\r
3663 IN EFI_QUESTION_ID QuestionId,\r
3664 IN EFI_VARSTORE_ID VarStoreId,\r
3665 IN UINT16 VarOffset,\r
3666 IN EFI_STRING_ID Prompt,\r
3667 IN EFI_STRING_ID Help,\r
3668 IN UINT8 QuestionFlags,\r
3669 IN UINT8 StringFlags,\r
3670 IN UINT8 MinSize,\r
3671 IN UINT8 MaxSize,\r
3672 IN VOID *DefaultsOpCodeHandle OPTIONAL\r
3673 )\r
3674{\r
3675 EFI_IFR_STRING OpCode;\r
3676 UINTN Position;\r
3677\r
e22812c7 3678 ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0);\r
7e3bcccb
LG
3679\r
3680 ZeroMem (&OpCode, sizeof (OpCode));\r
3681 OpCode.Question.Header.Prompt = Prompt;\r
3682 OpCode.Question.Header.Help = Help;\r
3683 OpCode.Question.QuestionId = QuestionId;\r
3684 OpCode.Question.VarStoreId = VarStoreId;\r
3685 OpCode.Question.VarStoreInfo.VarOffset = VarOffset;\r
3686 OpCode.Question.Flags = QuestionFlags;\r
3687 OpCode.MinSize = MinSize;\r
3688 OpCode.MaxSize = MaxSize;\r
3689 OpCode.Flags = (UINT8) (StringFlags & EFI_IFR_STRING_MULTI_LINE);\r
3690\r
3691 if (DefaultsOpCodeHandle == NULL) {\r
3692 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_STRING_OP, sizeof (OpCode));\r
3693 }\r
3694\r
3695 Position = InternalHiiOpCodeHandlePosition (OpCodeHandle);\r
3696 InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_STRING_OP, sizeof (OpCode), 0, 1);\r
3697 InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle);\r
3698 HiiCreateEndOpCode (OpCodeHandle);\r
3699 return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position;\r
3700}\r
3701\r
3702/**\r
3703 Create EFI_IFR_ONE_OF_OP opcode.\r
3704\r
3705 If OpCodeHandle is NULL, then ASSERT().\r
3706 If any reserved bits are set in QuestionFlags, then ASSERT().\r
3707 If any reserved bits are set in OneOfFlags, then ASSERT().\r
3708\r
3709 @param[in] OpCodeHandle Handle to the buffer of opcodes.\r
3710 @param[in] QuestionId Question ID\r
3711 @param[in] VarStoreId Storage ID\r
09acdc0b
ED
3712 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)\r
3713 for this name/value pair.\r
7e3bcccb
LG
3714 @param[in] Prompt String ID for Prompt\r
3715 @param[in] Help String ID for Help\r
3716 @param[in] QuestionFlags Flags in Question Header\r
3717 @param[in] OneOfFlags Flags for oneof opcode\r
3718 @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.\r
3719 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This\r
3720 is an optional parameter that may be NULL.\r
3721\r
3722 @retval NULL There is not enough space left in Buffer to add the opcode.\r
3723 @retval Other A pointer to the created opcode.\r
3724\r
3725**/\r
3726UINT8 *\r
3727EFIAPI\r
3728HiiCreateOneOfOpCode (\r
3729 IN VOID *OpCodeHandle,\r
3730 IN EFI_QUESTION_ID QuestionId,\r
3731 IN EFI_VARSTORE_ID VarStoreId,\r
3732 IN UINT16 VarOffset,\r
3733 IN EFI_STRING_ID Prompt,\r
3734 IN EFI_STRING_ID Help,\r
3735 IN UINT8 QuestionFlags,\r
3736 IN UINT8 OneOfFlags,\r
3737 IN VOID *OptionsOpCodeHandle,\r
3738 IN VOID *DefaultsOpCodeHandle OPTIONAL\r
3739 )\r
3740{\r
3741 EFI_IFR_ONE_OF OpCode;\r
3742 UINTN Position;\r
dcf5ba47 3743 UINTN Length;\r
7e3bcccb
LG
3744\r
3745 ASSERT (OptionsOpCodeHandle != NULL);\r
3746 ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY))) == 0);\r
3747\r
3748 ZeroMem (&OpCode, sizeof (OpCode));\r
3749 OpCode.Question.Header.Prompt = Prompt;\r
3750 OpCode.Question.Header.Help = Help;\r
3751 OpCode.Question.QuestionId = QuestionId;\r
3752 OpCode.Question.VarStoreId = VarStoreId;\r
3753 OpCode.Question.VarStoreInfo.VarOffset = VarOffset;\r
3754 OpCode.Question.Flags = QuestionFlags;\r
3755 OpCode.Flags = OneOfFlags;\r
3756\r
dcf5ba47
ED
3757 Length = OFFSET_OF (EFI_IFR_ONE_OF, data);\r
3758 Length += (1 << (OneOfFlags & EFI_IFR_NUMERIC_SIZE)) * 3;\r
3759\r
7e3bcccb 3760 Position = InternalHiiOpCodeHandlePosition (OpCodeHandle);\r
dcf5ba47 3761 InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_ONE_OF_OP, Length, 0, 1);\r
7e3bcccb
LG
3762 InternalHiiAppendOpCodes (OpCodeHandle, OptionsOpCodeHandle);\r
3763 if (DefaultsOpCodeHandle != NULL) {\r
3764 InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle);\r
3765 }\r
3766 HiiCreateEndOpCode (OpCodeHandle);\r
3767 return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position;\r
3768}\r
3769\r
3770/**\r
3771 Create EFI_IFR_ORDERED_LIST_OP opcode.\r
3772\r
3773 If OpCodeHandle is NULL, then ASSERT().\r
3774 If any reserved bits are set in QuestionFlags, then ASSERT().\r
3775 If any reserved bits are set in OrderedListFlags, then ASSERT().\r
3776\r
3777 @param[in] OpCodeHandle Handle to the buffer of opcodes.\r
3778 @param[in] QuestionId Question ID\r
3779 @param[in] VarStoreId Storage ID\r
09acdc0b
ED
3780 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)\r
3781 for this name/value pair.\r
7e3bcccb
LG
3782 @param[in] Prompt String ID for Prompt\r
3783 @param[in] Help String ID for Help\r
3784 @param[in] QuestionFlags Flags in Question Header\r
3785 @param[in] OrderedListFlags Flags for ordered list opcode\r
3786 @param[in] DataType Type for option value\r
3787 @param[in] MaxContainers Maximum count for options in this ordered list\r
3788 @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.\r
3789 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This\r
3790 is an optional parameter that may be NULL.\r
3791\r
3792 @retval NULL There is not enough space left in Buffer to add the opcode.\r
3793 @retval Other A pointer to the created opcode.\r
3794\r
3795**/\r
3796UINT8 *\r
3797EFIAPI\r
3798HiiCreateOrderedListOpCode (\r
3799 IN VOID *OpCodeHandle,\r
3800 IN EFI_QUESTION_ID QuestionId,\r
3801 IN EFI_VARSTORE_ID VarStoreId,\r
3802 IN UINT16 VarOffset,\r
3803 IN EFI_STRING_ID Prompt,\r
3804 IN EFI_STRING_ID Help,\r
3805 IN UINT8 QuestionFlags,\r
3806 IN UINT8 OrderedListFlags,\r
3807 IN UINT8 DataType,\r
3808 IN UINT8 MaxContainers,\r
3809 IN VOID *OptionsOpCodeHandle,\r
3810 IN VOID *DefaultsOpCodeHandle OPTIONAL\r
3811 )\r
3812{\r
3813 EFI_IFR_ORDERED_LIST OpCode;\r
3814 UINTN Position;\r
3815\r
3816 ASSERT (OptionsOpCodeHandle != NULL);\r
3817 ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY))) == 0);\r
3818\r
3819 ZeroMem (&OpCode, sizeof (OpCode));\r
3820 OpCode.Question.Header.Prompt = Prompt;\r
3821 OpCode.Question.Header.Help = Help;\r
3822 OpCode.Question.QuestionId = QuestionId;\r
3823 OpCode.Question.VarStoreId = VarStoreId;\r
3824 OpCode.Question.VarStoreInfo.VarOffset = VarOffset;\r
3825 OpCode.Question.Flags = QuestionFlags;\r
3826 OpCode.MaxContainers = MaxContainers;\r
3827 OpCode.Flags = OrderedListFlags;\r
3828\r
3829 Position = InternalHiiOpCodeHandlePosition (OpCodeHandle);\r
3830 InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_ORDERED_LIST_OP, sizeof (OpCode), 0, 1);\r
3831 InternalHiiAppendOpCodes (OpCodeHandle, OptionsOpCodeHandle);\r
3832 if (DefaultsOpCodeHandle != NULL) {\r
3833 InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle);\r
3834 }\r
3835 HiiCreateEndOpCode (OpCodeHandle);\r
e22812c7
LG
3836 return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position;\r
3837}\r
3838\r
3839/**\r
3840 Create EFI_IFR_TEXT_OP opcode.\r
3841\r
3842 If OpCodeHandle is NULL, then ASSERT().\r
3843\r
3844 @param[in] OpCodeHandle Handle to the buffer of opcodes.\r
3845 @param[in] Prompt String ID for Prompt.\r
3846 @param[in] Help String ID for Help.\r
3847 @param[in] TextTwo String ID for TextTwo.\r
3848\r
3849 @retval NULL There is not enough space left in Buffer to add the opcode.\r
3850 @retval Other A pointer to the created opcode.\r
3851\r
3852**/\r
3853UINT8 *\r
3854EFIAPI\r
3855HiiCreateTextOpCode (\r
3856 IN VOID *OpCodeHandle,\r
3857 IN EFI_STRING_ID Prompt,\r
3858 IN EFI_STRING_ID Help,\r
3859 IN EFI_STRING_ID TextTwo\r
3860 )\r
3861{\r
3862 EFI_IFR_TEXT OpCode;\r
3863\r
3864 ZeroMem (&OpCode, sizeof (OpCode));\r
3865 OpCode.Statement.Prompt = Prompt;\r
3866 OpCode.Statement.Help = Help;\r
3867 OpCode.TextTwo = TextTwo;\r
3868\r
3869 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_TEXT_OP, sizeof (OpCode));\r
3870}\r
3871\r
3872/**\r
3873 Create EFI_IFR_DATE_OP opcode.\r
3874\r
3875 If OpCodeHandle is NULL, then ASSERT().\r
3876 If any reserved bits are set in QuestionFlags, then ASSERT().\r
3877 If any reserved bits are set in DateFlags, then ASSERT().\r
3878\r
3879 @param[in] OpCodeHandle Handle to the buffer of opcodes.\r
3880 @param[in] QuestionId Question ID\r
3881 @param[in] VarStoreId Storage ID, optional. If DateFlags is not\r
3882 QF_DATE_STORAGE_NORMAL, this parameter is ignored.\r
09acdc0b
ED
3883 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)\r
3884 for this name/value pair, optional. If DateFlags is not\r
e22812c7
LG
3885 QF_DATE_STORAGE_NORMAL, this parameter is ignored.\r
3886 @param[in] Prompt String ID for Prompt\r
3887 @param[in] Help String ID for Help\r
3888 @param[in] QuestionFlags Flags in Question Header\r
3889 @param[in] DateFlags Flags for date opcode\r
3890 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This\r
3891 is an optional parameter that may be NULL.\r
3892\r
3893 @retval NULL There is not enough space left in Buffer to add the opcode.\r
3894 @retval Other A pointer to the created opcode.\r
3895\r
3896**/\r
3897UINT8 *\r
3898EFIAPI\r
3899HiiCreateDateOpCode (\r
3900 IN VOID *OpCodeHandle,\r
3901 IN EFI_QUESTION_ID QuestionId,\r
3902 IN EFI_VARSTORE_ID VarStoreId, OPTIONAL\r
3903 IN UINT16 VarOffset, OPTIONAL\r
3904 IN EFI_STRING_ID Prompt,\r
3905 IN EFI_STRING_ID Help,\r
3906 IN UINT8 QuestionFlags,\r
3907 IN UINT8 DateFlags,\r
3908 IN VOID *DefaultsOpCodeHandle OPTIONAL\r
3909 )\r
3910{\r
3911 EFI_IFR_DATE OpCode;\r
3912 UINTN Position;\r
3913\r
3914 ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0);\r
3915 ASSERT ((DateFlags & (~(EFI_QF_DATE_YEAR_SUPPRESS | EFI_QF_DATE_MONTH_SUPPRESS | EFI_QF_DATE_DAY_SUPPRESS | EFI_QF_DATE_STORAGE))) == 0);\r
3916\r
3917 ZeroMem (&OpCode, sizeof (OpCode));\r
3918 OpCode.Question.Header.Prompt = Prompt;\r
3919 OpCode.Question.Header.Help = Help;\r
3920 OpCode.Question.QuestionId = QuestionId;\r
3921 OpCode.Question.VarStoreId = VarStoreId;\r
3922 OpCode.Question.VarStoreInfo.VarOffset = VarOffset;\r
3923 OpCode.Question.Flags = QuestionFlags;\r
3924 OpCode.Flags = DateFlags;\r
3925\r
3926 if (DefaultsOpCodeHandle == NULL) {\r
3927 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_DATE_OP, sizeof (OpCode));\r
3928 }\r
3929\r
3930 Position = InternalHiiOpCodeHandlePosition (OpCodeHandle);\r
3931 InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_DATE_OP, sizeof (OpCode), 0, 1);\r
3932 InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle);\r
3933 HiiCreateEndOpCode (OpCodeHandle);\r
3934 return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position;\r
3935}\r
3936\r
3937/**\r
3938 Create EFI_IFR_TIME_OP opcode.\r
3939\r
3940 If OpCodeHandle is NULL, then ASSERT().\r
3941 If any reserved bits are set in QuestionFlags, then ASSERT().\r
3942 If any reserved bits are set in TimeFlags, then ASSERT().\r
3943\r
3944 @param[in] OpCodeHandle Handle to the buffer of opcodes.\r
3945 @param[in] QuestionId Question ID\r
3946 @param[in] VarStoreId Storage ID, optional. If TimeFlags is not\r
3947 QF_TIME_STORAGE_NORMAL, this parameter is ignored.\r
09acdc0b
ED
3948 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)\r
3949 for this name/value pair, optional. If TimeFlags is not\r
e22812c7
LG
3950 QF_TIME_STORAGE_NORMAL, this parameter is ignored.\r
3951 @param[in] Prompt String ID for Prompt\r
3952 @param[in] Help String ID for Help\r
3953 @param[in] QuestionFlags Flags in Question Header\r
3954 @param[in] TimeFlags Flags for time opcode\r
3955 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This\r
3956 is an optional parameter that may be NULL.\r
3957\r
3958 @retval NULL There is not enough space left in Buffer to add the opcode.\r
3959 @retval Other A pointer to the created opcode.\r
3960\r
3961**/\r
3962UINT8 *\r
3963EFIAPI\r
3964HiiCreateTimeOpCode (\r
3965 IN VOID *OpCodeHandle,\r
3966 IN EFI_QUESTION_ID QuestionId,\r
3967 IN EFI_VARSTORE_ID VarStoreId, OPTIONAL\r
3968 IN UINT16 VarOffset, OPTIONAL\r
3969 IN EFI_STRING_ID Prompt,\r
3970 IN EFI_STRING_ID Help,\r
3971 IN UINT8 QuestionFlags,\r
3972 IN UINT8 TimeFlags,\r
3973 IN VOID *DefaultsOpCodeHandle OPTIONAL\r
3974 )\r
3975{\r
3976 EFI_IFR_TIME OpCode;\r
3977 UINTN Position;\r
3978\r
3979 ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0);\r
3980 ASSERT ((TimeFlags & (~(QF_TIME_HOUR_SUPPRESS | QF_TIME_MINUTE_SUPPRESS | QF_TIME_SECOND_SUPPRESS | QF_TIME_STORAGE))) == 0);\r
3981\r
3982 ZeroMem (&OpCode, sizeof (OpCode));\r
3983 OpCode.Question.Header.Prompt = Prompt;\r
3984 OpCode.Question.Header.Help = Help;\r
3985 OpCode.Question.QuestionId = QuestionId;\r
3986 OpCode.Question.VarStoreId = VarStoreId;\r
3987 OpCode.Question.VarStoreInfo.VarOffset = VarOffset;\r
3988 OpCode.Question.Flags = QuestionFlags;\r
3989 OpCode.Flags = TimeFlags;\r
3990\r
3991 if (DefaultsOpCodeHandle == NULL) {\r
3992 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_TIME_OP, sizeof (OpCode));\r
3993 }\r
3994\r
3995 Position = InternalHiiOpCodeHandlePosition (OpCodeHandle);\r
3996 InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_TIME_OP, sizeof (OpCode), 0, 1);\r
3997 InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle);\r
3998 HiiCreateEndOpCode (OpCodeHandle);\r
7e3bcccb
LG
3999 return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position;\r
4000}\r
4001\r
4002/**\r
4003 This is the internal worker function to update the data in\r
4004 a form specified by FormSetGuid, FormId and Label.\r
4005\r
84213069
LG
4006 @param[in] FormSetGuid The optional Formset GUID.\r
4007 @param[in] FormId The Form ID.\r
4008 @param[in] Package The package header.\r
4009 @param[in] OpCodeBufferStart An OpCode buffer that contains the set of IFR \r
4010 opcodes to be inserted or replaced in the form.\r
4011 @param[in] OpCodeBufferEnd An OpCcode buffer that contains the IFR opcode\r
4012 that marks the end of a replace operation in the form.\r
4013 @param[out] TempPackage The resultant package.\r
7e3bcccb
LG
4014\r
4015 @retval EFI_SUCCESS The function completes successfully.\r
84213069 4016 @retval EFI_NOT_FOUND The updated opcode or endopcode is not found.\r
7e3bcccb
LG
4017\r
4018**/\r
4019EFI_STATUS\r
4020EFIAPI\r
4021InternalHiiUpdateFormPackageData (\r
4022 IN EFI_GUID *FormSetGuid, OPTIONAL\r
4023 IN EFI_FORM_ID FormId,\r
4024 IN EFI_HII_PACKAGE_HEADER *Package,\r
4025 IN HII_LIB_OPCODE_BUFFER *OpCodeBufferStart,\r
4026 IN HII_LIB_OPCODE_BUFFER *OpCodeBufferEnd, OPTIONAL\r
4027 OUT EFI_HII_PACKAGE_HEADER *TempPackage\r
4028 )\r
4029{\r
4030 UINTN AddSize;\r
4031 UINT8 *BufferPos;\r
4032 EFI_HII_PACKAGE_HEADER PackageHeader;\r
4033 UINTN Offset;\r
4034 EFI_IFR_OP_HEADER *IfrOpHdr;\r
4035 EFI_IFR_OP_HEADER *UpdateIfrOpHdr;\r
4036 BOOLEAN GetFormSet;\r
4037 BOOLEAN GetForm;\r
4038 BOOLEAN Updated;\r
d91c7bf9 4039 UINTN UpdatePackageLength;\r
7e3bcccb
LG
4040\r
4041 CopyMem (TempPackage, Package, sizeof (EFI_HII_PACKAGE_HEADER));\r
4042 UpdatePackageLength = sizeof (EFI_HII_PACKAGE_HEADER);\r
4043 BufferPos = (UINT8 *) (TempPackage + 1);\r
4044\r
4045 CopyMem (&PackageHeader, Package, sizeof (EFI_HII_PACKAGE_HEADER));\r
4046 IfrOpHdr = (EFI_IFR_OP_HEADER *)((UINT8 *) Package + sizeof (EFI_HII_PACKAGE_HEADER));\r
4047 Offset = sizeof (EFI_HII_PACKAGE_HEADER);\r
4048 GetFormSet = (BOOLEAN) ((FormSetGuid == NULL) ? TRUE : FALSE);\r
4049 GetForm = FALSE;\r
4050 Updated = FALSE;\r
4051\r
4052 while (Offset < PackageHeader.Length) {\r
4053 CopyMem (BufferPos, IfrOpHdr, IfrOpHdr->Length);\r
4054 BufferPos += IfrOpHdr->Length;\r
4055 UpdatePackageLength += IfrOpHdr->Length;\r
4056 \r
4057 //\r
4058 // Find the matched FormSet and Form\r
4059 //\r
4060 if ((IfrOpHdr->OpCode == EFI_IFR_FORM_SET_OP) && (FormSetGuid != NULL)) {\r
4061 if (CompareGuid((GUID *)(VOID *)&((EFI_IFR_FORM_SET *) IfrOpHdr)->Guid, FormSetGuid)) {\r
4062 GetFormSet = TRUE;\r
4063 } else {\r
4064 GetFormSet = FALSE;\r
4065 }\r
2573712e 4066 } else if (IfrOpHdr->OpCode == EFI_IFR_FORM_OP || IfrOpHdr->OpCode == EFI_IFR_FORM_MAP_OP) {\r
7e3bcccb
LG
4067 if (CompareMem (&((EFI_IFR_FORM *) IfrOpHdr)->FormId, &FormId, sizeof (EFI_FORM_ID)) == 0) {\r
4068 GetForm = TRUE;\r
4069 } else {\r
4070 GetForm = FALSE;\r
4071 }\r
4072 }\r
4073 \r
4074 //\r
4075 // The matched Form is found, and Update data in this form\r
4076 //\r
d91c7bf9 4077 if (GetFormSet && GetForm) {\r
7e3bcccb
LG
4078 UpdateIfrOpHdr = (EFI_IFR_OP_HEADER *) OpCodeBufferStart->Buffer;\r
4079 if ((UpdateIfrOpHdr->Length == IfrOpHdr->Length) && \\r
4080 (CompareMem (IfrOpHdr, UpdateIfrOpHdr, UpdateIfrOpHdr->Length) == 0)) {\r
4081 //\r
4082 // Remove the original data when End OpCode buffer exist.\r
4083 //\r
4084 if (OpCodeBufferEnd != NULL) {\r
4085 Offset += IfrOpHdr->Length;\r
4086 IfrOpHdr = (EFI_IFR_OP_HEADER *) ((UINT8 *) (IfrOpHdr) + IfrOpHdr->Length);\r
4087 UpdateIfrOpHdr = (EFI_IFR_OP_HEADER *) OpCodeBufferEnd->Buffer;\r
4088 while (Offset < PackageHeader.Length) {\r
4089 //\r
4090 // Search the matched end opcode\r
4091 //\r
4092 if ((UpdateIfrOpHdr->Length == IfrOpHdr->Length) && \\r
4093 (CompareMem (IfrOpHdr, UpdateIfrOpHdr, UpdateIfrOpHdr->Length) == 0)) {\r
4094 break;\r
4095 }\r
4096 //\r
4097 // Go to the next Op-Code\r
4098 //\r
4099 Offset += IfrOpHdr->Length;\r
4100 IfrOpHdr = (EFI_IFR_OP_HEADER *) ((UINT8 *) (IfrOpHdr) + IfrOpHdr->Length);\r
4101 }\r
4102 \r
4103 if (Offset >= PackageHeader.Length) {\r
4104 //\r
4105 // The end opcode is not found.\r
4106 //\r
4107 return EFI_NOT_FOUND;\r
4108 }\r
4109 }\r
d91c7bf9 4110\r
7e3bcccb
LG
4111 //\r
4112 // Insert the updated data\r
4113 //\r
d91c7bf9
LG
4114 AddSize = ((EFI_IFR_OP_HEADER *) OpCodeBufferStart->Buffer)->Length;\r
4115 CopyMem (BufferPos, OpCodeBufferStart->Buffer + AddSize, OpCodeBufferStart->Position - AddSize);\r
4116 BufferPos += OpCodeBufferStart->Position - AddSize;\r
4117 UpdatePackageLength += OpCodeBufferStart->Position - AddSize;\r
b8215f46 4118\r
7e3bcccb
LG
4119 if (OpCodeBufferEnd != NULL) {\r
4120 //\r
4121 // Add the end opcode\r
4122 //\r
4123 CopyMem (BufferPos, IfrOpHdr, IfrOpHdr->Length);\r
4124 BufferPos += IfrOpHdr->Length;\r
4125 UpdatePackageLength += IfrOpHdr->Length;\r
4126 }\r
d91c7bf9
LG
4127\r
4128 //\r
4129 // Copy the left package data.\r
4130 //\r
4131 Offset += IfrOpHdr->Length;\r
4132 CopyMem (BufferPos, (UINT8 *) Package + Offset, PackageHeader.Length - Offset);\r
4133 UpdatePackageLength += PackageHeader.Length - Offset;\r
4134\r
7e3bcccb
LG
4135 //\r
4136 // Set update flag\r
4137 //\r
4138 Updated = TRUE;\r
d91c7bf9 4139 break;\r
7e3bcccb
LG
4140 }\r
4141 }\r
4142\r
4143 //\r
4144 // Go to the next Op-Code\r
4145 //\r
4146 Offset += IfrOpHdr->Length;\r
4147 IfrOpHdr = (EFI_IFR_OP_HEADER *) ((CHAR8 *) (IfrOpHdr) + IfrOpHdr->Length);\r
4148 }\r
4149 \r
4150 if (!Updated) {\r
4151 //\r
4152 // The updated opcode buffer is not found.\r
4153 //\r
4154 return EFI_NOT_FOUND;\r
4155 }\r
4156 //\r
4157 // Update the package length.\r
4158 //\r
d91c7bf9 4159 PackageHeader.Length = (UINT32) UpdatePackageLength;\r
7e3bcccb
LG
4160 CopyMem (TempPackage, &PackageHeader, sizeof (EFI_HII_PACKAGE_HEADER));\r
4161\r
4162 return EFI_SUCCESS;\r
4163}\r
4164\r
4165/**\r
4166 This function updates a form that has previously been registered with the HII \r
4167 Database. This function will perform at most one update operation.\r
4168 \r
4169 The form to update is specified by Handle, FormSetGuid, and FormId. Binary \r
4170 comparisons of IFR opcodes are performed from the beginning of the form being \r
4171 updated until an IFR opcode is found that exactly matches the first IFR opcode \r
84213069 4172 specified by StartOpCodeHandle. The following rules are used to determine if\r
7e3bcccb
LG
4173 an insert, replace, or delete operation is performed.\r
4174 \r
4175 1) If no matches are found, then NULL is returned. \r
4176 2) If a match is found, and EndOpCodeHandle is NULL, then all of the IFR opcodes\r
84213069
LG
4177 from StartOpCodeHandle except the first opcode are inserted immediately after \r
4178 the matching IFR opcode in the form to be updated.\r
7e3bcccb 4179 3) If a match is found, and EndOpCodeHandle is not NULL, then a search is made \r
84213069 4180 from the matching IFR opcode until an IFR opcode exactly matches the first \r
7e3bcccb
LG
4181 IFR opcode specified by EndOpCodeHandle. If no match is found for the first\r
4182 IFR opcode specified by EndOpCodeHandle, then NULL is returned. If a match\r
4183 is found, then all of the IFR opcodes between the start match and the end \r
4184 match are deleted from the form being updated and all of the IFR opcodes\r
84213069 4185 from StartOpCodeHandle except the first opcode are inserted immediately after \r
7e3bcccb 4186 the matching start IFR opcode. If StartOpCcodeHandle only contains one\r
84213069 4187 IFR instruction, then the result of this operation will delete all of the IFR\r
7e3bcccb
LG
4188 opcodes between the start end matches.\r
4189\r
4190 If HiiHandle is NULL, then ASSERT().\r
4191 If StartOpCodeHandle is NULL, then ASSERT().\r
4192\r
4193 @param[in] HiiHandle The HII Handle of the form to update.\r
4194 @param[in] FormSetGuid The Formset GUID of the form to update. This\r
4195 is an optional parameter that may be NULL.\r
4196 If it is NULL, all FormSet will be updated.\r
4197 @param[in] FormId The ID of the form to update.\r
4198 @param[in] StartOpCodeHandle An OpCode Handle that contains the set of IFR \r
4199 opcodes to be inserted or replaced in the form.\r
4200 The first IFR instruction in StartOpCodeHandle \r
4201 is used to find matching IFR opcode in the \r
4202 form. \r
4203 @param[in] EndOpCodeHandle An OpCcode Handle that contains the IFR opcode\r
4204 that marks the end of a replace operation in\r
4205 the form. This is an optional parameter that\r
4206 may be NULL. If it is NULL, then an the IFR\r
4207 opcodes specified by StartOpCodeHandle are \r
4208 inserted into the form.\r
4209 \r
4210 @retval EFI_OUT_OF_RESOURCES No enough memory resource is allocated.\r
4211 @retval EFI_NOT_FOUND The following cases will return EFI_NOT_FOUND.\r
4212 1) The form specified by HiiHandle, FormSetGuid, \r
4213 and FormId could not be found in the HII Database.\r
4214 2) No IFR opcodes in the target form match the first\r
4215 IFR opcode in StartOpCodeHandle.\r
4216 3) EndOpCOde is not NULL, and no IFR opcodes in the \r
4217 target form following a matching start opcode match \r
4218 the first IFR opcode in EndOpCodeHandle.\r
4219 @retval EFI_SUCCESS The matched form is updated by StartOpcode.\r
4220\r
4221**/\r
4222EFI_STATUS\r
4223EFIAPI\r
4224HiiUpdateForm (\r
4225 IN EFI_HII_HANDLE HiiHandle, \r
4226 IN EFI_GUID *FormSetGuid, OPTIONAL\r
4227 IN EFI_FORM_ID FormId,\r
84213069
LG
4228 IN VOID *StartOpCodeHandle,\r
4229 IN VOID *EndOpCodeHandle OPTIONAL\r
7e3bcccb
LG
4230 )\r
4231{\r
4232 EFI_STATUS Status;\r
4233 EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;\r
4234 UINT32 PackageListLength; \r
4235 UINT32 Offset;\r
4236 EFI_HII_PACKAGE_LIST_HEADER *UpdatePackageList;\r
4237 UINTN BufferSize;\r
4238 UINT8 *UpdateBufferPos;\r
4239 EFI_HII_PACKAGE_HEADER *Package;\r
3b28e744 4240 EFI_HII_PACKAGE_HEADER *TempPackage;\r
7e3bcccb
LG
4241 EFI_HII_PACKAGE_HEADER PackageHeader;\r
4242 BOOLEAN Updated;\r
4243 HII_LIB_OPCODE_BUFFER *OpCodeBufferStart;\r
4244 HII_LIB_OPCODE_BUFFER *OpCodeBufferEnd;\r
4245 \r
4246 //\r
4247 // Input update data can't be NULL.\r
4248 //\r
4249 ASSERT (HiiHandle != NULL);\r
84213069 4250 ASSERT (StartOpCodeHandle != NULL);\r
7e3bcccb 4251 UpdatePackageList = NULL;\r
3b28e744 4252 TempPackage = NULL;\r
7e3bcccb
LG
4253 HiiPackageList = NULL;\r
4254 \r
4255 //\r
84213069 4256 // Retrieve buffer data from Opcode Handle\r
7e3bcccb 4257 //\r
84213069
LG
4258 OpCodeBufferStart = (HII_LIB_OPCODE_BUFFER *) StartOpCodeHandle;\r
4259 OpCodeBufferEnd = (HII_LIB_OPCODE_BUFFER *) EndOpCodeHandle;\r
7e3bcccb
LG
4260 \r
4261 //\r
84213069 4262 // Get the original package list\r
7e3bcccb
LG
4263 //\r
4264 BufferSize = 0;\r
4265 HiiPackageList = NULL;\r
4266 Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, HiiHandle, &BufferSize, HiiPackageList);\r
4267 //\r
4268 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.\r
4269 //\r
4270 if (Status != EFI_BUFFER_TOO_SMALL) {\r
4271 return Status;\r
4272 }\r
4273\r
4274 HiiPackageList = AllocatePool (BufferSize);\r
4275 if (HiiPackageList == NULL) {\r
4276 Status = EFI_OUT_OF_RESOURCES;\r
4277 goto Finish;\r
4278 }\r
4279\r
4280 Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, HiiHandle, &BufferSize, HiiPackageList);\r
4281 if (EFI_ERROR (Status)) {\r
4282 goto Finish;\r
4283 }\r
4284\r
4285 //\r
4286 // Calculate and allocate space for retrieval of IFR data\r
4287 //\r
4288 BufferSize += OpCodeBufferStart->Position;\r
4289 UpdatePackageList = AllocateZeroPool (BufferSize);\r
4290 if (UpdatePackageList == NULL) {\r
4291 Status = EFI_OUT_OF_RESOURCES;\r
4292 goto Finish;\r
4293 }\r
4294 \r
4295 //\r
4296 // Allocate temp buffer to store the temp updated package buffer\r
4297 //\r
3b28e744
GL
4298 TempPackage = AllocateZeroPool (BufferSize);\r
4299 if (TempPackage == NULL) {\r
7e3bcccb
LG
4300 Status = EFI_OUT_OF_RESOURCES;\r
4301 goto Finish;\r
4302 }\r
4303\r
4304 UpdateBufferPos = (UINT8 *) UpdatePackageList;\r
4305\r
4306 //\r
4307 // Copy the package list header\r
4308 //\r
4309 CopyMem (UpdateBufferPos, HiiPackageList, sizeof (EFI_HII_PACKAGE_LIST_HEADER));\r
4310 UpdateBufferPos += sizeof (EFI_HII_PACKAGE_LIST_HEADER);\r
4311 \r
4312 //\r
84213069 4313 // Go through each package to find the matched package and update one by one\r
7e3bcccb
LG
4314 //\r
4315 Updated = FALSE;\r
4316 Offset = sizeof (EFI_HII_PACKAGE_LIST_HEADER);\r
4317 PackageListLength = ReadUnaligned32 (&HiiPackageList->PackageLength);\r
4318 while (Offset < PackageListLength) {\r
4319 Package = (EFI_HII_PACKAGE_HEADER *) (((UINT8 *) HiiPackageList) + Offset);\r
4320 CopyMem (&PackageHeader, Package, sizeof (EFI_HII_PACKAGE_HEADER));\r
4321 Offset += Package->Length;\r
4322\r
4323 if (Package->Type == EFI_HII_PACKAGE_FORMS) {\r
4324 //\r
4325 // Check this package is the matched package.\r
4326 //\r
3b28e744 4327 Status = InternalHiiUpdateFormPackageData (FormSetGuid, FormId, Package, OpCodeBufferStart, OpCodeBufferEnd, TempPackage);\r
7e3bcccb 4328 //\r
84213069 4329 // The matched package is found. Its package buffer will be updated by the input new data.\r
7e3bcccb
LG
4330 //\r
4331 if (!EFI_ERROR(Status)) {\r
4332 //\r
4333 // Set Update Flag\r
4334 // \r
4335 Updated = TRUE;\r
4336 //\r
4337 // Add updated package buffer\r
4338 //\r
3b28e744 4339 Package = TempPackage;\r
7e3bcccb
LG
4340 }\r
4341 }\r
4342\r
4343 //\r
4344 // Add pacakge buffer\r
4345 //\r
4346 CopyMem (&PackageHeader, Package, sizeof (EFI_HII_PACKAGE_HEADER));\r
4347 CopyMem (UpdateBufferPos, Package, PackageHeader.Length);\r
4348 UpdateBufferPos += PackageHeader.Length;\r
4349 }\r
4350 \r
4351 if (Updated) {\r
4352 //\r
4353 // Update package list length\r
4354 //\r
4355 BufferSize = UpdateBufferPos - (UINT8 *) UpdatePackageList;\r
4356 WriteUnaligned32 (&UpdatePackageList->PackageLength, (UINT32) BufferSize);\r
4357 \r
4358 //\r
84213069 4359 // Update Package to show form\r
7e3bcccb
LG
4360 //\r
4361 Status = gHiiDatabase->UpdatePackageList (gHiiDatabase, HiiHandle, UpdatePackageList);\r
4362 } else {\r
4363 //\r
4364 // Not matched form is found and updated.\r
4365 //\r
4366 Status = EFI_NOT_FOUND;\r
4367 }\r
4368\r
4369Finish:\r
4370 if (HiiPackageList != NULL) {\r
4371 FreePool (HiiPackageList);\r
4372 }\r
4373 \r
4374 if (UpdatePackageList != NULL) {\r
4375 FreePool (UpdatePackageList);\r
4376 }\r
4377 \r
3b28e744
GL
4378 if (TempPackage != NULL) {\r
4379 FreePool (TempPackage);\r
7e3bcccb
LG
4380 }\r
4381\r
4382 return Status; \r
4383}\r