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