]>
Commit | Line | Data |
---|---|---|
08e4b3cf | 1 | /** @file\r |
2 | HII Library implementation that uses DXE protocols and services.\r | |
3 | \r | |
4 | Copyright (c) 2006 - 2008, Intel Corporation<BR>\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
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 | |
7e3bcccb LG |
17 | //\r |
18 | // <ConfigHdr> Template\r | |
19 | //\r | |
20 | GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR16 mConfigHdrTemplate[] = L"GUID=00000000000000000000000000000000&NAME=0000&PATH=00";\r | |
08e4b3cf | 21 | \r |
7e3bcccb LG |
22 | //\r |
23 | // Form Browser2 Protocol\r | |
24 | //\r | |
3c7449e4 | 25 | EFI_FORM_BROWSER2_PROTOCOL *mUefiFormBrowser2 = NULL;\r |
08e4b3cf | 26 | \r |
27 | /**\r | |
28 | This funciton build the package list based on the package number,\r | |
29 | the GUID of the package list and the list of pointer which point to\r | |
30 | package header that defined by UEFI VFR compiler and StringGather\r | |
31 | tool.\r | |
32 | \r | |
33 | #pragma pack (push, 1)\r | |
34 | typedef struct {\r | |
35 | UINT32 BinaryLength;\r | |
36 | EFI_HII_PACKAGE_HEADER PackageHeader;\r | |
37 | } EDKII_AUTOGEN_PACKAGES_HEADER;\r | |
38 | #pragma pack (pop)\r | |
39 | \r | |
40 | If there is not enough resource for the new package list,\r | |
41 | the function will ASSERT.\r | |
42 | \r | |
43 | @param NumberOfPackages The number of packages be \r | |
44 | @param GuidId The GUID for the package list to be generated.\r | |
45 | @param Marker The variable argument list. Each entry represent a specific package header that is\r | |
46 | generated by VFR compiler and StrGather tool. The first 4 bytes is a UINT32 value\r | |
47 | that indicate the overall length of the package.\r | |
48 | \r | |
49 | @return The pointer to the package list header.\r | |
50 | \r | |
51 | **/\r | |
52 | EFI_HII_PACKAGE_LIST_HEADER *\r | |
53 | InternalHiiLibPreparePackages (\r | |
54 | IN UINTN NumberOfPackages,\r | |
55 | IN CONST EFI_GUID *GuidId,\r | |
56 | IN VA_LIST Marker\r | |
57 | )\r | |
58 | {\r | |
59 | EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader;\r | |
60 | UINT8 *PackageListData;\r | |
61 | UINT32 PackageListLength;\r | |
62 | UINT32 PackageLength;\r | |
63 | EFI_HII_PACKAGE_HEADER PackageHeader;\r | |
64 | UINT8 *PackageArray;\r | |
65 | UINTN Index;\r | |
66 | VA_LIST MarkerBackup;\r | |
67 | \r | |
68 | PackageListLength = sizeof (EFI_HII_PACKAGE_LIST_HEADER);\r | |
69 | \r | |
70 | MarkerBackup = Marker;\r | |
71 | \r | |
72 | //\r | |
dfe687ca | 73 | // Count the length of the final package list.\r |
08e4b3cf | 74 | //\r |
75 | for (Index = 0; Index < NumberOfPackages; Index++) {\r | |
76 | CopyMem (&PackageLength, VA_ARG (Marker, VOID *), sizeof (UINT32));\r | |
77 | //\r | |
78 | // Do not count the BinaryLength field.\r | |
79 | //\r | |
80 | PackageListLength += (PackageLength - sizeof (UINT32));\r | |
81 | }\r | |
82 | \r | |
83 | //\r | |
dfe687ca | 84 | // Include the length of EFI_HII_PACKAGE_END\r |
08e4b3cf | 85 | //\r |
86 | PackageListLength += sizeof (EFI_HII_PACKAGE_HEADER);\r | |
87 | PackageListHeader = AllocateZeroPool (PackageListLength);\r | |
88 | ASSERT (PackageListHeader != NULL);\r | |
89 | \r | |
90 | CopyGuid (&PackageListHeader->PackageListGuid, GuidId);\r | |
91 | PackageListHeader->PackageLength = PackageListLength;\r | |
92 | \r | |
93 | PackageListData = ((UINT8 *) PackageListHeader) + sizeof (EFI_HII_PACKAGE_LIST_HEADER);\r | |
94 | \r | |
95 | Marker = MarkerBackup;\r | |
96 | //\r | |
97 | // Prepare the final package list.\r | |
98 | //\r | |
99 | for (Index = 0; Index < NumberOfPackages; Index++) {\r | |
100 | PackageArray = (UINT8 *) VA_ARG (Marker, VOID *);\r | |
101 | //\r | |
102 | // CopyMem is used for UINT32 to cover the unaligned address access.\r | |
103 | //\r | |
104 | CopyMem (&PackageLength, PackageArray, sizeof (UINT32));\r | |
105 | PackageLength -= sizeof (UINT32);\r | |
106 | PackageArray += sizeof (UINT32);\r | |
107 | CopyMem (PackageListData, PackageArray, PackageLength);\r | |
108 | PackageListData += PackageLength;\r | |
109 | }\r | |
110 | \r | |
111 | //\r | |
112 | // Append EFI_HII_PACKAGE_END\r | |
113 | //\r | |
114 | PackageHeader.Type = EFI_HII_PACKAGE_END;\r | |
115 | PackageHeader.Length = sizeof (EFI_HII_PACKAGE_HEADER);\r | |
116 | CopyMem (PackageListData, &PackageHeader, PackageHeader.Length);\r | |
117 | \r | |
118 | return PackageListHeader;\r | |
119 | }\r | |
120 | \r | |
121 | /**\r | |
122 | Assemble EFI_HII_PACKAGE_LIST according to the passed in packages.\r | |
123 | \r | |
124 | If GuidId is NULL, then ASSERT.\r | |
125 | If not enough resource to complete the operation, then ASSERT.\r | |
126 | \r | |
127 | @param NumberOfPackages Number of packages.\r | |
128 | @param GuidId Package GUID.\r | |
129 | @param ... Variable argument list for packages to be assembled.\r | |
130 | \r | |
131 | @return Pointer of EFI_HII_PACKAGE_LIST_HEADER.\r | |
132 | \r | |
133 | **/\r | |
134 | EFI_HII_PACKAGE_LIST_HEADER *\r | |
135 | EFIAPI\r | |
136 | HiiLibPreparePackageList (\r | |
137 | IN UINTN NumberOfPackages,\r | |
138 | IN CONST EFI_GUID *GuidId,\r | |
139 | ...\r | |
140 | )\r | |
141 | {\r | |
142 | EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader;\r | |
143 | VA_LIST Marker;\r | |
144 | \r | |
145 | ASSERT (GuidId != NULL);\r | |
146 | \r | |
147 | VA_START (Marker, GuidId);\r | |
148 | PackageListHeader = InternalHiiLibPreparePackages (NumberOfPackages, GuidId, Marker);\r | |
149 | VA_END (Marker);\r | |
150 | \r | |
151 | return PackageListHeader;\r | |
152 | }\r | |
153 | \r | |
154 | \r | |
155 | /**\r | |
156 | This function allocates pool for an EFI_HII_PACKAGE_LIST structure\r | |
157 | with additional space that is big enough to host all packages described by the variable \r | |
158 | argument list of package pointers. The allocated structure is initialized using NumberOfPackages, \r | |
159 | GuidId, and the variable length argument list of package pointers.\r | |
160 | \r | |
161 | Then, EFI_HII_PACKAGE_LIST will be register to the default System HII Database. The\r | |
dfe687ca | 162 | Handle to the newly registered Package List is returned through HiiHandle.\r |
08e4b3cf | 163 | \r |
164 | If HiiHandle is NULL, then ASSERT.\r | |
165 | \r | |
166 | @param NumberOfPackages The number of HII packages to register.\r | |
167 | @param GuidId Package List GUID ID.\r | |
168 | @param DriverHandle Optional. If not NULL, the DriverHandle on which an instance of DEVICE_PATH_PROTOCOL is installed.\r | |
169 | This DriverHandle uniquely defines the device that the added packages are associated with.\r | |
170 | @param HiiHandle On output, the HiiHandle is update with the handle which can be used to retrieve the Package \r | |
171 | List later. If the functions failed to add the package to the default HII database, this value will\r | |
172 | be set to NULL.\r | |
173 | @param ... The variable argument list describing all HII Package.\r | |
174 | \r | |
175 | @return EFI_SUCCESS If the packages are successfully added to the default HII database.\r | |
176 | @return EFI_OUT_OF_RESOURCE Not enough resource to complete the operation.\r | |
177 | \r | |
178 | **/\r | |
179 | EFI_STATUS\r | |
180 | EFIAPI\r | |
181 | HiiLibAddPackages (\r | |
182 | IN UINTN NumberOfPackages,\r | |
183 | IN CONST EFI_GUID *GuidId,\r | |
184 | IN EFI_HANDLE DriverHandle, OPTIONAL\r | |
185 | OUT EFI_HII_HANDLE *HiiHandle,\r | |
186 | ...\r | |
187 | )\r | |
188 | {\r | |
189 | VA_LIST Args;\r | |
190 | EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader;\r | |
191 | EFI_STATUS Status;\r | |
192 | \r | |
193 | ASSERT (HiiHandle != NULL);\r | |
194 | \r | |
195 | VA_START (Args, HiiHandle);\r | |
196 | PackageListHeader = InternalHiiLibPreparePackages (NumberOfPackages, GuidId, Args);\r | |
197 | \r | |
7e3bcccb | 198 | Status = gHiiDatabase->NewPackageList (gHiiDatabase, PackageListHeader, DriverHandle, HiiHandle);\r |
08e4b3cf | 199 | if (HiiHandle != NULL) {\r |
200 | if (EFI_ERROR (Status)) {\r | |
201 | *HiiHandle = NULL;\r | |
202 | }\r | |
203 | }\r | |
204 | \r | |
205 | FreePool (PackageListHeader);\r | |
206 | VA_END (Args);\r | |
207 | \r | |
208 | return Status;\r | |
209 | }\r | |
210 | \r | |
211 | /**\r | |
212 | Removes a package list from the default HII database.\r | |
213 | \r | |
214 | If HiiHandle is NULL, then ASSERT.\r | |
215 | If HiiHandle is not a valid EFI_HII_HANDLE in the default HII database, then ASSERT.\r | |
216 | \r | |
217 | @param HiiHandle The handle that was previously registered to the data base that is requested for removal.\r | |
218 | List later.\r | |
219 | \r | |
220 | **/\r | |
221 | VOID\r | |
222 | EFIAPI\r | |
223 | HiiLibRemovePackages (\r | |
224 | IN EFI_HII_HANDLE HiiHandle\r | |
225 | )\r | |
226 | {\r | |
227 | EFI_STATUS Status;\r | |
228 | ASSERT (IsHiiHandleRegistered (HiiHandle));\r | |
229 | \r | |
7e3bcccb | 230 | Status = gHiiDatabase->RemovePackageList (gHiiDatabase, HiiHandle);\r |
08e4b3cf | 231 | ASSERT_EFI_ERROR (Status);\r |
232 | }\r | |
233 | \r | |
234 | \r | |
235 | /**\r | |
236 | Determines the handles that are currently active in the database.\r | |
237 | It's the caller's responsibility to free handle buffer.\r | |
238 | \r | |
239 | If HandleBufferLength is NULL, then ASSERT.\r | |
240 | If HiiHandleBuffer is NULL, then ASSERT.\r | |
241 | \r | |
242 | @param HandleBufferLength On input, a pointer to the length of the handle\r | |
243 | buffer. On output, the length of the handle buffer\r | |
244 | that is required for the handles found.\r | |
245 | @param HiiHandleBuffer Pointer to an array of Hii Handles returned.\r | |
246 | \r | |
247 | @retval EFI_SUCCESS Get an array of Hii Handles successfully.\r | |
248 | \r | |
249 | **/\r | |
250 | EFI_STATUS\r | |
251 | EFIAPI\r | |
252 | HiiLibGetHiiHandles (\r | |
253 | IN OUT UINTN *HandleBufferLength,\r | |
254 | OUT EFI_HII_HANDLE **HiiHandleBuffer\r | |
255 | )\r | |
256 | {\r | |
08e4b3cf | 257 | EFI_STATUS Status;\r |
258 | \r | |
259 | ASSERT (HandleBufferLength != NULL);\r | |
260 | ASSERT (HiiHandleBuffer != NULL);\r | |
261 | \r | |
fa7b3168 | 262 | *HandleBufferLength = 0;\r |
263 | *HiiHandleBuffer = NULL;\r | |
08e4b3cf | 264 | \r |
265 | //\r | |
266 | // Try to find the actual buffer size for HiiHandle Buffer.\r | |
267 | //\r | |
7e3bcccb LG |
268 | Status = gHiiDatabase->ListPackageLists (\r |
269 | gHiiDatabase,\r | |
08e4b3cf | 270 | EFI_HII_PACKAGE_TYPE_ALL,\r |
271 | NULL,\r | |
fa7b3168 | 272 | HandleBufferLength,\r |
08e4b3cf | 273 | *HiiHandleBuffer\r |
274 | );\r | |
fa7b3168 | 275 | \r |
08e4b3cf | 276 | if (Status == EFI_BUFFER_TOO_SMALL) {\r |
fa7b3168 | 277 | *HiiHandleBuffer = AllocateZeroPool (*HandleBufferLength);\r |
08e4b3cf | 278 | ASSERT (*HiiHandleBuffer != NULL);\r |
7e3bcccb LG |
279 | Status = gHiiDatabase->ListPackageLists (\r |
280 | gHiiDatabase,\r | |
08e4b3cf | 281 | EFI_HII_PACKAGE_TYPE_ALL,\r |
282 | NULL,\r | |
fa7b3168 | 283 | HandleBufferLength,\r |
08e4b3cf | 284 | *HiiHandleBuffer\r |
285 | );\r | |
08e4b3cf | 286 | \r |
fa7b3168 | 287 | if (EFI_ERROR (Status)) {\r |
288 | FreePool (*HiiHandleBuffer);\r | |
289 | *HiiHandleBuffer = NULL;\r | |
290 | }\r | |
291 | }\r | |
08e4b3cf | 292 | \r |
293 | return Status;\r | |
294 | }\r | |
295 | \r | |
296 | /**\r | |
297 | Extract Hii package list GUID for given HII handle.\r | |
298 | \r | |
299 | If HiiHandle could not be found in the default HII database, then ASSERT.\r | |
300 | If Guid is NULL, then ASSERT.\r | |
301 | \r | |
302 | @param Handle Hii handle\r | |
303 | @param Guid Package list GUID\r | |
304 | \r | |
305 | @retval EFI_SUCCESS Successfully extract GUID from Hii database.\r | |
306 | \r | |
307 | **/\r | |
308 | EFI_STATUS\r | |
309 | EFIAPI\r | |
310 | HiiLibExtractGuidFromHiiHandle (\r | |
311 | IN EFI_HII_HANDLE Handle,\r | |
312 | OUT EFI_GUID *Guid\r | |
313 | )\r | |
314 | {\r | |
315 | EFI_STATUS Status;\r | |
316 | UINTN BufferSize;\r | |
317 | EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;\r | |
318 | \r | |
319 | ASSERT (Guid != NULL);\r | |
320 | ASSERT (IsHiiHandleRegistered (Handle));\r | |
321 | \r | |
322 | //\r | |
323 | // Get HII PackageList\r | |
324 | //\r | |
325 | BufferSize = 0;\r | |
326 | HiiPackageList = NULL;\r | |
327 | \r | |
7e3bcccb | 328 | Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &BufferSize, HiiPackageList);\r |
08e4b3cf | 329 | ASSERT (Status != EFI_NOT_FOUND);\r |
330 | \r | |
331 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
332 | HiiPackageList = AllocatePool (BufferSize);\r | |
333 | ASSERT (HiiPackageList != NULL);\r | |
334 | \r | |
7e3bcccb | 335 | Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &BufferSize, HiiPackageList);\r |
08e4b3cf | 336 | }\r |
337 | if (EFI_ERROR (Status)) {\r | |
338 | FreePool (HiiPackageList);\r | |
339 | return Status;\r | |
340 | }\r | |
341 | \r | |
342 | //\r | |
343 | // Extract GUID\r | |
344 | //\r | |
345 | CopyGuid (Guid, &HiiPackageList->PackageListGuid);\r | |
346 | \r | |
347 | FreePool (HiiPackageList);\r | |
348 | \r | |
349 | return EFI_SUCCESS;\r | |
350 | }\r | |
351 | \r | |
352 | /**\r | |
353 | Find HII Handle in the default HII database associated with given Device Path.\r | |
354 | \r | |
355 | If DevicePath is NULL, then ASSERT.\r | |
356 | \r | |
357 | @param DevicePath Device Path associated with the HII package list\r | |
358 | handle.\r | |
359 | \r | |
360 | @retval Handle HII package list Handle associated with the Device\r | |
361 | Path.\r | |
362 | @retval NULL Hii Package list handle is not found.\r | |
363 | \r | |
364 | **/\r | |
365 | EFI_HII_HANDLE\r | |
366 | EFIAPI\r | |
367 | HiiLibDevicePathToHiiHandle (\r | |
368 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
369 | )\r | |
370 | {\r | |
371 | EFI_STATUS Status;\r | |
372 | EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath;\r | |
373 | UINTN BufferSize;\r | |
374 | UINTN HandleCount;\r | |
375 | UINTN Index;\r | |
376 | EFI_HANDLE *Handles;\r | |
377 | EFI_HANDLE Handle;\r | |
378 | UINTN Size;\r | |
379 | EFI_HANDLE DriverHandle;\r | |
380 | EFI_HII_HANDLE *HiiHandles;\r | |
381 | EFI_HII_HANDLE HiiHandle;\r | |
382 | \r | |
383 | ASSERT (DevicePath != NULL);\r | |
384 | \r | |
385 | //\r | |
386 | // Locate Device Path Protocol handle buffer\r | |
387 | //\r | |
388 | Status = gBS->LocateHandleBuffer (\r | |
389 | ByProtocol,\r | |
390 | &gEfiDevicePathProtocolGuid,\r | |
391 | NULL,\r | |
392 | &HandleCount,\r | |
393 | &Handles\r | |
394 | );\r | |
395 | if (EFI_ERROR (Status)) {\r | |
396 | return NULL;\r | |
397 | }\r | |
398 | \r | |
399 | //\r | |
400 | // Search Driver Handle by Device Path\r | |
401 | //\r | |
402 | DriverHandle = NULL;\r | |
403 | BufferSize = GetDevicePathSize (DevicePath);\r | |
404 | for(Index = 0; Index < HandleCount; Index++) {\r | |
405 | Handle = Handles[Index];\r | |
406 | gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **) &TmpDevicePath);\r | |
407 | \r | |
408 | //\r | |
409 | // Check whether DevicePath match\r | |
410 | //\r | |
411 | Size = GetDevicePathSize (TmpDevicePath);\r | |
412 | if ((Size == BufferSize) && CompareMem (DevicePath, TmpDevicePath, Size) == 0) {\r | |
413 | DriverHandle = Handle;\r | |
414 | break;\r | |
415 | }\r | |
416 | }\r | |
417 | FreePool (Handles);\r | |
418 | \r | |
419 | if (DriverHandle == NULL) {\r | |
420 | return NULL;\r | |
421 | }\r | |
422 | \r | |
423 | //\r | |
424 | // Retrieve all Hii Handles from HII database\r | |
425 | //\r | |
426 | BufferSize = 0x1000;\r | |
427 | HiiHandles = AllocatePool (BufferSize);\r | |
428 | ASSERT (HiiHandles != NULL);\r | |
7e3bcccb LG |
429 | Status = gHiiDatabase->ListPackageLists (\r |
430 | gHiiDatabase,\r | |
08e4b3cf | 431 | EFI_HII_PACKAGE_TYPE_ALL,\r |
432 | NULL,\r | |
433 | &BufferSize,\r | |
434 | HiiHandles\r | |
435 | );\r | |
436 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
437 | FreePool (HiiHandles);\r | |
438 | HiiHandles = AllocatePool (BufferSize);\r | |
439 | ASSERT (HiiHandles != NULL);\r | |
440 | \r | |
7e3bcccb LG |
441 | Status = gHiiDatabase->ListPackageLists (\r |
442 | gHiiDatabase,\r | |
08e4b3cf | 443 | EFI_HII_PACKAGE_TYPE_ALL,\r |
444 | NULL,\r | |
445 | &BufferSize,\r | |
446 | HiiHandles\r | |
447 | );\r | |
448 | }\r | |
449 | \r | |
450 | if (EFI_ERROR (Status)) {\r | |
451 | FreePool (HiiHandles);\r | |
452 | return NULL;\r | |
453 | }\r | |
454 | \r | |
455 | //\r | |
456 | // Search Hii Handle by Driver Handle\r | |
457 | //\r | |
458 | HiiHandle = NULL;\r | |
459 | HandleCount = BufferSize / sizeof (EFI_HII_HANDLE);\r | |
460 | for (Index = 0; Index < HandleCount; Index++) {\r | |
7e3bcccb LG |
461 | Status = gHiiDatabase->GetPackageListHandle (\r |
462 | gHiiDatabase,\r | |
08e4b3cf | 463 | HiiHandles[Index],\r |
464 | &Handle\r | |
465 | );\r | |
466 | if (!EFI_ERROR (Status) && (Handle == DriverHandle)) {\r | |
467 | HiiHandle = HiiHandles[Index];\r | |
468 | break;\r | |
469 | }\r | |
470 | }\r | |
471 | \r | |
472 | FreePool (HiiHandles);\r | |
473 | return HiiHandle;\r | |
474 | }\r | |
475 | \r | |
476 | /**\r | |
477 | Exports the contents of one or all package lists in the HII database into a buffer.\r | |
478 | \r | |
479 | If Handle is not NULL and not a valid EFI_HII_HANDLE registered in the database, \r | |
480 | then ASSERT.\r | |
481 | If PackageListHeader is NULL, then ASSERT.\r | |
482 | If PackageListSize is NULL, then ASSERT.\r | |
483 | \r | |
484 | @param Handle The HII Handle.\r | |
485 | @param PackageListHeader A pointer to a buffer that will contain the results of \r | |
486 | the export function.\r | |
487 | @param PackageListSize On output, the length of the buffer that is required for the exported data.\r | |
488 | \r | |
489 | @retval EFI_SUCCESS Package exported.\r | |
490 | \r | |
491 | @retval EFI_OUT_OF_RESOURCES Not enought memory to complete the operations.\r | |
492 | \r | |
493 | **/\r | |
494 | EFI_STATUS \r | |
495 | EFIAPI\r | |
496 | HiiLibExportPackageLists (\r | |
497 | IN EFI_HII_HANDLE Handle,\r | |
498 | OUT EFI_HII_PACKAGE_LIST_HEADER **PackageListHeader,\r | |
499 | OUT UINTN *PackageListSize\r | |
500 | )\r | |
501 | {\r | |
502 | EFI_STATUS Status;\r | |
503 | UINTN Size;\r | |
504 | EFI_HII_PACKAGE_LIST_HEADER *PackageListHdr;\r | |
505 | \r | |
506 | ASSERT (PackageListSize != NULL);\r | |
507 | ASSERT (PackageListHeader != NULL);\r | |
508 | \r | |
509 | if (Handle != NULL) {\r | |
510 | ASSERT (IsHiiHandleRegistered (Handle));\r | |
511 | }\r | |
512 | \r | |
513 | Size = 0;\r | |
514 | PackageListHdr = NULL;\r | |
7e3bcccb LG |
515 | Status = gHiiDatabase->ExportPackageLists (\r |
516 | gHiiDatabase,\r | |
08e4b3cf | 517 | Handle,\r |
518 | &Size,\r | |
519 | PackageListHdr\r | |
520 | );\r | |
521 | ASSERT_EFI_ERROR (Status != EFI_BUFFER_TOO_SMALL);\r | |
522 | \r | |
523 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
524 | PackageListHdr = AllocateZeroPool (Size);\r | |
525 | \r | |
526 | if (PackageListHeader == NULL) {\r | |
527 | return EFI_OUT_OF_RESOURCES;\r | |
528 | } else {\r | |
7e3bcccb LG |
529 | Status = gHiiDatabase->ExportPackageLists (\r |
530 | gHiiDatabase,\r | |
08e4b3cf | 531 | Handle,\r |
532 | &Size,\r | |
533 | PackageListHdr\r | |
534 | );\r | |
535 | }\r | |
536 | }\r | |
537 | \r | |
538 | if (!EFI_ERROR (Status)) {\r | |
539 | *PackageListHeader = PackageListHdr;\r | |
540 | *PackageListSize = Size;\r | |
541 | } else {\r | |
542 | FreePool (PackageListHdr);\r | |
543 | }\r | |
544 | \r | |
545 | return Status;\r | |
546 | }\r | |
547 | \r | |
548 | /**\r | |
549 | \r | |
550 | This function returns a list of the package handles of the \r | |
551 | specified type that are currently active in the HII database. The \r | |
552 | pseudo-type EFI_HII_PACKAGE_TYPE_ALL will cause all package \r | |
553 | handles to be listed.\r | |
554 | \r | |
555 | If HandleBufferLength is NULL, then ASSERT.\r | |
556 | If HandleBuffer is NULL, the ASSERT.\r | |
557 | If PackageType is EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is\r | |
558 | NULL, then ASSERT.\r | |
559 | If PackageType is not EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is not\r | |
560 | NULL, then ASSERT.\r | |
561 | \r | |
562 | \r | |
563 | @param PackageType Specifies the package type of the packages\r | |
564 | to list or EFI_HII_PACKAGE_TYPE_ALL for\r | |
565 | all packages to be listed.\r | |
566 | \r | |
567 | @param PackageGuid If PackageType is\r | |
568 | EFI_HII_PACKAGE_TYPE_GUID, then this is\r | |
569 | the pointer to the GUID which must match\r | |
570 | the Guid field of\r | |
571 | EFI_HII_PACKAGE_GUID_HEADER. Otherwise, it\r | |
572 | must be NULL.\r | |
573 | \r | |
574 | @param HandleBufferLength On output, the length of the handle buffer\r | |
575 | that is required for the handles found.\r | |
576 | \r | |
577 | @param HandleBuffer On output, an array of EFI_HII_HANDLE instances returned.\r | |
578 | The caller is responcible to free this pointer allocated.\r | |
579 | \r | |
580 | @retval EFI_SUCCESS The matching handles are outputed successfully.\r | |
581 | HandleBufferLength is updated with the actual length.\r | |
582 | @retval EFI_OUT_OF_RESOURCES Not enough resource to complete the operation.\r | |
583 | @retval EFI_NOT_FOUND No matching handle could not be found in database.\r | |
584 | **/\r | |
585 | EFI_STATUS\r | |
586 | EFIAPI\r | |
587 | HiiLibListPackageLists (\r | |
588 | IN UINT8 PackageType,\r | |
589 | IN CONST EFI_GUID *PackageGuid,\r | |
590 | IN OUT UINTN *HandleBufferLength,\r | |
591 | OUT EFI_HII_HANDLE **HandleBuffer\r | |
592 | )\r | |
593 | {\r | |
594 | EFI_STATUS Status;\r | |
595 | \r | |
596 | ASSERT (HandleBufferLength != NULL);\r | |
597 | ASSERT (HandleBuffer != NULL);\r | |
598 | \r | |
599 | *HandleBufferLength = 0;\r | |
600 | *HandleBuffer = NULL;\r | |
601 | \r | |
602 | if (PackageType == EFI_HII_PACKAGE_TYPE_GUID) {\r | |
603 | ASSERT (PackageGuid != NULL);\r | |
604 | } else {\r | |
605 | ASSERT (PackageGuid == NULL);\r | |
606 | }\r | |
607 | \r | |
7e3bcccb LG |
608 | Status = gHiiDatabase->ListPackageLists (\r |
609 | gHiiDatabase,\r | |
08e4b3cf | 610 | PackageType,\r |
611 | PackageGuid,\r | |
612 | HandleBufferLength,\r | |
613 | *HandleBuffer\r | |
614 | );\r | |
615 | if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {\r | |
616 | //\r | |
617 | // No packages is registered to UEFI HII Database, just return.\r | |
618 | // \r | |
619 | //\r | |
620 | return Status;\r | |
621 | }\r | |
622 | \r | |
623 | *HandleBuffer = AllocateZeroPool (*HandleBufferLength);\r | |
624 | \r | |
625 | if (*HandleBuffer == NULL) {\r | |
626 | return EFI_OUT_OF_RESOURCES;\r | |
627 | }\r | |
628 | \r | |
7e3bcccb LG |
629 | return gHiiDatabase->ListPackageLists (\r |
630 | gHiiDatabase,\r | |
08e4b3cf | 631 | PackageType,\r |
632 | PackageGuid,\r | |
633 | HandleBufferLength,\r | |
634 | *HandleBuffer\r | |
635 | );\r | |
636 | \r | |
637 | }\r | |
638 | /**\r | |
639 | This function check if the Hii Handle is a valid handle registered\r | |
640 | in the HII database.\r | |
641 | \r | |
642 | @param HiiHandle The HII Handle.\r | |
643 | \r | |
644 | @retval TRUE If it is a valid HII handle.\r | |
645 | @retval FALSE If it is a invalid HII handle.\r | |
646 | **/\r | |
647 | BOOLEAN\r | |
648 | IsHiiHandleRegistered (\r | |
649 | EFI_HII_HANDLE HiiHandle\r | |
650 | )\r | |
651 | {\r | |
652 | EFI_STATUS Status;\r | |
653 | UINTN BufferSize;\r | |
654 | EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;\r | |
655 | \r | |
656 | ASSERT (HiiHandle != NULL);\r | |
657 | \r | |
658 | HiiPackageList = NULL;\r | |
659 | BufferSize = 0;\r | |
660 | \r | |
7e3bcccb LG |
661 | Status = gHiiDatabase->ExportPackageLists (\r |
662 | gHiiDatabase,\r | |
08e4b3cf | 663 | HiiHandle,\r |
664 | &BufferSize,\r | |
665 | HiiPackageList\r | |
666 | );\r | |
667 | \r | |
668 | return (BOOLEAN) (Status == EFI_BUFFER_TOO_SMALL);\r | |
669 | }\r | |
670 | \r | |
7e3bcccb LG |
671 | \r |
672 | /**\r | |
673 | Converts all hex dtring characters in range ['A'..'F'] to ['a'..'f'] for \r | |
674 | hex digits that appear between a '=' and a '&' in a config string.\r | |
675 | \r | |
676 | If String is NULL, then ASSERT().\r | |
677 | \r | |
678 | @param[in] String Pointer to a Null-terminated Unicode string.\r | |
679 | \r | |
680 | @return Pointer to the Null-terminated Unicode result string.\r | |
681 | \r | |
682 | **/\r | |
683 | EFI_STRING\r | |
684 | EFIAPI\r | |
685 | InternalHiiLowerConfigString (\r | |
686 | IN EFI_STRING ConfigString\r | |
687 | )\r | |
688 | {\r | |
689 | EFI_STRING String;\r | |
690 | BOOLEAN Lower;\r | |
691 | \r | |
692 | ASSERT (ConfigString != NULL);\r | |
693 | \r | |
694 | //\r | |
695 | // Convert all hex digits in range [A-F] in the configuration header to [a-f]\r | |
696 | //\r | |
697 | for (String = ConfigString, Lower = FALSE; *String != L'\0'; String++) {\r | |
698 | if (*String == L'=') {\r | |
699 | Lower = TRUE;\r | |
700 | } else if (*String == L'&') {\r | |
701 | Lower = FALSE;\r | |
3e3f86e0 | 702 | } else if (Lower && *String >= L'A' && *String <= L'F') {\r |
5c1ebff6 | 703 | *String = (CHAR16) (*String - L'A' + L'a');\r |
7e3bcccb LG |
704 | }\r |
705 | }\r | |
706 | \r | |
707 | return ConfigString;\r | |
708 | }\r | |
709 | \r | |
710 | /**\r | |
711 | Uses the BlockToConfig() service of the Config Routing Protocol to \r | |
712 | convert <ConfigRequest> and a buffer to a <ConfigResp>\r | |
713 | \r | |
714 | If ConfigRequest is NULL, then ASSERT().\r | |
715 | If Block is NULL, then ASSERT().\r | |
716 | \r | |
717 | @param[in] ConfigRequest Pointer to a Null-terminated Unicode string.\r | |
718 | @param[in] Block Pointer to a block of data.\r | |
719 | @param[in] BlockSize The zie, in bytes, of Block.\r | |
720 | \r | |
721 | @retval NULL The <ConfigResp> string could not be generated.\r | |
722 | @retval Other Pointer to the Null-terminated Unicode <ConfigResp> string.\r | |
723 | \r | |
724 | **/\r | |
725 | EFI_STRING\r | |
726 | EFIAPI\r | |
727 | InternalHiiBlockToConfig (\r | |
728 | IN CONST EFI_STRING ConfigRequest,\r | |
729 | IN CONST UINT8 *Block,\r | |
730 | IN UINTN BlockSize\r | |
731 | )\r | |
732 | {\r | |
733 | EFI_STATUS Status;\r | |
734 | EFI_STRING ConfigResp;\r | |
735 | CHAR16 *Progress;\r | |
736 | \r | |
737 | ASSERT (ConfigRequest != NULL);\r | |
738 | ASSERT (Block != NULL);\r | |
739 | \r | |
740 | //\r | |
741 | // Convert <ConfigRequest> to <ConfigResp>\r | |
742 | //\r | |
743 | Status = gHiiConfigRouting->BlockToConfig (\r | |
744 | gHiiConfigRouting,\r | |
745 | ConfigRequest,\r | |
746 | Block,\r | |
747 | BlockSize,\r | |
748 | &ConfigResp,\r | |
749 | &Progress\r | |
750 | );\r | |
751 | if (EFI_ERROR (Status)) {\r | |
752 | return NULL;\r | |
753 | }\r | |
754 | return ConfigResp;\r | |
755 | }\r | |
756 | \r | |
757 | /**\r | |
758 | Uses the ConfigToBlock() service of the Config Routing Protocol to \r | |
759 | convert <ConfigResp> to a block. The block is allocated using\r | |
760 | AllocatePool(). The caller is responsible for freeing the block\r | |
761 | using FreePool().\r | |
762 | \r | |
763 | If ConfigResp is NULL, then ASSERT().\r | |
764 | \r | |
765 | @param[in] ConfigResp Pointer to a Null-terminated Unicode string.\r | |
766 | @param[in] BufferSize Length in bytes of buffer to hold retrived data. \r | |
767 | \r | |
768 | @retval NULL The block could not be generated..\r | |
769 | @retval Other Pointer to the allocated block.\r | |
770 | \r | |
771 | **/\r | |
772 | UINT8 *\r | |
773 | EFIAPI\r | |
774 | InternalHiiConfigToBlock (\r | |
775 | IN EFI_STRING ConfigResp,\r | |
776 | IN UINTN BlockSize\r | |
777 | )\r | |
778 | {\r | |
779 | EFI_STATUS Status;\r | |
780 | CHAR16 *Progress;\r | |
781 | UINT8 *Block;\r | |
782 | \r | |
783 | ASSERT (ConfigResp != NULL);\r | |
784 | \r | |
785 | //\r | |
786 | // Allocate a buffer to hold the <ConfigResp> conversion\r | |
787 | //\r | |
788 | Block = AllocateZeroPool (BlockSize);\r | |
789 | if (Block == NULL) {\r | |
790 | return NULL;\r | |
791 | }\r | |
792 | \r | |
793 | //\r | |
794 | // Convert <ConfigResp> to a buffer\r | |
795 | //\r | |
796 | Status = gHiiConfigRouting->ConfigToBlock (\r | |
797 | gHiiConfigRouting,\r | |
798 | ConfigResp,\r | |
799 | Block,\r | |
800 | &BlockSize,\r | |
801 | &Progress\r | |
802 | );\r | |
803 | if (EFI_ERROR (Status)) {\r | |
804 | FreePool (Block);\r | |
805 | return NULL;\r | |
806 | }\r | |
807 | \r | |
808 | //\r | |
809 | // Return converted buffer\r | |
810 | //\r | |
811 | return Block;\r | |
812 | }\r | |
813 | \r | |
814 | /**\r | |
815 | Uses the BrowserCallback() service of the Form Browser Protocol to retrieve \r | |
816 | or set uncommitted data. If sata i being retrieved, then the buffer is \r | |
817 | allocated using AllocatePool(). The caller is then responsible for freeing \r | |
818 | the buffer using FreePool().\r | |
819 | \r | |
820 | @param[in] VariableName Pointer to a Null-terminated Unicode string. This \r | |
821 | is an optional parameter that may be NULL.\r | |
822 | @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional \r | |
823 | parameter that may be NULL.\r | |
824 | @param[in] SetResultsData If not NULL, then this parameter specified the buffer\r | |
825 | of uncommited data to set. If this parameter is NULL,\r | |
826 | then the caller is requesting to get the uncommited data\r | |
827 | from the Form Browser.\r | |
828 | \r | |
829 | @retval NULL The uncommitted data could not be retrieved.\r | |
830 | @retval Other A pointer to a buffer containing the uncommitted data.\r | |
831 | \r | |
832 | **/\r | |
833 | EFI_STRING\r | |
834 | EFIAPI\r | |
835 | InternalHiiBrowserCallback (\r | |
836 | IN CONST EFI_GUID *VariableGuid, OPTIONAL\r | |
837 | IN CONST CHAR16 *VariableName, OPTIONAL\r | |
838 | IN CONST EFI_STRING SetResultsData OPTIONAL\r | |
839 | )\r | |
840 | {\r | |
841 | EFI_STATUS Status;\r | |
842 | UINTN ResultsDataSize;\r | |
843 | EFI_STRING ResultsData;\r | |
844 | CHAR16 TempResultsData;\r | |
845 | \r | |
846 | //\r | |
847 | // Locate protocols\r | |
848 | //\r | |
3c7449e4 LG |
849 | if (mUefiFormBrowser2 == NULL) {\r |
850 | Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &mUefiFormBrowser2);\r | |
851 | if (EFI_ERROR (Status) || mUefiFormBrowser2 == NULL) {\r | |
7e3bcccb LG |
852 | return NULL;\r |
853 | }\r | |
854 | }\r | |
855 | \r | |
856 | ResultsDataSize = 0;\r | |
857 | \r | |
858 | if (SetResultsData != NULL) {\r | |
859 | //\r | |
860 | // Request to to set data in the uncommitted browser state information\r | |
861 | //\r | |
862 | ResultsData = SetResultsData;\r | |
863 | } else {\r | |
864 | //\r | |
865 | // Retrieve the length of the buffer required ResultsData from the Browser Callback\r | |
866 | //\r | |
3c7449e4 LG |
867 | Status = mUefiFormBrowser2->BrowserCallback (\r |
868 | mUefiFormBrowser2,\r | |
7e3bcccb LG |
869 | &ResultsDataSize,\r |
870 | &TempResultsData,\r | |
871 | TRUE,\r | |
872 | VariableGuid,\r | |
873 | VariableName\r | |
874 | );\r | |
875 | if (Status != EFI_BUFFER_TOO_SMALL) {\r | |
876 | return NULL;\r | |
877 | }\r | |
878 | \r | |
879 | //\r | |
880 | // Allocate the ResultsData buffer\r | |
881 | //\r | |
882 | ResultsData = AllocateZeroPool (ResultsDataSize);\r | |
883 | if (ResultsData == NULL) {\r | |
884 | return NULL;\r | |
885 | }\r | |
886 | }\r | |
887 | \r | |
888 | //\r | |
889 | // Retrieve or set the ResultsData from the Browser Callback\r | |
890 | //\r | |
3c7449e4 LG |
891 | Status = mUefiFormBrowser2->BrowserCallback (\r |
892 | mUefiFormBrowser2,\r | |
7e3bcccb LG |
893 | &ResultsDataSize,\r |
894 | ResultsData,\r | |
895 | (BOOLEAN)(SetResultsData == NULL),\r | |
896 | VariableGuid,\r | |
897 | VariableName\r | |
898 | );\r | |
899 | if (EFI_ERROR (Status)) {\r | |
900 | return NULL;\r | |
901 | }\r | |
902 | \r | |
903 | return ResultsData;\r | |
904 | }\r | |
905 | \r | |
906 | /**\r | |
907 | Allocates and returns a Null-terminated Unicode <ConfigHdr> string using routing \r | |
908 | information that includes a GUID, an optional Unicode string name, and a device\r | |
909 | path. The string returned is allocated with AllocatePool(). The caller is \r | |
910 | responsible for freeing the allocated string with FreePool().\r | |
911 | \r | |
912 | The format of a <ConfigHdr> is as follows:\r | |
913 | \r | |
914 | GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize<Null>\r | |
915 | \r | |
916 | @param[in] Guid Pointer to an EFI_GUID that is the routing information\r | |
917 | GUID. Each of the 16 bytes in Guid is converted to \r | |
918 | a 2 Unicode character hexidecimal string. This is \r | |
919 | an optional parameter that may be NULL.\r | |
920 | @param[in] Name Pointer to a Null-terminated Unicode string that is \r | |
921 | the routing information NAME. This is an optional \r | |
922 | parameter that may be NULL. Each 16-bit Unicode \r | |
923 | character in Name is converted to a 4 character Unicode \r | |
924 | hexidecimal string. \r | |
925 | @param[in] DriverHandle The driver handle which supports a Device Path Protocol\r | |
926 | that is the routing information PATH. Each byte of\r | |
927 | the Device Path associated with DriverHandle is converted\r | |
928 | to a 2 Unicode character hexidecimal string.\r | |
929 | \r | |
7e3bcccb LG |
930 | @retval NULL DriverHandle does not support the Device Path Protocol.\r |
931 | @retval Other A pointer to the Null-terminate Unicode <ConfigHdr> string\r | |
932 | \r | |
933 | **/\r | |
934 | EFI_STRING\r | |
935 | EFIAPI\r | |
936 | HiiConstructConfigHdr (\r | |
937 | IN CONST EFI_GUID *Guid, OPTIONAL\r | |
938 | IN CONST CHAR16 *Name, OPTIONAL\r | |
939 | IN EFI_HANDLE DriverHandle\r | |
940 | )\r | |
941 | {\r | |
942 | UINTN NameLength;\r | |
943 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
944 | UINTN DevicePathSize;\r | |
945 | CHAR16 *String;\r | |
946 | CHAR16 *ReturnString;\r | |
947 | UINTN Index;\r | |
948 | UINT8 *Buffer;\r | |
949 | \r | |
950 | //\r | |
951 | // Compute the length of Name in Unicode characters. \r | |
952 | // If Name is NULL, then the length is 0.\r | |
953 | //\r | |
954 | NameLength = 0;\r | |
955 | if (Name != NULL) {\r | |
956 | NameLength = StrLen (Name);\r | |
957 | }\r | |
958 | \r | |
3e3f86e0 LG |
959 | DevicePath = NULL;\r |
960 | DevicePathSize = 0;\r | |
7e3bcccb LG |
961 | //\r |
962 | // Retrieve DevicePath Protocol associated with DriverHandle\r | |
963 | //\r | |
3e3f86e0 LG |
964 | if (DriverHandle != NULL) {\r |
965 | DevicePath = DevicePathFromHandle (DriverHandle);\r | |
966 | if (DevicePath == NULL) {\r | |
967 | return NULL;\r | |
968 | }\r | |
969 | //\r | |
970 | // Compute the size of the device path in bytes\r | |
971 | //\r | |
972 | DevicePathSize = GetDevicePathSize (DevicePath);\r | |
7e3bcccb LG |
973 | }\r |
974 | \r | |
7e3bcccb LG |
975 | //\r |
976 | // GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize <Null>\r | |
977 | // | 5 | sizeof (EFI_GUID) * 2 | 6 | NameStrLen*4 | 6 | DevicePathSize * 2 | 1 |\r | |
978 | //\r | |
979 | String = AllocateZeroPool ((5 + sizeof (EFI_GUID) * 2 + 6 + NameLength * 4 + 6 + DevicePathSize * 2 + 1) * sizeof (CHAR16));\r | |
980 | if (String == NULL) {\r | |
981 | return NULL;\r | |
982 | }\r | |
983 | \r | |
984 | //\r | |
985 | // Start with L"GUID="\r | |
986 | //\r | |
987 | ReturnString = StrCpy (String, L"GUID=");\r | |
988 | String += StrLen (String);\r | |
989 | \r | |
990 | if (Guid != NULL) {\r | |
991 | //\r | |
992 | // Append Guid converted to <HexCh>32\r | |
993 | //\r | |
994 | for (Index = 0, Buffer = (UINT8 *)Guid; Index < sizeof (EFI_GUID); Index++) {\r | |
995 | String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, *(Buffer++), 2);\r | |
996 | }\r | |
997 | }\r | |
998 | \r | |
999 | //\r | |
1000 | // Append L"&NAME="\r | |
1001 | //\r | |
1002 | StrCpy (String, L"&NAME=");\r | |
1003 | String += StrLen (String);\r | |
1004 | \r | |
1005 | if (Name != NULL) {\r | |
1006 | //\r | |
1007 | // Append Name converted to <Char>NameLength\r | |
1008 | //\r | |
1009 | for (; *Name != L'\0'; Name++) {\r | |
1010 | String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, *Name, 4);\r | |
1011 | }\r | |
1012 | }\r | |
1013 | \r | |
1014 | //\r | |
1015 | // Append L"&PATH="\r | |
1016 | //\r | |
1017 | StrCpy (String, L"&PATH=");\r | |
1018 | String += StrLen (String);\r | |
1019 | \r | |
1020 | //\r | |
1021 | // Append the device path associated with DriverHandle converted to <HexChar>DevicePathSize\r | |
1022 | //\r | |
1023 | for (Index = 0, Buffer = (UINT8 *)DevicePath; Index < DevicePathSize; Index++) {\r | |
1024 | String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, *(Buffer++), 2);\r | |
1025 | }\r | |
1026 | \r | |
1027 | //\r | |
1028 | // Null terminate the Unicode string\r | |
1029 | //\r | |
1030 | *String = L'\0';\r | |
1031 | \r | |
1032 | //\r | |
1033 | // Convert all hex digits in range [A-F] in the configuration header to [a-f]\r | |
1034 | //\r | |
1035 | return InternalHiiLowerConfigString (ReturnString);\r | |
1036 | }\r | |
1037 | \r | |
1038 | /**\r | |
1039 | Allocates and returns a Null-terminated Unicode <ConfigAltResp> string.\r | |
1040 | \r | |
1041 | If Guid is NULL, then ASSERT().\r | |
1042 | If Name is NULL, then ASSERT().\r | |
1043 | If BlockNameArray is NULL, then ASSERT().\r | |
1044 | \r | |
1045 | @param[in] Guid GUID of the buffer storage.\r | |
1046 | @param[in] Name Name of the buffer storage.\r | |
1047 | @param[in] DriverHandle The DriverHandle that support a Device Path\r | |
1048 | Protocol. \r | |
1049 | @param[in] BufferStorage Content of the buffer storage.\r | |
1050 | @param[in] BufferStorageSize Length in bytes of the buffer storage.\r | |
1051 | @param[in] BlockNameArray Array generated by VFR compiler. This array\r | |
1052 | contains a UINT32 value that is the length\r | |
1053 | of BlockNameArray in bytes, followed by pairs\r | |
1054 | of 16-bit values that are the offset and length\r | |
1055 | values used to contruct a <ConfigRequest> string.\r | |
1056 | @param[in] ... A variable argument list that contains pairs of 16-bit\r | |
1057 | ALTCFG identifiers and pointers to DefaultValueArrays.\r | |
1058 | The variable argument list is terminated by a NULL \r | |
1059 | DefaultValueArray pointer. A DefaultValueArray \r | |
1060 | contains a UINT32 value that is the length, in bytes,\r | |
1061 | of the DefaultValueArray. The UINT32 length value \r | |
1062 | is followed by a series of records that contain\r | |
1063 | a 16-bit WIDTH value followed by a byte array with \r | |
1064 | WIDTH entries. The records must be parsed from\r | |
1065 | beginning to end until the UINT32 length limit\r | |
1066 | is reached. \r | |
1067 | \r | |
1068 | @retval NULL There are not enough resources to process the request.\r | |
1069 | @retval NULL A <ConfigResp> could not be retrieved from the Config \r | |
1070 | Routing Protocol.\r | |
1071 | @retval Other A pointer to the Null-terminate Unicode <ConfigAltResp>\r | |
1072 | string.\r | |
1073 | \r | |
1074 | **/\r | |
1075 | EFI_STRING\r | |
1076 | EFIAPI\r | |
1077 | HiiConstructConfigAltResp (\r | |
1078 | IN CONST EFI_GUID *Guid,\r | |
1079 | IN CONST CHAR16 *Name,\r | |
1080 | IN EFI_HANDLE DriverHandle,\r | |
1081 | IN CONST VOID *BufferStorage,\r | |
1082 | IN UINTN BufferStorageSize,\r | |
1083 | IN CONST VOID *BlockNameArray, \r | |
1084 | ...\r | |
1085 | )\r | |
1086 | {\r | |
1087 | UINTN Length;\r | |
1088 | CHAR16 *String;\r | |
1089 | CHAR16 *ConfigHdr;\r | |
1090 | UINT8 *Buffer;\r | |
1091 | UINT8 *BufferEnd;\r | |
1092 | CHAR16 *ConfigRequest;\r | |
1093 | EFI_STRING ConfigResp;\r | |
1094 | EFI_STRING ConfigAltResp;\r | |
1095 | VA_LIST Args;\r | |
1096 | UINTN AltCfgId;\r | |
1097 | UINT16 Width;\r | |
5c1ebff6 LG |
1098 | UINT16 OffsetValue;\r |
1099 | UINT16 WidthValue;\r | |
7e3bcccb LG |
1100 | \r |
1101 | ASSERT (Guid != NULL);\r | |
1102 | ASSERT (Name != NULL);\r | |
1103 | ASSERT (BlockNameArray != NULL);\r | |
1104 | \r | |
1105 | //\r | |
1106 | // Initialize local variables\r | |
1107 | //\r | |
1108 | ConfigHdr = NULL;\r | |
1109 | ConfigRequest = NULL; \r | |
1110 | ConfigResp = NULL;\r | |
1111 | \r | |
1112 | //\r | |
1113 | // Construct <ConfigHdr> : "GUID=...&NAME=...&PATH=..."\r | |
1114 | //\r | |
1115 | ConfigHdr = HiiConstructConfigHdr (Guid, Name, DriverHandle);\r | |
1116 | if (ConfigHdr == NULL) {\r | |
1117 | goto Exit;\r | |
1118 | }\r | |
1119 | \r | |
1120 | //\r | |
1121 | // Compute the length of the entire request starting with <ConfigHdr> and a \r | |
1122 | // Null-terminator\r | |
1123 | //\r | |
1124 | Length = StrLen (ConfigHdr) + 1;\r | |
1125 | \r | |
1126 | //\r | |
1127 | // Determine the size <BlockName> Offset/Width pairs\r | |
1128 | //\r | |
1129 | Buffer = (UINT8 *)BlockNameArray;\r | |
1130 | BufferEnd = Buffer + ReadUnaligned32 ((UINT32 *)Buffer);\r | |
1131 | Buffer += sizeof (UINT32);\r | |
1132 | \r | |
1133 | //\r | |
1134 | // Add <BlockName> length that is composed of one or more Offset/Width pairs\r | |
1135 | //\r | |
1136 | // <BlockName> ::= &OFFSET=1234&WIDTH=1234\r | |
1137 | // | 8 | 4 | 7 | 4 |\r | |
1138 | //\r | |
1139 | Length += (((BufferEnd - Buffer) / (sizeof (UINT16) + sizeof (UINT16))) * (8 + 4 + 7 + 4));\r | |
1140 | \r | |
1141 | //\r | |
1142 | // Allocate buffer for the entire <ConfigRequest>\r | |
1143 | //\r | |
1144 | ConfigRequest = AllocateZeroPool (Length * sizeof (CHAR16));\r | |
1145 | if (ConfigRequest == NULL) {\r | |
1146 | goto Exit;\r | |
1147 | }\r | |
1148 | String = ConfigRequest;\r | |
1149 | \r | |
1150 | //\r | |
1151 | // Start with <ConfigHdr>\r | |
1152 | //\r | |
1153 | StrCpy (String, ConfigHdr);\r | |
1154 | String += StrLen (String);\r | |
1155 | \r | |
1156 | //\r | |
1157 | // Loop through all the Offset/Width pairs and append them to ConfigRequest\r | |
1158 | //\r | |
1159 | while (Buffer < BufferEnd) {\r | |
1160 | //\r | |
1161 | // Append &OFFSET=XXXX&WIDTH=YYYY\r | |
1162 | //\r | |
5c1ebff6 LG |
1163 | OffsetValue = ReadUnaligned16 ((UINT16 *)Buffer);\r |
1164 | WidthValue = ReadUnaligned16 ((UINT16 *)(Buffer + sizeof (UINT16)));\r | |
7e3bcccb LG |
1165 | UnicodeSPrint (\r |
1166 | String, \r | |
1167 | (8 + 4 + 7 + 4) * sizeof (CHAR16), \r | |
1168 | L"&OFFSET=%04X&WIDTH=%04X", \r | |
5c1ebff6 LG |
1169 | OffsetValue, \r |
1170 | WidthValue\r | |
1171 | );\r | |
1172 | \r | |
7e3bcccb LG |
1173 | String += StrLen (String);\r |
1174 | Buffer += (sizeof (UINT16) + sizeof (UINT16));\r | |
1175 | }\r | |
1176 | \r | |
1177 | //\r | |
1178 | // Get the <ConfigResp>\r | |
1179 | //\r | |
1180 | ConfigResp = InternalHiiBlockToConfig (ConfigRequest, BufferStorage, BufferStorageSize);\r | |
1181 | if (ConfigResp == NULL) {\r | |
1182 | goto Exit;\r | |
1183 | }\r | |
1184 | \r | |
1185 | //\r | |
1186 | // Compute the length of the entire response starting with <ConfigResp> and a \r | |
1187 | // Null-terminator\r | |
1188 | //\r | |
1189 | Length = StrLen (ConfigResp) + 1;\r | |
1190 | \r | |
1191 | //\r | |
1192 | // Add the length associated with each pair of variable argument parameters\r | |
1193 | //\r | |
1194 | VA_START (Args, BlockNameArray);\r | |
1195 | while (TRUE) {\r | |
1196 | AltCfgId = VA_ARG (Args, UINT16);\r | |
1197 | Buffer = VA_ARG (Args, UINT8 *);\r | |
1198 | if (Buffer == NULL) {\r | |
1199 | break;\r | |
1200 | }\r | |
1201 | \r | |
1202 | //\r | |
1203 | // Add length for "&<ConfigHdr>&ALTCFG=XXXX"\r | |
1204 | // |1| StrLen (ConfigHdr) | 8 | 4 |\r | |
1205 | //\r | |
1206 | Length += (1 + StrLen (ConfigHdr) + 8 + 4);\r | |
1207 | \r | |
1208 | BufferEnd = Buffer + ReadUnaligned32 ((UINT32 *)Buffer);\r | |
1209 | Buffer += sizeof (UINT32);\r | |
1210 | while (Buffer < BufferEnd) {\r | |
1211 | //\r | |
1212 | // Extract Width field\r | |
1213 | //\r | |
1214 | Width = ReadUnaligned16 ((UINT16 *)(Buffer + sizeof (UINT16)));\r | |
1215 | \r | |
1216 | //\r | |
1217 | // Add length for "&OFFSET=XXXX&WIDTH=YYYY&VALUE=zzzzzzzzzzzz"\r | |
1218 | // | 8 | 4 | 7 | 4 | 7 | Width * 2 |\r | |
1219 | //\r | |
1220 | Length += (8 + 4 + 7 + 4 + 7 + Width * 2);\r | |
1221 | \r | |
1222 | //\r | |
1223 | // Update Buffer to the next record\r | |
1224 | //\r | |
1225 | Buffer += (sizeof (UINT16) + sizeof (UINT16) + Width);\r | |
1226 | }\r | |
1227 | }\r | |
1228 | VA_END (Args);\r | |
1229 | \r | |
1230 | //\r | |
1231 | // Allocate a buffer for the entire response\r | |
1232 | //\r | |
1233 | ConfigAltResp = AllocateZeroPool (Length * sizeof (CHAR16));\r | |
1234 | if (ConfigAltResp == NULL) {\r | |
1235 | goto Exit;\r | |
1236 | }\r | |
1237 | String = ConfigAltResp;\r | |
1238 | \r | |
1239 | //\r | |
1240 | // Add <ConfigResp>\r | |
1241 | //\r | |
1242 | StrCpy (String, ConfigResp);\r | |
1243 | String += StrLen (String);\r | |
1244 | \r | |
1245 | //\r | |
1246 | // Add <AltResp> for each pair of variable argument parameters\r | |
1247 | //\r | |
1248 | VA_START (Args, BlockNameArray);\r | |
1249 | while (TRUE) {\r | |
1250 | AltCfgId = VA_ARG (Args, UINT16);\r | |
1251 | Buffer = VA_ARG (Args, UINT8 *);\r | |
1252 | if (Buffer == NULL) {\r | |
1253 | break;\r | |
1254 | }\r | |
1255 | \r | |
1256 | //\r | |
1257 | // Add <AltConfigHdr> of the form "&<ConfigHdr>&ALTCFG=XXXX"\r | |
1258 | // |1| StrLen (ConfigHdr) | 8 | 4 |\r | |
1259 | //\r | |
1260 | UnicodeSPrint (\r | |
1261 | String, \r | |
1262 | (1 + StrLen (ConfigHdr) + 8 + 4) * sizeof (CHAR16), \r | |
1263 | L"&%s&ALTCFG=%04X", \r | |
1264 | ConfigHdr, \r | |
1265 | AltCfgId\r | |
1266 | );\r | |
1267 | String += StrLen (String);\r | |
1268 | \r | |
1269 | //\r | |
1270 | // Add <ConfigBody> ::= <ConfigElement>*\r | |
1271 | //\r | |
1272 | BufferEnd = Buffer + ReadUnaligned32 ((UINT32 *)Buffer);\r | |
1273 | Buffer += sizeof (UINT32);\r | |
1274 | while (Buffer < BufferEnd) {\r | |
1275 | //\r | |
1276 | // Extract Width field\r | |
1277 | //\r | |
1278 | Width = ReadUnaligned16 ((UINT16 *)(Buffer + sizeof (UINT16)));\r | |
1279 | \r | |
1280 | //\r | |
1281 | // Add <BlockConfig>\r | |
1282 | //\r | |
1283 | UnicodeSPrint (\r | |
1284 | String, \r | |
1285 | (8 + 4 + 7 + 4 + 7 + Width * 2) * sizeof (CHAR16),\r | |
1286 | L"&OFFSET=%04X&WIDTH=%04X&VALUE=", \r | |
1287 | ReadUnaligned16 ((UINT16 *)Buffer), \r | |
1288 | Width\r | |
1289 | );\r | |
1290 | String += StrLen (String);\r | |
1291 | \r | |
1292 | //\r | |
1293 | // Update Buffer to point to the value in the current record\r | |
1294 | //\r | |
1295 | Buffer += (sizeof (UINT16) + sizeof (UINT16));\r | |
1296 | \r | |
1297 | //\r | |
1298 | // Convert Value to a hex string in "%x" format\r | |
1299 | // NOTE: This is in the opposite byte that GUID and PATH use\r | |
1300 | //\r | |
1301 | for (; Width > 0; Width--) {\r | |
1302 | String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, Buffer[Width - 1], 2);\r | |
1303 | }\r | |
1304 | //\r | |
1305 | // Update Buffer to the next record\r | |
1306 | //\r | |
1307 | Buffer += Width;\r | |
1308 | }\r | |
1309 | }\r | |
1310 | VA_END (Args);\r | |
1311 | \r | |
1312 | //\r | |
1313 | // Convert all hex digits in range [A-F] in the configuration header to [a-f]\r | |
1314 | //\r | |
1315 | return InternalHiiLowerConfigString (ConfigAltResp);\r | |
1316 | \r | |
1317 | Exit:\r | |
1318 | if (ConfigHdr != NULL) {\r | |
1319 | FreePool (ConfigHdr);\r | |
1320 | }\r | |
1321 | if (ConfigRequest != NULL) {\r | |
1322 | FreePool (ConfigRequest);\r | |
1323 | }\r | |
1324 | if (ConfigResp != NULL) {\r | |
1325 | FreePool (ConfigResp);\r | |
1326 | }\r | |
1327 | \r | |
1328 | return NULL;\r | |
1329 | }\r | |
1330 | \r | |
1331 | /**\r | |
1332 | Determines if two values in config strings match.\r | |
1333 | \r | |
1334 | Compares the substring between StartSearchString and StopSearchString in \r | |
1335 | FirstString to the substring between StartSearchString and StopSearchString \r | |
1336 | in SecondString. If the two substrings match, then TRUE is returned. If the\r | |
1337 | two substrings do not match, then FALSE is returned.\r | |
1338 | \r | |
1339 | If FirstString is NULL, then ASSERT().\r | |
1340 | If SecondString is NULL, then ASSERT().\r | |
1341 | If StartSearchString is NULL, then ASSERT().\r | |
1342 | If StopSearchString is NULL, then ASSERT().\r | |
1343 | \r | |
1344 | @param FirstString Pointer to the first Null-terminated Unicode string.\r | |
1345 | @param SecondString Pointer to the second Null-terminated Unicode string.\r | |
1346 | @param StartSearchString Pointer to the Null-terminated Unicode string that \r | |
1347 | marks the start of the value string to compare.\r | |
1348 | @param StopSearchString Pointer to the Null-terminated Unicode string that \r | |
1349 | marks the end of the vakue string to compare.\r | |
1350 | \r | |
1351 | @retval FALSE StartSearchString is not present in FirstString. \r | |
1352 | @retval FALSE StartSearchString is not present in SecondString.\r | |
1353 | @retval FALSE StopSearchString is not present in FirstString. \r | |
1354 | @retval FALSE StopSearchString is not present in SecondString.\r | |
1355 | @retval FALSE The length of the substring in FirstString is not the \r | |
1356 | same length as the substring in SecondString.\r | |
1357 | @retval FALSE The value string in FirstString does not matche the \r | |
1358 | value string in SecondString.\r | |
1359 | @retval TRUE The value string in FirstString matches the value \r | |
1360 | string in SecondString.\r | |
1361 | \r | |
1362 | **/\r | |
1363 | BOOLEAN\r | |
1364 | EFIAPI\r | |
1365 | InternalHiiCompareSubString (\r | |
1366 | IN CHAR16 *FirstString,\r | |
1367 | IN CHAR16 *SecondString,\r | |
1368 | IN CHAR16 *StartSearchString,\r | |
1369 | IN CHAR16 *StopSearchString\r | |
1370 | )\r | |
1371 | {\r | |
1372 | CHAR16 *EndFirstString;\r | |
1373 | CHAR16 *EndSecondString;\r | |
1374 | \r | |
1375 | ASSERT (FirstString != NULL);\r | |
1376 | ASSERT (SecondString != NULL);\r | |
1377 | ASSERT (StartSearchString != NULL);\r | |
1378 | ASSERT (StopSearchString != NULL);\r | |
1379 | \r | |
1380 | FirstString = StrStr (FirstString, StartSearchString);\r | |
1381 | if (FirstString == NULL) {\r | |
1382 | return FALSE;\r | |
1383 | }\r | |
1384 | \r | |
1385 | SecondString = StrStr (SecondString, StartSearchString);\r | |
1386 | if (SecondString == NULL) {\r | |
1387 | return FALSE;\r | |
1388 | }\r | |
1389 | \r | |
1390 | EndFirstString = StrStr (FirstString, StopSearchString);\r | |
1391 | if (EndFirstString == NULL) {\r | |
1392 | return FALSE;\r | |
1393 | }\r | |
1394 | \r | |
1395 | EndSecondString = StrStr (SecondString, StopSearchString);\r | |
1396 | if (EndSecondString == NULL) {\r | |
1397 | return FALSE;\r | |
1398 | }\r | |
1399 | \r | |
1400 | if ((EndFirstString - FirstString) != (EndSecondString - SecondString)) {\r | |
1401 | return FALSE;\r | |
1402 | }\r | |
1403 | \r | |
1404 | return (BOOLEAN)(StrnCmp (FirstString, SecondString, EndFirstString - FirstString) == 0);\r | |
1405 | }\r | |
1406 | \r | |
1407 | /**\r | |
1408 | Determines if the routing data specified by GUID and NAME match a <ConfigHdr>.\r | |
1409 | \r | |
1410 | If ConfigHdr is NULL, then ASSERT().\r | |
1411 | \r | |
1412 | @param[in] ConfigHdr Either <ConfigRequest> or <ConfigResp>.\r | |
1413 | @param[in] Guid GUID of the storage.\r | |
1414 | @param[in] Name NAME of the storage.\r | |
1415 | \r | |
1416 | @retval TRUE Routing information matches <ConfigHdr>.\r | |
1417 | @retval FALSE Routing information does not match <ConfigHdr>.\r | |
1418 | \r | |
1419 | **/\r | |
1420 | BOOLEAN\r | |
1421 | EFIAPI\r | |
1422 | HiiIsConfigHdrMatch (\r | |
1423 | IN CONST EFI_STRING ConfigHdr,\r | |
1424 | IN CONST EFI_GUID *Guid, OPTIONAL\r | |
1425 | IN CONST CHAR16 *Name OPTIONAL\r | |
1426 | )\r | |
1427 | {\r | |
1428 | EFI_STRING CompareConfigHdr;\r | |
1429 | BOOLEAN Result;\r | |
1430 | \r | |
1431 | ASSERT (ConfigHdr != NULL);\r | |
1432 | \r | |
1433 | //\r | |
1434 | // Use Guid and Name to generate a <ConfigHdr> string\r | |
1435 | //\r | |
1436 | CompareConfigHdr = HiiConstructConfigHdr (Guid, Name, NULL);\r | |
1437 | if (CompareConfigHdr == NULL) {\r | |
1438 | return FALSE;\r | |
1439 | }\r | |
1440 | \r | |
1441 | Result = TRUE;\r | |
1442 | if (Guid != NULL) {\r | |
1443 | //\r | |
1444 | // Compare GUID value strings\r | |
1445 | //\r | |
1446 | Result = InternalHiiCompareSubString (ConfigHdr, CompareConfigHdr, L"GUID=", L"&NAME=");\r | |
1447 | }\r | |
1448 | \r | |
1449 | if (Result && Name != NULL) {\r | |
1450 | //\r | |
1451 | // Compare NAME value strings\r | |
1452 | //\r | |
1453 | Result = InternalHiiCompareSubString (ConfigHdr, CompareConfigHdr, L"&NAME=", L"&PATH=");\r | |
1454 | }\r | |
1455 | \r | |
1456 | //\r | |
1457 | // Free the <ConfigHdr> string\r | |
1458 | //\r | |
1459 | FreePool (CompareConfigHdr);\r | |
1460 | \r | |
1461 | return Result;\r | |
1462 | }\r | |
1463 | \r | |
1464 | /**\r | |
1465 | Retrieves uncommited data from the Form Browser and converts it to a binary\r | |
1466 | buffer. The returned buffer is allocated using AllocatePool(). The caller\r | |
1467 | is responsible for freeing the returned buffer using FreePool().\r | |
1468 | \r | |
1469 | @param[in] VariableName Pointer to a Null-terminated Unicode string. This \r | |
1470 | is an optional parameter that may be NULL.\r | |
1471 | @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional \r | |
1472 | parameter that may be NULL.\r | |
1473 | @param[in] BufferSize Length in bytes of buffer to hold retrived data. \r | |
1474 | \r | |
1475 | @retval NULL The uncommitted data could not be retrieved.\r | |
1476 | @retval Other A pointer to a buffer containing the uncommitted data.\r | |
1477 | \r | |
1478 | **/\r | |
1479 | UINT8 *\r | |
1480 | EFIAPI\r | |
1481 | HiiGetBrowserData (\r | |
1482 | IN CONST EFI_GUID *VariableGuid, OPTIONAL\r | |
1483 | IN CONST CHAR16 *VariableName, OPTIONAL\r | |
1484 | IN UINTN BlockSize\r | |
1485 | )\r | |
1486 | {\r | |
1487 | EFI_STRING ResultsData;\r | |
1488 | UINTN Size;\r | |
1489 | EFI_STRING ConfigResp;\r | |
1490 | UINT8 *Block;\r | |
1491 | \r | |
1492 | //\r | |
1493 | // Retrieve the results data from the Browser Callback\r | |
1494 | //\r | |
1495 | ResultsData = InternalHiiBrowserCallback (VariableGuid, VariableName, NULL);\r | |
1496 | if (ResultsData == NULL) {\r | |
1497 | return NULL;\r | |
1498 | }\r | |
1499 | \r | |
1500 | //\r | |
5c1ebff6 | 1501 | // Construct <ConfigResp> mConfigHdrTemplate L'&' ResultsData L'\0'\r |
7e3bcccb | 1502 | //\r |
5c1ebff6 LG |
1503 | Size = (StrLen (mConfigHdrTemplate) + 1) * sizeof (CHAR16);\r |
1504 | Size = Size + (StrLen (ResultsData) + 1) * sizeof (CHAR16);\r | |
7e3bcccb LG |
1505 | ConfigResp = AllocateZeroPool (Size);\r |
1506 | UnicodeSPrint (ConfigResp, Size, L"%s&%s", mConfigHdrTemplate, ResultsData);\r | |
1507 | \r | |
1508 | //\r | |
1509 | // Free the allocated buffer\r | |
1510 | //\r | |
1511 | FreePool (ResultsData);\r | |
1512 | if (ConfigResp == NULL) {\r | |
1513 | return NULL;\r | |
1514 | }\r | |
1515 | \r | |
1516 | //\r | |
1517 | // Convert <ConfigResp> to a buffer\r | |
1518 | //\r | |
1519 | Block = InternalHiiConfigToBlock (ConfigResp, BlockSize);\r | |
1520 | FreePool (ConfigResp);\r | |
1521 | \r | |
1522 | return Block;\r | |
1523 | }\r | |
1524 | \r | |
1525 | /**\r | |
1526 | Updates uncommitted data in the Form Browser.\r | |
1527 | \r | |
1528 | If Buffer is NULL, then ASSERT().\r | |
1529 | \r | |
1530 | @param[in] VariableName Pointer to a Null-terminated Unicode string. This\r | |
1531 | is an optional parameter that may be NULL.\r | |
1532 | @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional\r | |
1533 | parameter that may be NULL.\r | |
1534 | @param[in] BufferSize Length, in bytes, of Buffer.\r | |
1535 | @param[in] Buffer Buffer of data to commit.\r | |
1536 | @param[in] RequestElement An optional field to specify which part of the\r | |
1537 | buffer data will be send back to Browser. If NULL,\r | |
1538 | the whole buffer of data will be committed to\r | |
1539 | Browser. \r | |
1540 | <RequestElement> ::= &OFFSET=<Number>&WIDTH=<Number>*\r | |
1541 | \r | |
1542 | @retval FALSE The uncommitted data could not be updated.\r | |
1543 | @retval TRUE The uncommitted data was updated.\r | |
1544 | \r | |
1545 | **/\r | |
1546 | BOOLEAN\r | |
1547 | EFIAPI\r | |
1548 | HiiSetBrowserData (\r | |
1549 | IN CONST EFI_GUID *VariableGuid, OPTIONAL\r | |
1550 | IN CONST CHAR16 *VariableName, OPTIONAL\r | |
1551 | IN UINTN BufferSize,\r | |
1552 | IN CONST UINT8 *Buffer,\r | |
1553 | IN CONST CHAR16 *RequestElement OPTIONAL\r | |
1554 | )\r | |
1555 | {\r | |
1556 | UINTN Size;\r | |
1557 | EFI_STRING ConfigRequest;\r | |
1558 | EFI_STRING ConfigResp;\r | |
1559 | EFI_STRING ResultsData;\r | |
1560 | \r | |
1561 | ASSERT (Buffer != NULL);\r | |
1562 | \r | |
1563 | //\r | |
1564 | // Construct <ConfigRequest>\r | |
1565 | //\r | |
1566 | if (RequestElement == NULL) {\r | |
1567 | //\r | |
1568 | // Allocate and fill a buffer large enough to hold the <ConfigHdr> template \r | |
1569 | // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r | |
1570 | //\r | |
1571 | Size = (StrLen (mConfigHdrTemplate) + 32 + 1) * sizeof (CHAR16);\r | |
1572 | ConfigRequest = AllocateZeroPool (Size);\r | |
1573 | UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", mConfigHdrTemplate, (UINT64)BufferSize);\r | |
1574 | } else {\r | |
1575 | //\r | |
1576 | // Allocate and fill a buffer large enough to hold the <ConfigHdr> template \r | |
1577 | // followed by <RequestElement> followed by a Null-terminator\r | |
1578 | //\r | |
5c1ebff6 LG |
1579 | Size = StrLen (mConfigHdrTemplate) * sizeof (CHAR16);\r |
1580 | Size = Size + (StrLen (RequestElement) + 1) * sizeof (CHAR16);\r | |
7e3bcccb LG |
1581 | ConfigRequest = AllocateZeroPool (Size);\r |
1582 | UnicodeSPrint (ConfigRequest, Size, L"%s%s", mConfigHdrTemplate, RequestElement);\r | |
1583 | }\r | |
1584 | if (ConfigRequest == NULL) {\r | |
1585 | return FALSE;\r | |
1586 | }\r | |
1587 | \r | |
1588 | //\r | |
1589 | // Convert <ConfigRequest> to <ConfigResp>\r | |
1590 | //\r | |
1591 | ConfigResp = InternalHiiBlockToConfig (ConfigRequest, Buffer, BufferSize);\r | |
1592 | FreePool (ConfigRequest);\r | |
1593 | if (ConfigResp == NULL) {\r | |
1594 | return FALSE;\r | |
1595 | }\r | |
1596 | \r | |
1597 | //\r | |
1598 | // Set data in the uncommitted browser state information\r | |
1599 | //\r | |
1600 | ResultsData = InternalHiiBrowserCallback (VariableGuid, VariableName, ConfigResp + StrLen(mConfigHdrTemplate) + 1);\r | |
1601 | FreePool (ConfigResp);\r | |
1602 | \r | |
1603 | return (BOOLEAN)(ResultsData != NULL);\r | |
1604 | }\r | |
1605 | \r | |
1606 | /////////////////////////////////////////\r | |
1607 | /////////////////////////////////////////\r | |
1608 | /// IFR Functions\r | |
1609 | /////////////////////////////////////////\r | |
1610 | /////////////////////////////////////////\r | |
1611 | \r | |
1612 | #define HII_LIB_OPCODE_ALLOCATION_SIZE 0x200\r | |
1613 | \r | |
1614 | typedef struct {\r | |
1615 | UINT8 *Buffer;\r | |
1616 | UINTN BufferSize;\r | |
1617 | UINTN Position;\r | |
1618 | } HII_LIB_OPCODE_BUFFER;\r | |
1619 | \r | |
1620 | ///\r | |
1621 | /// Lookup table that converts EFI_IFR_TYPE_X enum values to a width in bytes\r | |
1622 | ///\r | |
1623 | GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 mHiiDefaultTypeToWidth[] = {\r | |
1624 | 1, // EFI_IFR_TYPE_NUM_SIZE_8\r | |
1625 | 2, // EFI_IFR_TYPE_NUM_SIZE_16\r | |
1626 | 4, // EFI_IFR_TYPE_NUM_SIZE_32\r | |
1627 | 8, // EFI_IFR_TYPE_NUM_SIZE_64\r | |
1628 | 1, // EFI_IFR_TYPE_BOOLEAN\r | |
1629 | 3, // EFI_IFR_TYPE_TIME\r | |
1630 | 4, // EFI_IFR_TYPE_DATE\r | |
1631 | 2 // EFI_IFR_TYPE_STRING\r | |
1632 | };\r | |
1633 | \r | |
1634 | /**\r | |
1635 | Allocates and returns a new OpCode Handle. OpCode Handles must be freed with \r | |
1636 | HiiFreeOpCodeHandle().\r | |
1637 | \r | |
1638 | @retval NULL There are not enough resources to allocate a new OpCode Handle.\r | |
1639 | @retval Other A new OpCode handle.\r | |
1640 | \r | |
1641 | **/\r | |
1642 | VOID *\r | |
1643 | EFIAPI\r | |
1644 | HiiAllocateOpCodeHandle (\r | |
1645 | VOID\r | |
1646 | )\r | |
1647 | {\r | |
1648 | HII_LIB_OPCODE_BUFFER *OpCodeBuffer;\r | |
1649 | \r | |
1650 | OpCodeBuffer = (HII_LIB_OPCODE_BUFFER *)AllocatePool (sizeof (HII_LIB_OPCODE_BUFFER));\r | |
1651 | if (OpCodeBuffer == NULL) {\r | |
1652 | return NULL;\r | |
1653 | }\r | |
1654 | OpCodeBuffer->Buffer = (UINT8 *)AllocatePool (HII_LIB_OPCODE_ALLOCATION_SIZE);\r | |
1655 | if (OpCodeBuffer->Buffer == NULL) {\r | |
1656 | FreePool (OpCodeBuffer);\r | |
1657 | return NULL;\r | |
1658 | }\r | |
1659 | OpCodeBuffer->BufferSize = HII_LIB_OPCODE_ALLOCATION_SIZE;\r | |
1660 | OpCodeBuffer->Position = 0;\r | |
1661 | return (VOID *)OpCodeBuffer;\r | |
1662 | }\r | |
1663 | \r | |
1664 | /**\r | |
1665 | Frees an OpCode Handle that was peviously allocated with HiiAllocateOpCodeHandle().\r | |
1666 | When an OpCode Handle is freed, all of the opcodes associated with the OpCode\r | |
1667 | Handle are also freed.\r | |
1668 | \r | |
1669 | If OpCodeHandle is NULL, then ASSERT().\r | |
1670 | \r | |
1671 | **/\r | |
1672 | VOID\r | |
1673 | EFIAPI\r | |
1674 | HiiFreeOpCodeHandle (\r | |
1675 | VOID *OpCodeHandle\r | |
1676 | )\r | |
1677 | {\r | |
1678 | HII_LIB_OPCODE_BUFFER *OpCodeBuffer;\r | |
1679 | \r | |
1680 | ASSERT (OpCodeHandle != NULL);\r | |
1681 | \r | |
1682 | OpCodeBuffer = (HII_LIB_OPCODE_BUFFER *)OpCodeHandle;\r | |
1683 | if (OpCodeBuffer->Buffer != NULL) {\r | |
1684 | FreePool (OpCodeBuffer->Buffer);\r | |
1685 | }\r | |
1686 | FreePool (OpCodeBuffer);\r | |
1687 | }\r | |
1688 | \r | |
1689 | UINTN\r | |
1690 | EFIAPI\r | |
1691 | InternalHiiOpCodeHandlePosition (\r | |
1692 | IN VOID *OpCodeHandle\r | |
1693 | )\r | |
1694 | {\r | |
1695 | return ((HII_LIB_OPCODE_BUFFER *)OpCodeHandle)->Position;\r | |
1696 | }\r | |
1697 | \r | |
1698 | UINT8 *\r | |
1699 | EFIAPI\r | |
1700 | InternalHiiOpCodeHandleBuffer (\r | |
1701 | IN VOID *OpCodeHandle\r | |
1702 | )\r | |
1703 | {\r | |
1704 | return ((HII_LIB_OPCODE_BUFFER *)OpCodeHandle)->Buffer;\r | |
1705 | }\r | |
1706 | \r | |
1707 | UINT8 *\r | |
1708 | EFIAPI\r | |
1709 | InternalHiiGrowOpCodeHandle (\r | |
1710 | VOID *OpCodeHandle,\r | |
1711 | UINTN Size\r | |
1712 | )\r | |
1713 | {\r | |
1714 | HII_LIB_OPCODE_BUFFER *OpCodeBuffer;\r | |
1715 | UINT8 *Buffer;\r | |
1716 | \r | |
1717 | ASSERT (OpCodeHandle != NULL);\r | |
1718 | \r | |
1719 | OpCodeBuffer = (HII_LIB_OPCODE_BUFFER *)OpCodeHandle;\r | |
1720 | if (OpCodeBuffer->Position + Size > OpCodeBuffer->BufferSize) {\r | |
1721 | Buffer = ReallocatePool (\r | |
1722 | OpCodeBuffer->BufferSize, \r | |
1723 | OpCodeBuffer->BufferSize + (Size + HII_LIB_OPCODE_ALLOCATION_SIZE),\r | |
1724 | OpCodeBuffer->Buffer\r | |
1725 | );\r | |
1726 | if (Buffer == NULL) {\r | |
1727 | return NULL;\r | |
1728 | }\r | |
1729 | OpCodeBuffer->Buffer = Buffer;\r | |
1730 | OpCodeBuffer->BufferSize += (Size + HII_LIB_OPCODE_ALLOCATION_SIZE);\r | |
1731 | }\r | |
1732 | Buffer = OpCodeBuffer->Buffer + OpCodeBuffer->Position;\r | |
1733 | OpCodeBuffer->Position += Size;\r | |
1734 | return Buffer;\r | |
1735 | }\r | |
1736 | \r | |
1737 | UINT8 *\r | |
1738 | EFIAPI\r | |
1739 | InternalHiiCreateOpCodeExtended (\r | |
1740 | IN VOID *OpCodeHandle,\r | |
1741 | IN VOID *OpCodeTemplate,\r | |
1742 | IN UINT8 OpCode,\r | |
1743 | IN UINTN OpCodeSize,\r | |
1744 | IN UINTN ExtensionSize,\r | |
1745 | IN UINT8 Scope\r | |
1746 | )\r | |
1747 | {\r | |
1748 | EFI_IFR_OP_HEADER *Header;\r | |
1749 | UINT8 *Buffer;\r | |
1750 | \r | |
1751 | ASSERT (OpCodeTemplate != NULL);\r | |
1752 | ASSERT ((OpCodeSize + ExtensionSize) <= 0x7F);\r | |
1753 | \r | |
1754 | Header = (EFI_IFR_OP_HEADER *)OpCodeTemplate;\r | |
1755 | Header->OpCode = OpCode;\r | |
1756 | Header->Scope = Scope;\r | |
1757 | Header->Length = (UINT8)(OpCodeSize + ExtensionSize);\r | |
1758 | Buffer = InternalHiiGrowOpCodeHandle (OpCodeHandle, Header->Length);\r | |
1759 | return (UINT8 *)CopyMem (Buffer, Header, OpCodeSize);\r | |
1760 | }\r | |
1761 | \r | |
1762 | UINT8 *\r | |
1763 | EFIAPI\r | |
1764 | InternalHiiCreateOpCode (\r | |
1765 | IN VOID *OpCodeHandle,\r | |
1766 | IN VOID *OpCodeTemplate,\r | |
1767 | IN UINT8 OpCode,\r | |
1768 | IN UINTN OpCodeSize\r | |
1769 | )\r | |
1770 | {\r | |
1771 | return InternalHiiCreateOpCodeExtended (OpCodeHandle, OpCodeTemplate, OpCode, OpCodeSize, 0, 0);\r | |
1772 | }\r | |
1773 | \r | |
1774 | /**\r | |
1775 | Append raw opcodes to an OpCodeHandle.\r | |
1776 | \r | |
1777 | If OpCodeHandle is NULL, then ASSERT().\r | |
1778 | If RawBuffer is NULL, then ASSERT();\r | |
1779 | \r | |
1780 | @param[in] OpCodeHandle Handle to the buffer of opcodes.\r | |
1781 | @param[in] RawBuffer Buffer of opcodes to append.\r | |
1782 | @param[in] RawBufferSize The size, in bytes, of Buffer.\r | |
1783 | \r | |
1784 | @retval NULL There is not enough space left in Buffer to add the opcode.\r | |
1785 | @retval Other A pointer to the appended opcodes.\r | |
1786 | \r | |
1787 | **/\r | |
1788 | UINT8 *\r | |
1789 | EFIAPI\r | |
1790 | InternalHiiCreateRawOpCodes (\r | |
1791 | IN VOID *OpCodeHandle,\r | |
1792 | IN UINT8 *RawBuffer,\r | |
1793 | IN UINTN RawBufferSize\r | |
1794 | )\r | |
1795 | {\r | |
1796 | UINT8 *Buffer;\r | |
1797 | \r | |
1798 | ASSERT (RawBuffer != NULL);\r | |
1799 | \r | |
1800 | Buffer = InternalHiiGrowOpCodeHandle (OpCodeHandle, RawBufferSize);\r | |
1801 | return (UINT8 *)CopyMem (Buffer, RawBuffer, RawBufferSize);\r | |
1802 | }\r | |
1803 | \r | |
1804 | /**\r | |
1805 | Append opcodes from one OpCode Handle to another OpCode handle.\r | |
1806 | \r | |
1807 | If OpCodeHandle is NULL, then ASSERT().\r | |
1808 | If RawOpCodeHandle is NULL, then ASSERT();\r | |
1809 | \r | |
1810 | @param[in] OpCodeHandle Handle to the buffer of opcodes.\r | |
1811 | @param[in] RawOpCodeHandle Handle to the buffer of opcodes.\r | |
1812 | \r | |
1813 | @retval NULL There is not enough space left in Buffer to add the opcode.\r | |
1814 | @retval Other A pointer to the appended opcodes.\r | |
1815 | \r | |
1816 | **/\r | |
1817 | UINT8 *\r | |
1818 | EFIAPI\r | |
1819 | InternalHiiAppendOpCodes (\r | |
1820 | IN VOID *OpCodeHandle,\r | |
1821 | IN VOID *RawOpCodeHandle\r | |
1822 | )\r | |
1823 | {\r | |
1824 | HII_LIB_OPCODE_BUFFER *RawOpCodeBuffer;\r | |
1825 | \r | |
1826 | ASSERT (RawOpCodeHandle != NULL);\r | |
1827 | \r | |
1828 | RawOpCodeBuffer = (HII_LIB_OPCODE_BUFFER *)RawOpCodeHandle;\r | |
1829 | return InternalHiiCreateRawOpCodes (OpCodeHandle, RawOpCodeBuffer->Buffer, RawOpCodeBuffer->Position);\r | |
1830 | }\r | |
1831 | \r | |
1832 | /**\r | |
1833 | Create EFI_IFR_END_OP opcode.\r | |
1834 | \r | |
1835 | If OpCodeHandle is NULL, then ASSERT().\r | |
1836 | \r | |
1837 | @param[in] OpCodeHandle Handle to the buffer of opcodes.\r | |
1838 | \r | |
1839 | @retval NULL There is not enough space left in Buffer to add the opcode.\r | |
1840 | @retval Other A pointer to the created opcode.\r | |
1841 | \r | |
1842 | **/\r | |
1843 | UINT8 *\r | |
1844 | EFIAPI\r | |
1845 | HiiCreateEndOpCode (\r | |
1846 | IN VOID *OpCodeHandle\r | |
1847 | )\r | |
1848 | {\r | |
1849 | EFI_IFR_END OpCode;\r | |
1850 | \r | |
1851 | return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_END_OP, sizeof (OpCode));\r | |
1852 | }\r | |
1853 | \r | |
1854 | /**\r | |
1855 | Create EFI_IFR_ONE_OF_OPTION_OP opcode.\r | |
1856 | \r | |
1857 | If OpCodeHandle is NULL, then ASSERT().\r | |
1858 | If Type is invalid, then ASSERT().\r | |
1859 | If Flags is invalid, then ASSERT().\r | |
1860 | \r | |
1861 | @param[in] OpCodeHandle Handle to the buffer of opcodes.\r | |
1862 | @param[in] StringId StringId for the option\r | |
1863 | @param[in] Flags Flags for the option\r | |
1864 | @param[in] Type Type for the option\r | |
1865 | @param[in] Value Value for the option\r | |
1866 | \r | |
1867 | @retval NULL There is not enough space left in Buffer to add the opcode.\r | |
1868 | @retval Other A pointer to the created opcode.\r | |
1869 | \r | |
1870 | **/\r | |
1871 | UINT8 *\r | |
1872 | EFIAPI\r | |
1873 | HiiCreateOneOfOptionOpCode (\r | |
1874 | IN VOID *OpCodeHandle,\r | |
1875 | IN UINT16 StringId,\r | |
1876 | IN UINT8 Flags,\r | |
1877 | IN UINT8 Type,\r | |
1878 | IN UINT64 Value\r | |
1879 | )\r | |
1880 | {\r | |
1881 | EFI_IFR_ONE_OF_OPTION OpCode;\r | |
1882 | \r | |
1883 | ASSERT (Type < EFI_IFR_TYPE_OTHER);\r | |
1884 | \r | |
1885 | ZeroMem (&OpCode, sizeof (OpCode));\r | |
1886 | OpCode.Option = StringId;\r | |
1887 | OpCode.Flags = (UINT8) (Flags & (EFI_IFR_OPTION_DEFAULT | EFI_IFR_OPTION_DEFAULT_MFG));\r | |
1888 | OpCode.Type = Type;\r | |
1889 | CopyMem (&OpCode.Value, &Value, mHiiDefaultTypeToWidth[Type]);\r | |
1890 | \r | |
1891 | return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_ONE_OF_OPTION_OP, sizeof (OpCode));\r | |
1892 | }\r | |
1893 | \r | |
1894 | /**\r | |
1895 | Create EFI_IFR_DEFAULT_OP opcode.\r | |
1896 | \r | |
1897 | If OpCodeHandle is NULL, then ASSERT().\r | |
1898 | If Type is invalid, then ASSERT().\r | |
1899 | \r | |
1900 | @param[in] OpCodeHandle Handle to the buffer of opcodes.\r | |
1901 | @param[in] DefaultId DefaultId for the default\r | |
1902 | @param[in] Type Type for the default\r | |
1903 | @param[in] Value Value for the default\r | |
1904 | \r | |
1905 | @retval NULL There is not enough space left in Buffer to add the opcode.\r | |
1906 | @retval Other A pointer to the created opcode.\r | |
1907 | \r | |
1908 | **/\r | |
1909 | UINT8 *\r | |
1910 | EFIAPI\r | |
1911 | HiiCreateDefaultOpCode (\r | |
1912 | IN VOID *OpCodeHandle,\r | |
1913 | IN UINT16 DefaultId,\r | |
1914 | IN UINT8 Type,\r | |
1915 | IN UINT64 Value\r | |
1916 | )\r | |
1917 | {\r | |
1918 | EFI_IFR_DEFAULT OpCode;\r | |
1919 | \r | |
1920 | ASSERT (Type < EFI_IFR_TYPE_OTHER);\r | |
1921 | \r | |
1922 | ZeroMem (&OpCode, sizeof (OpCode));\r | |
1923 | OpCode.Type = Type;\r | |
1924 | OpCode.DefaultId = DefaultId;\r | |
1925 | CopyMem (&OpCode.Value, &Value, mHiiDefaultTypeToWidth[Type]);\r | |
1926 | \r | |
1927 | return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_DEFAULT_OP, sizeof (OpCode));\r | |
1928 | }\r | |
1929 | \r | |
1930 | /**\r | |
1931 | Create EFI_IFR_GUID opcode.\r | |
1932 | \r | |
1933 | If OpCodeHandle is NULL, then ASSERT().\r | |
1934 | If Guid is NULL, then ASSERT().\r | |
1935 | If OpCodeSize < sizeof (EFI_IFR_GUID), then ASSERT().\r | |
1936 | \r | |
1937 | @param[in] OpCodeHandle Handle to the buffer of opcodes.\r | |
1938 | @param[in] Guid Pointer to EFI_GUID of this guided opcode.\r | |
1939 | @param[in] GuidOpCode Pointer to an EFI_IFR_GUID opcode. This is an \r | |
1940 | optional parameter that may be NULL. If this\r | |
1941 | parameter is NULL, then the GUID extension \r | |
1942 | region of the created opcode is filled with zeros.\r | |
1943 | If this parameter is not NULL, then the GUID \r | |
1944 | extension region of GuidData will be copied to \r | |
1945 | the GUID extension region of the created opcode.\r | |
1946 | @param[in] OpCodeSize The size, in bytes, of created opcode. This value \r | |
1947 | must be >= sizeof(EFI_IFR_GUID).\r | |
1948 | \r | |
1949 | @retval NULL There is not enough space left in Buffer to add the opcode.\r | |
1950 | @retval Other A pointer to the created opcode.\r | |
1951 | \r | |
1952 | **/\r | |
1953 | UINT8 *\r | |
1954 | EFIAPI\r | |
1955 | HiiCreateGuidOpCode (\r | |
1956 | IN VOID *OpCodeHandle,\r | |
1957 | IN CONST EFI_GUID *Guid,\r | |
1958 | IN CONST VOID *GuidOpCode, OPTIONAL\r | |
1959 | IN UINTN OpCodeSize\r | |
1960 | )\r | |
1961 | {\r | |
1962 | EFI_IFR_GUID OpCode;\r | |
1963 | EFI_IFR_GUID *OpCodePointer;\r | |
1964 | \r | |
1965 | ASSERT (Guid != NULL);\r | |
1966 | ASSERT (OpCodeSize >= sizeof (OpCode));\r | |
1967 | \r | |
1968 | ZeroMem (&OpCode, sizeof (OpCode));\r | |
5c1ebff6 | 1969 | CopyGuid ((EFI_GUID *)(VOID *)&OpCode.Guid, Guid);\r |
7e3bcccb LG |
1970 | \r |
1971 | OpCodePointer = (EFI_IFR_GUID *)InternalHiiCreateOpCodeExtended (\r | |
1972 | OpCodeHandle, \r | |
1973 | &OpCode,\r | |
1974 | EFI_IFR_GUID_OP,\r | |
1975 | sizeof (OpCode),\r | |
1976 | OpCodeSize - sizeof (OpCode),\r | |
1977 | 0\r | |
1978 | );\r | |
1979 | if (OpCodePointer != NULL && GuidOpCode != NULL) {\r | |
1980 | CopyMem (OpCodePointer + 1, (EFI_IFR_GUID *)GuidOpCode + 1, OpCodeSize - sizeof (OpCode));\r | |
1981 | }\r | |
1982 | return (UINT8 *)OpCodePointer;\r | |
1983 | }\r | |
1984 | \r | |
1985 | /**\r | |
1986 | Create EFI_IFR_ACTION_OP opcode.\r | |
1987 | \r | |
1988 | If OpCodeHandle is NULL, then ASSERT().\r | |
1989 | If any reserved bits are set in QuestionFlags, then ASSERT().\r | |
1990 | \r | |
1991 | @param[in] OpCodeHandle Handle to the buffer of opcodes.\r | |
1992 | @param[in] QuestionId Question ID\r | |
1993 | @param[in] Prompt String ID for Prompt\r | |
1994 | @param[in] Help String ID for Help\r | |
1995 | @param[in] QuestionFlags Flags in Question Header\r | |
1996 | @param[in] QuestionConfig String ID for configuration\r | |
1997 | \r | |
1998 | @retval NULL There is not enough space left in Buffer to add the opcode.\r | |
1999 | @retval Other A pointer to the created opcode.\r | |
2000 | \r | |
2001 | **/\r | |
2002 | UINT8 *\r | |
2003 | EFIAPI\r | |
2004 | HiiCreateActionOpCode (\r | |
2005 | IN VOID *OpCodeHandle,\r | |
2006 | IN EFI_QUESTION_ID QuestionId,\r | |
2007 | IN EFI_STRING_ID Prompt,\r | |
2008 | IN EFI_STRING_ID Help,\r | |
2009 | IN UINT8 QuestionFlags,\r | |
2010 | IN EFI_STRING_ID QuestionConfig\r | |
2011 | )\r | |
2012 | {\r | |
2013 | EFI_IFR_ACTION OpCode;\r | |
2014 | \r | |
2015 | ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY))) == 0);\r | |
2016 | \r | |
2017 | ZeroMem (&OpCode, sizeof (OpCode));\r | |
2018 | OpCode.Question.QuestionId = QuestionId;\r | |
2019 | OpCode.Question.Header.Prompt = Prompt;\r | |
2020 | OpCode.Question.Header.Help = Help;\r | |
2021 | OpCode.Question.Flags = QuestionFlags;\r | |
2022 | OpCode.QuestionConfig = QuestionConfig;\r | |
2023 | \r | |
2024 | return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_ACTION_OP, sizeof (OpCode));\r | |
2025 | }\r | |
2026 | \r | |
2027 | /**\r | |
2028 | Create EFI_IFR_SUBTITLE_OP opcode.\r | |
2029 | \r | |
2030 | If OpCodeHandle is NULL, then ASSERT().\r | |
2031 | If any reserved bits are set in Flags, then ASSERT().\r | |
2032 | If Scope > 1, then ASSERT().\r | |
2033 | \r | |
2034 | @param[in] OpCodeHandle Handle to the buffer of opcodes.\r | |
2035 | @param[in] Prompt String ID for Prompt\r | |
2036 | @param[in] Help String ID for Help\r | |
2037 | @param[in] Flags Subtitle opcode flags\r | |
2038 | @param[in] Scope 1 if this opcpde is the beginning of a new scope.\r | |
2039 | 0 if this opcode is within the current scope.\r | |
2040 | \r | |
2041 | @retval NULL There is not enough space left in Buffer to add the opcode.\r | |
2042 | @retval Other A pointer to the created opcode.\r | |
2043 | \r | |
2044 | **/\r | |
2045 | UINT8 *\r | |
2046 | EFIAPI\r | |
2047 | HiiCreateSubTitleOpCode (\r | |
2048 | IN VOID *OpCodeHandle,\r | |
2049 | IN EFI_STRING_ID Prompt,\r | |
2050 | IN EFI_STRING_ID Help,\r | |
2051 | IN UINT8 Flags,\r | |
2052 | IN UINT8 Scope\r | |
2053 | )\r | |
2054 | {\r | |
2055 | EFI_IFR_SUBTITLE OpCode;\r | |
2056 | \r | |
2057 | ASSERT (Scope <= 1);\r | |
2058 | ASSERT ((Flags & (~(EFI_IFR_FLAGS_HORIZONTAL))) == 0);\r | |
2059 | \r | |
2060 | ZeroMem (&OpCode, sizeof (OpCode));\r | |
2061 | OpCode.Statement.Prompt = Prompt;\r | |
2062 | OpCode.Statement.Help = Help;\r | |
2063 | OpCode.Flags = Flags;\r | |
2064 | \r | |
2065 | return InternalHiiCreateOpCodeExtended (\r | |
2066 | OpCodeHandle, \r | |
2067 | &OpCode,\r | |
2068 | EFI_IFR_SUBTITLE_OP, \r | |
2069 | sizeof (OpCode), \r | |
2070 | 0, \r | |
2071 | Scope\r | |
2072 | );\r | |
2073 | }\r | |
2074 | \r | |
2075 | /**\r | |
2076 | Create EFI_IFR_REF_OP opcode.\r | |
2077 | \r | |
2078 | If OpCodeHandle is NULL, then ASSERT().\r | |
2079 | If any reserved bits are set in QuestionFlags, then ASSERT().\r | |
2080 | \r | |
2081 | @param[in] OpCodeHandle Handle to the buffer of opcodes.\r | |
2082 | @param[in] FormId Destination Form ID\r | |
2083 | @param[in] Prompt String ID for Prompt\r | |
2084 | @param[in] Help String ID for Help\r | |
2085 | @param[in] QuestionFlags Flags in Question Header\r | |
2086 | @param[in] QuestionId Question ID\r | |
2087 | \r | |
2088 | @retval NULL There is not enough space left in Buffer to add the opcode.\r | |
2089 | @retval Other A pointer to the created opcode.\r | |
2090 | \r | |
2091 | **/\r | |
2092 | UINT8 *\r | |
2093 | EFIAPI\r | |
2094 | HiiCreateGotoOpCode (\r | |
2095 | IN VOID *OpCodeHandle,\r | |
2096 | IN EFI_FORM_ID FormId,\r | |
2097 | IN EFI_STRING_ID Prompt,\r | |
2098 | IN EFI_STRING_ID Help,\r | |
2099 | IN UINT8 QuestionFlags,\r | |
2100 | IN EFI_QUESTION_ID QuestionId\r | |
2101 | )\r | |
2102 | {\r | |
2103 | EFI_IFR_REF OpCode;\r | |
2104 | \r | |
2105 | ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY))) == 0);\r | |
2106 | \r | |
2107 | ZeroMem (&OpCode, sizeof (OpCode));\r | |
2108 | OpCode.Question.Header.Prompt = Prompt;\r | |
2109 | OpCode.Question.Header.Help = Help;\r | |
2110 | OpCode.Question.QuestionId = QuestionId;\r | |
2111 | OpCode.Question.Flags = QuestionFlags;\r | |
2112 | OpCode.FormId = FormId;\r | |
2113 | \r | |
2114 | return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_REF_OP, sizeof (OpCode));\r | |
2115 | }\r | |
2116 | \r | |
2117 | /**\r | |
2118 | Create EFI_IFR_CHECKBOX_OP opcode.\r | |
2119 | \r | |
2120 | If OpCodeHandle is NULL, then ASSERT().\r | |
2121 | If any reserved bits are set in QuestionFlags, then ASSERT().\r | |
2122 | If any reserved bits are set in CheckBoxFlags, then ASSERT().\r | |
2123 | \r | |
2124 | @param[in] OpCodeHandle Handle to the buffer of opcodes.\r | |
2125 | @param[in] QuestionId Question ID\r | |
2126 | @param[in] VarStoreId Storage ID\r | |
2127 | @param[in] VarOffset Offset in Storage\r | |
2128 | @param[in] Prompt String ID for Prompt\r | |
2129 | @param[in] Help String ID for Help\r | |
2130 | @param[in] QuestionFlags Flags in Question Header\r | |
2131 | @param[in] CheckBoxFlags Flags for checkbox opcode\r | |
2132 | @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This\r | |
2133 | is an optional parameter that may be NULL.\r | |
2134 | \r | |
2135 | @retval NULL There is not enough space left in Buffer to add the opcode.\r | |
2136 | @retval Other A pointer to the created opcode.\r | |
2137 | \r | |
2138 | **/\r | |
2139 | UINT8 *\r | |
2140 | EFIAPI\r | |
2141 | HiiCreateCheckBoxOpCode (\r | |
2142 | IN VOID *OpCodeHandle,\r | |
2143 | IN EFI_QUESTION_ID QuestionId,\r | |
2144 | IN EFI_VARSTORE_ID VarStoreId,\r | |
2145 | IN UINT16 VarOffset,\r | |
2146 | IN EFI_STRING_ID Prompt,\r | |
2147 | IN EFI_STRING_ID Help,\r | |
2148 | IN UINT8 QuestionFlags,\r | |
2149 | IN UINT8 CheckBoxFlags,\r | |
2150 | IN VOID *DefaultsOpCodeHandle OPTIONAL\r | |
2151 | )\r | |
2152 | {\r | |
2153 | EFI_IFR_CHECKBOX OpCode;\r | |
2154 | UINTN Position;\r | |
2155 | \r | |
2156 | ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY))) == 0);\r | |
2157 | \r | |
2158 | ZeroMem (&OpCode, sizeof (OpCode));\r | |
2159 | OpCode.Question.QuestionId = QuestionId;\r | |
2160 | OpCode.Question.VarStoreId = VarStoreId;\r | |
2161 | OpCode.Question.VarStoreInfo.VarOffset = VarOffset;\r | |
2162 | OpCode.Question.Header.Prompt = Prompt;\r | |
2163 | OpCode.Question.Header.Help = Help;\r | |
2164 | OpCode.Question.Flags = QuestionFlags;\r | |
2165 | OpCode.Flags = CheckBoxFlags;\r | |
2166 | \r | |
2167 | if (DefaultsOpCodeHandle == NULL) {\r | |
2168 | return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_CHECKBOX_OP, sizeof (OpCode));\r | |
2169 | }\r | |
2170 | \r | |
2171 | Position = InternalHiiOpCodeHandlePosition (OpCodeHandle);\r | |
2172 | InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_CHECKBOX_OP, sizeof (OpCode), 0, 1);\r | |
2173 | InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle);\r | |
2174 | HiiCreateEndOpCode (OpCodeHandle);\r | |
2175 | return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position;\r | |
2176 | }\r | |
2177 | \r | |
2178 | /**\r | |
2179 | Create EFI_IFR_NUMERIC_OP opcode.\r | |
2180 | \r | |
2181 | If OpCodeHandle is NULL, then ASSERT().\r | |
2182 | If any reserved bits are set in QuestionFlags, then ASSERT().\r | |
2183 | If any reserved bits are set in NumericFlags, then ASSERT().\r | |
2184 | \r | |
2185 | @param[in] OpCodeHandle Handle to the buffer of opcodes.\r | |
2186 | @param[in] QuestionId Question ID\r | |
2187 | @param[in] VarStoreId Storage ID\r | |
2188 | @param[in] VarOffset Offset in Storage\r | |
2189 | @param[in] Prompt String ID for Prompt\r | |
2190 | @param[in] Help String ID for Help\r | |
2191 | @param[in] QuestionFlags Flags in Question Header\r | |
2192 | @param[in] NumericFlags Flags for numeric opcode\r | |
2193 | @param[in] Minimum Numeric minimum value\r | |
2194 | @param[in] Maximum Numeric maximum value\r | |
2195 | @param[in] Step Numeric step for edit\r | |
2196 | @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This\r | |
2197 | is an optional parameter that may be NULL.\r | |
2198 | \r | |
2199 | @retval NULL There is not enough space left in Buffer to add the opcode.\r | |
2200 | @retval Other A pointer to the created opcode.\r | |
2201 | \r | |
2202 | **/\r | |
2203 | UINT8 *\r | |
2204 | EFIAPI\r | |
2205 | HiiCreateNumericOpCode (\r | |
2206 | IN VOID *OpCodeHandle,\r | |
2207 | IN EFI_QUESTION_ID QuestionId,\r | |
2208 | IN EFI_VARSTORE_ID VarStoreId,\r | |
2209 | IN UINT16 VarOffset,\r | |
2210 | IN EFI_STRING_ID Prompt,\r | |
2211 | IN EFI_STRING_ID Help,\r | |
2212 | IN UINT8 QuestionFlags,\r | |
2213 | IN UINT8 NumericFlags,\r | |
2214 | IN UINT64 Minimum,\r | |
2215 | IN UINT64 Maximum,\r | |
2216 | IN UINT64 Step,\r | |
2217 | IN VOID *DefaultsOpCodeHandle OPTIONAL\r | |
2218 | )\r | |
2219 | {\r | |
2220 | EFI_IFR_NUMERIC OpCode;\r | |
2221 | UINTN Position;\r | |
2222 | \r | |
2223 | ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY))) == 0);\r | |
2224 | \r | |
2225 | ZeroMem (&OpCode, sizeof (OpCode));\r | |
2226 | OpCode.Question.QuestionId = QuestionId;\r | |
2227 | OpCode.Question.VarStoreId = VarStoreId;\r | |
2228 | OpCode.Question.VarStoreInfo.VarOffset = VarOffset;\r | |
2229 | OpCode.Question.Header.Prompt = Prompt;\r | |
2230 | OpCode.Question.Header.Help = Help;\r | |
2231 | OpCode.Question.Flags = QuestionFlags;\r | |
2232 | OpCode.Flags = NumericFlags;\r | |
2233 | \r | |
2234 | switch (NumericFlags & EFI_IFR_NUMERIC_SIZE) {\r | |
2235 | case EFI_IFR_NUMERIC_SIZE_1:\r | |
2236 | OpCode.data.u8.MinValue = (UINT8)Minimum;\r | |
2237 | OpCode.data.u8.MaxValue = (UINT8)Maximum;\r | |
2238 | OpCode.data.u8.Step = (UINT8)Step;\r | |
2239 | break;\r | |
2240 | \r | |
2241 | case EFI_IFR_NUMERIC_SIZE_2:\r | |
2242 | OpCode.data.u16.MinValue = (UINT16)Minimum;\r | |
2243 | OpCode.data.u16.MaxValue = (UINT16)Maximum;\r | |
2244 | OpCode.data.u16.Step = (UINT16)Step;\r | |
2245 | break;\r | |
2246 | \r | |
2247 | case EFI_IFR_NUMERIC_SIZE_4:\r | |
2248 | OpCode.data.u32.MinValue = (UINT32)Minimum;\r | |
2249 | OpCode.data.u32.MaxValue = (UINT32)Maximum;\r | |
2250 | OpCode.data.u32.Step = (UINT32)Step;\r | |
2251 | break;\r | |
2252 | \r | |
2253 | case EFI_IFR_NUMERIC_SIZE_8:\r | |
2254 | OpCode.data.u64.MinValue = Minimum;\r | |
2255 | OpCode.data.u64.MaxValue = Maximum;\r | |
2256 | OpCode.data.u64.Step = Step;\r | |
2257 | break;\r | |
2258 | }\r | |
2259 | \r | |
2260 | if (DefaultsOpCodeHandle == NULL) {\r | |
2261 | return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_NUMERIC_OP, sizeof (OpCode));\r | |
2262 | }\r | |
2263 | \r | |
2264 | Position = InternalHiiOpCodeHandlePosition (OpCodeHandle);\r | |
2265 | InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_NUMERIC_OP, sizeof (OpCode), 0, 1);\r | |
2266 | InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle);\r | |
2267 | HiiCreateEndOpCode (OpCodeHandle);\r | |
2268 | return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position;\r | |
2269 | }\r | |
2270 | \r | |
2271 | /**\r | |
2272 | Create EFI_IFR_STRING_OP opcode.\r | |
2273 | \r | |
2274 | If OpCodeHandle is NULL, then ASSERT().\r | |
2275 | If any reserved bits are set in QuestionFlags, then ASSERT().\r | |
2276 | If any reserved bits are set in StringFlags, then ASSERT().\r | |
2277 | \r | |
2278 | @param[in] OpCodeHandle Handle to the buffer of opcodes.\r | |
2279 | @param[in] QuestionId Question ID\r | |
2280 | @param[in] VarStoreId Storage ID\r | |
2281 | @param[in] VarOffset Offset in Storage\r | |
2282 | @param[in] Prompt String ID for Prompt\r | |
2283 | @param[in] Help String ID for Help\r | |
2284 | @param[in] QuestionFlags Flags in Question Header\r | |
2285 | @param[in] StringFlags Flags for string opcode\r | |
2286 | @param[in] MinSize String minimum length\r | |
2287 | @param[in] MaxSize String maximum length\r | |
2288 | @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This\r | |
2289 | is an optional parameter that may be NULL.\r | |
2290 | \r | |
2291 | @retval NULL There is not enough space left in Buffer to add the opcode.\r | |
2292 | @retval Other A pointer to the created opcode.\r | |
2293 | \r | |
2294 | **/\r | |
2295 | UINT8 *\r | |
2296 | EFIAPI\r | |
2297 | HiiCreateStringOpCode (\r | |
2298 | IN VOID *OpCodeHandle,\r | |
2299 | IN EFI_QUESTION_ID QuestionId,\r | |
2300 | IN EFI_VARSTORE_ID VarStoreId,\r | |
2301 | IN UINT16 VarOffset,\r | |
2302 | IN EFI_STRING_ID Prompt,\r | |
2303 | IN EFI_STRING_ID Help,\r | |
2304 | IN UINT8 QuestionFlags,\r | |
2305 | IN UINT8 StringFlags,\r | |
2306 | IN UINT8 MinSize,\r | |
2307 | IN UINT8 MaxSize,\r | |
2308 | IN VOID *DefaultsOpCodeHandle OPTIONAL\r | |
2309 | )\r | |
2310 | {\r | |
2311 | EFI_IFR_STRING OpCode;\r | |
2312 | UINTN Position;\r | |
2313 | \r | |
2314 | ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY))) == 0);\r | |
2315 | \r | |
2316 | ZeroMem (&OpCode, sizeof (OpCode));\r | |
2317 | OpCode.Question.Header.Prompt = Prompt;\r | |
2318 | OpCode.Question.Header.Help = Help;\r | |
2319 | OpCode.Question.QuestionId = QuestionId;\r | |
2320 | OpCode.Question.VarStoreId = VarStoreId;\r | |
2321 | OpCode.Question.VarStoreInfo.VarOffset = VarOffset;\r | |
2322 | OpCode.Question.Flags = QuestionFlags;\r | |
2323 | OpCode.MinSize = MinSize;\r | |
2324 | OpCode.MaxSize = MaxSize;\r | |
2325 | OpCode.Flags = (UINT8) (StringFlags & EFI_IFR_STRING_MULTI_LINE);\r | |
2326 | \r | |
2327 | if (DefaultsOpCodeHandle == NULL) {\r | |
2328 | return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_STRING_OP, sizeof (OpCode));\r | |
2329 | }\r | |
2330 | \r | |
2331 | Position = InternalHiiOpCodeHandlePosition (OpCodeHandle);\r | |
2332 | InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_STRING_OP, sizeof (OpCode), 0, 1);\r | |
2333 | InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle);\r | |
2334 | HiiCreateEndOpCode (OpCodeHandle);\r | |
2335 | return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position;\r | |
2336 | }\r | |
2337 | \r | |
2338 | /**\r | |
2339 | Create EFI_IFR_ONE_OF_OP opcode.\r | |
2340 | \r | |
2341 | If OpCodeHandle is NULL, then ASSERT().\r | |
2342 | If any reserved bits are set in QuestionFlags, then ASSERT().\r | |
2343 | If any reserved bits are set in OneOfFlags, then ASSERT().\r | |
2344 | \r | |
2345 | @param[in] OpCodeHandle Handle to the buffer of opcodes.\r | |
2346 | @param[in] QuestionId Question ID\r | |
2347 | @param[in] VarStoreId Storage ID\r | |
2348 | @param[in] VarOffset Offset in Storage\r | |
2349 | @param[in] Prompt String ID for Prompt\r | |
2350 | @param[in] Help String ID for Help\r | |
2351 | @param[in] QuestionFlags Flags in Question Header\r | |
2352 | @param[in] OneOfFlags Flags for oneof opcode\r | |
2353 | @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.\r | |
2354 | @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This\r | |
2355 | is an optional parameter that may be NULL.\r | |
2356 | \r | |
2357 | @retval NULL There is not enough space left in Buffer to add the opcode.\r | |
2358 | @retval Other A pointer to the created opcode.\r | |
2359 | \r | |
2360 | **/\r | |
2361 | UINT8 *\r | |
2362 | EFIAPI\r | |
2363 | HiiCreateOneOfOpCode (\r | |
2364 | IN VOID *OpCodeHandle,\r | |
2365 | IN EFI_QUESTION_ID QuestionId,\r | |
2366 | IN EFI_VARSTORE_ID VarStoreId,\r | |
2367 | IN UINT16 VarOffset,\r | |
2368 | IN EFI_STRING_ID Prompt,\r | |
2369 | IN EFI_STRING_ID Help,\r | |
2370 | IN UINT8 QuestionFlags,\r | |
2371 | IN UINT8 OneOfFlags,\r | |
2372 | IN VOID *OptionsOpCodeHandle,\r | |
2373 | IN VOID *DefaultsOpCodeHandle OPTIONAL\r | |
2374 | )\r | |
2375 | {\r | |
2376 | EFI_IFR_ONE_OF OpCode;\r | |
2377 | UINTN Position;\r | |
2378 | \r | |
2379 | ASSERT (OptionsOpCodeHandle != NULL);\r | |
2380 | ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY))) == 0);\r | |
2381 | \r | |
2382 | ZeroMem (&OpCode, sizeof (OpCode));\r | |
2383 | OpCode.Question.Header.Prompt = Prompt;\r | |
2384 | OpCode.Question.Header.Help = Help;\r | |
2385 | OpCode.Question.QuestionId = QuestionId;\r | |
2386 | OpCode.Question.VarStoreId = VarStoreId;\r | |
2387 | OpCode.Question.VarStoreInfo.VarOffset = VarOffset;\r | |
2388 | OpCode.Question.Flags = QuestionFlags;\r | |
2389 | OpCode.Flags = OneOfFlags;\r | |
2390 | \r | |
2391 | Position = InternalHiiOpCodeHandlePosition (OpCodeHandle);\r | |
2392 | InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_ONE_OF_OP, sizeof (OpCode), 0, 1);\r | |
2393 | InternalHiiAppendOpCodes (OpCodeHandle, OptionsOpCodeHandle);\r | |
2394 | if (DefaultsOpCodeHandle != NULL) {\r | |
2395 | InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle);\r | |
2396 | }\r | |
2397 | HiiCreateEndOpCode (OpCodeHandle);\r | |
2398 | return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position;\r | |
2399 | }\r | |
2400 | \r | |
2401 | /**\r | |
2402 | Create EFI_IFR_ORDERED_LIST_OP opcode.\r | |
2403 | \r | |
2404 | If OpCodeHandle is NULL, then ASSERT().\r | |
2405 | If any reserved bits are set in QuestionFlags, then ASSERT().\r | |
2406 | If any reserved bits are set in OrderedListFlags, then ASSERT().\r | |
2407 | \r | |
2408 | @param[in] OpCodeHandle Handle to the buffer of opcodes.\r | |
2409 | @param[in] QuestionId Question ID\r | |
2410 | @param[in] VarStoreId Storage ID\r | |
2411 | @param[in] VarOffset Offset in Storage\r | |
2412 | @param[in] Prompt String ID for Prompt\r | |
2413 | @param[in] Help String ID for Help\r | |
2414 | @param[in] QuestionFlags Flags in Question Header\r | |
2415 | @param[in] OrderedListFlags Flags for ordered list opcode\r | |
2416 | @param[in] DataType Type for option value\r | |
2417 | @param[in] MaxContainers Maximum count for options in this ordered list\r | |
2418 | @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.\r | |
2419 | @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This\r | |
2420 | is an optional parameter that may be NULL.\r | |
2421 | \r | |
2422 | @retval NULL There is not enough space left in Buffer to add the opcode.\r | |
2423 | @retval Other A pointer to the created opcode.\r | |
2424 | \r | |
2425 | **/\r | |
2426 | UINT8 *\r | |
2427 | EFIAPI\r | |
2428 | HiiCreateOrderedListOpCode (\r | |
2429 | IN VOID *OpCodeHandle,\r | |
2430 | IN EFI_QUESTION_ID QuestionId,\r | |
2431 | IN EFI_VARSTORE_ID VarStoreId,\r | |
2432 | IN UINT16 VarOffset,\r | |
2433 | IN EFI_STRING_ID Prompt,\r | |
2434 | IN EFI_STRING_ID Help,\r | |
2435 | IN UINT8 QuestionFlags,\r | |
2436 | IN UINT8 OrderedListFlags,\r | |
2437 | IN UINT8 DataType,\r | |
2438 | IN UINT8 MaxContainers,\r | |
2439 | IN VOID *OptionsOpCodeHandle,\r | |
2440 | IN VOID *DefaultsOpCodeHandle OPTIONAL\r | |
2441 | )\r | |
2442 | {\r | |
2443 | EFI_IFR_ORDERED_LIST OpCode;\r | |
2444 | UINTN Position;\r | |
2445 | \r | |
2446 | ASSERT (OptionsOpCodeHandle != NULL);\r | |
2447 | ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY))) == 0);\r | |
2448 | \r | |
2449 | ZeroMem (&OpCode, sizeof (OpCode));\r | |
2450 | OpCode.Question.Header.Prompt = Prompt;\r | |
2451 | OpCode.Question.Header.Help = Help;\r | |
2452 | OpCode.Question.QuestionId = QuestionId;\r | |
2453 | OpCode.Question.VarStoreId = VarStoreId;\r | |
2454 | OpCode.Question.VarStoreInfo.VarOffset = VarOffset;\r | |
2455 | OpCode.Question.Flags = QuestionFlags;\r | |
2456 | OpCode.MaxContainers = MaxContainers;\r | |
2457 | OpCode.Flags = OrderedListFlags;\r | |
2458 | \r | |
2459 | Position = InternalHiiOpCodeHandlePosition (OpCodeHandle);\r | |
2460 | InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_ORDERED_LIST_OP, sizeof (OpCode), 0, 1);\r | |
2461 | InternalHiiAppendOpCodes (OpCodeHandle, OptionsOpCodeHandle);\r | |
2462 | if (DefaultsOpCodeHandle != NULL) {\r | |
2463 | InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle);\r | |
2464 | }\r | |
2465 | HiiCreateEndOpCode (OpCodeHandle);\r | |
2466 | return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position;\r | |
2467 | }\r | |
2468 | \r | |
2469 | /**\r | |
2470 | This is the internal worker function to update the data in\r | |
2471 | a form specified by FormSetGuid, FormId and Label.\r | |
2472 | \r | |
2473 | @param FormSetGuid The optional Formset GUID.\r | |
2474 | @param FormId The Form ID.\r | |
2475 | @param Package The package header.\r | |
2476 | \r | |
2477 | @param TempPacakge The resultant package.\r | |
2478 | \r | |
2479 | @retval EFI_SUCCESS The function completes successfully.\r | |
2480 | \r | |
2481 | **/\r | |
2482 | EFI_STATUS\r | |
2483 | EFIAPI\r | |
2484 | InternalHiiUpdateFormPackageData (\r | |
2485 | IN EFI_GUID *FormSetGuid, OPTIONAL\r | |
2486 | IN EFI_FORM_ID FormId,\r | |
2487 | IN EFI_HII_PACKAGE_HEADER *Package,\r | |
2488 | IN HII_LIB_OPCODE_BUFFER *OpCodeBufferStart,\r | |
2489 | IN HII_LIB_OPCODE_BUFFER *OpCodeBufferEnd, OPTIONAL\r | |
2490 | OUT EFI_HII_PACKAGE_HEADER *TempPackage\r | |
2491 | )\r | |
2492 | {\r | |
2493 | UINTN AddSize;\r | |
2494 | UINT8 *BufferPos;\r | |
2495 | EFI_HII_PACKAGE_HEADER PackageHeader;\r | |
2496 | UINTN Offset;\r | |
2497 | EFI_IFR_OP_HEADER *IfrOpHdr;\r | |
2498 | EFI_IFR_OP_HEADER *UpdateIfrOpHdr;\r | |
2499 | BOOLEAN GetFormSet;\r | |
2500 | BOOLEAN GetForm;\r | |
2501 | BOOLEAN Updated;\r | |
2502 | EFI_IFR_OP_HEADER *AddOpCode;\r | |
2503 | UINT32 UpdatePackageLength;\r | |
2504 | \r | |
2505 | CopyMem (TempPackage, Package, sizeof (EFI_HII_PACKAGE_HEADER));\r | |
2506 | UpdatePackageLength = sizeof (EFI_HII_PACKAGE_HEADER);\r | |
2507 | BufferPos = (UINT8 *) (TempPackage + 1);\r | |
2508 | \r | |
2509 | CopyMem (&PackageHeader, Package, sizeof (EFI_HII_PACKAGE_HEADER));\r | |
2510 | IfrOpHdr = (EFI_IFR_OP_HEADER *)((UINT8 *) Package + sizeof (EFI_HII_PACKAGE_HEADER));\r | |
2511 | Offset = sizeof (EFI_HII_PACKAGE_HEADER);\r | |
2512 | GetFormSet = (BOOLEAN) ((FormSetGuid == NULL) ? TRUE : FALSE);\r | |
2513 | GetForm = FALSE;\r | |
2514 | Updated = FALSE;\r | |
2515 | \r | |
2516 | while (Offset < PackageHeader.Length) {\r | |
2517 | CopyMem (BufferPos, IfrOpHdr, IfrOpHdr->Length);\r | |
2518 | BufferPos += IfrOpHdr->Length;\r | |
2519 | UpdatePackageLength += IfrOpHdr->Length;\r | |
2520 | \r | |
2521 | //\r | |
2522 | // Find the matched FormSet and Form\r | |
2523 | //\r | |
2524 | if ((IfrOpHdr->OpCode == EFI_IFR_FORM_SET_OP) && (FormSetGuid != NULL)) {\r | |
2525 | if (CompareGuid((GUID *)(VOID *)&((EFI_IFR_FORM_SET *) IfrOpHdr)->Guid, FormSetGuid)) {\r | |
2526 | GetFormSet = TRUE;\r | |
2527 | } else {\r | |
2528 | GetFormSet = FALSE;\r | |
2529 | }\r | |
2530 | } else if (IfrOpHdr->OpCode == EFI_IFR_FORM_OP) {\r | |
2531 | if (CompareMem (&((EFI_IFR_FORM *) IfrOpHdr)->FormId, &FormId, sizeof (EFI_FORM_ID)) == 0) {\r | |
2532 | GetForm = TRUE;\r | |
2533 | } else {\r | |
2534 | GetForm = FALSE;\r | |
2535 | }\r | |
2536 | }\r | |
2537 | \r | |
2538 | //\r | |
2539 | // The matched Form is found, and Update data in this form\r | |
2540 | //\r | |
2541 | if (GetFormSet && GetForm && !Updated) {\r | |
2542 | UpdateIfrOpHdr = (EFI_IFR_OP_HEADER *) OpCodeBufferStart->Buffer;\r | |
2543 | if ((UpdateIfrOpHdr->Length == IfrOpHdr->Length) && \\r | |
2544 | (CompareMem (IfrOpHdr, UpdateIfrOpHdr, UpdateIfrOpHdr->Length) == 0)) {\r | |
2545 | //\r | |
2546 | // Remove the original data when End OpCode buffer exist.\r | |
2547 | //\r | |
2548 | if (OpCodeBufferEnd != NULL) {\r | |
2549 | Offset += IfrOpHdr->Length;\r | |
2550 | IfrOpHdr = (EFI_IFR_OP_HEADER *) ((UINT8 *) (IfrOpHdr) + IfrOpHdr->Length);\r | |
2551 | UpdateIfrOpHdr = (EFI_IFR_OP_HEADER *) OpCodeBufferEnd->Buffer;\r | |
2552 | while (Offset < PackageHeader.Length) {\r | |
2553 | //\r | |
2554 | // Search the matched end opcode\r | |
2555 | //\r | |
2556 | if ((UpdateIfrOpHdr->Length == IfrOpHdr->Length) && \\r | |
2557 | (CompareMem (IfrOpHdr, UpdateIfrOpHdr, UpdateIfrOpHdr->Length) == 0)) {\r | |
2558 | break;\r | |
2559 | }\r | |
2560 | //\r | |
2561 | // Go to the next Op-Code\r | |
2562 | //\r | |
2563 | Offset += IfrOpHdr->Length;\r | |
2564 | IfrOpHdr = (EFI_IFR_OP_HEADER *) ((UINT8 *) (IfrOpHdr) + IfrOpHdr->Length);\r | |
2565 | }\r | |
2566 | \r | |
2567 | if (Offset >= PackageHeader.Length) {\r | |
2568 | //\r | |
2569 | // The end opcode is not found.\r | |
2570 | //\r | |
2571 | return EFI_NOT_FOUND;\r | |
2572 | }\r | |
2573 | }\r | |
2574 | //\r | |
2575 | // Insert the updated data\r | |
2576 | //\r | |
2577 | UpdateIfrOpHdr = (EFI_IFR_OP_HEADER *) OpCodeBufferStart->Buffer;\r | |
2578 | AddOpCode = (EFI_IFR_OP_HEADER *) (OpCodeBufferStart->Buffer + UpdateIfrOpHdr->Length);\r | |
2579 | AddSize = UpdateIfrOpHdr->Length;\r | |
2580 | while (AddSize < OpCodeBufferStart->Position) {\r | |
2581 | CopyMem (BufferPos, AddOpCode, AddOpCode->Length);\r | |
2582 | BufferPos += AddOpCode->Length;\r | |
2583 | UpdatePackageLength += AddOpCode->Length;\r | |
2584 | \r | |
2585 | AddOpCode = (EFI_IFR_OP_HEADER *) ((UINT8 *) (AddOpCode) + AddOpCode->Length);\r | |
2586 | AddSize += AddOpCode->Length; \r | |
2587 | }\r | |
2588 | \r | |
2589 | if (OpCodeBufferEnd != NULL) {\r | |
2590 | //\r | |
2591 | // Add the end opcode\r | |
2592 | //\r | |
2593 | CopyMem (BufferPos, IfrOpHdr, IfrOpHdr->Length);\r | |
2594 | BufferPos += IfrOpHdr->Length;\r | |
2595 | UpdatePackageLength += IfrOpHdr->Length;\r | |
2596 | }\r | |
2597 | //\r | |
2598 | // Set update flag\r | |
2599 | //\r | |
2600 | Updated = TRUE;\r | |
2601 | }\r | |
2602 | }\r | |
2603 | \r | |
2604 | //\r | |
2605 | // Go to the next Op-Code\r | |
2606 | //\r | |
2607 | Offset += IfrOpHdr->Length;\r | |
2608 | IfrOpHdr = (EFI_IFR_OP_HEADER *) ((CHAR8 *) (IfrOpHdr) + IfrOpHdr->Length);\r | |
2609 | }\r | |
2610 | \r | |
2611 | if (!Updated) {\r | |
2612 | //\r | |
2613 | // The updated opcode buffer is not found.\r | |
2614 | //\r | |
2615 | return EFI_NOT_FOUND;\r | |
2616 | }\r | |
2617 | //\r | |
2618 | // Update the package length.\r | |
2619 | //\r | |
2620 | PackageHeader.Length = UpdatePackageLength;\r | |
2621 | CopyMem (TempPackage, &PackageHeader, sizeof (EFI_HII_PACKAGE_HEADER));\r | |
2622 | \r | |
2623 | return EFI_SUCCESS;\r | |
2624 | }\r | |
2625 | \r | |
2626 | /**\r | |
2627 | This function updates a form that has previously been registered with the HII \r | |
2628 | Database. This function will perform at most one update operation.\r | |
2629 | \r | |
2630 | The form to update is specified by Handle, FormSetGuid, and FormId. Binary \r | |
2631 | comparisons of IFR opcodes are performed from the beginning of the form being \r | |
2632 | updated until an IFR opcode is found that exactly matches the first IFR opcode \r | |
2633 | specifed by StartOpCodeHandle. The following rules are used to determine if\r | |
2634 | an insert, replace, or delete operation is performed.\r | |
2635 | \r | |
2636 | 1) If no matches are found, then NULL is returned. \r | |
2637 | 2) If a match is found, and EndOpCodeHandle is NULL, then all of the IFR opcodes\r | |
2638 | from StartOpcodeHandle except the first opcode are inserted immediately after \r | |
2639 | the matching IFR opcode in the form beng updated.\r | |
2640 | 3) If a match is found, and EndOpCodeHandle is not NULL, then a search is made \r | |
2641 | from the matching IFR opcode until an IFR opcode exatly matches the first \r | |
2642 | IFR opcode specified by EndOpCodeHandle. If no match is found for the first\r | |
2643 | IFR opcode specified by EndOpCodeHandle, then NULL is returned. If a match\r | |
2644 | is found, then all of the IFR opcodes between the start match and the end \r | |
2645 | match are deleted from the form being updated and all of the IFR opcodes\r | |
2646 | from StartOpcodeHandle except the first opcode are inserted immediately after \r | |
2647 | the matching start IFR opcode. If StartOpCcodeHandle only contains one\r | |
2648 | IFR instruction, then the result of ths operation will delete all of the IFR\r | |
2649 | opcodes between the start end matches.\r | |
2650 | \r | |
2651 | If HiiHandle is NULL, then ASSERT().\r | |
2652 | If StartOpCodeHandle is NULL, then ASSERT().\r | |
2653 | \r | |
2654 | @param[in] HiiHandle The HII Handle of the form to update.\r | |
2655 | @param[in] FormSetGuid The Formset GUID of the form to update. This\r | |
2656 | is an optional parameter that may be NULL.\r | |
2657 | If it is NULL, all FormSet will be updated.\r | |
2658 | @param[in] FormId The ID of the form to update.\r | |
2659 | @param[in] StartOpCodeHandle An OpCode Handle that contains the set of IFR \r | |
2660 | opcodes to be inserted or replaced in the form.\r | |
2661 | The first IFR instruction in StartOpCodeHandle \r | |
2662 | is used to find matching IFR opcode in the \r | |
2663 | form. \r | |
2664 | @param[in] EndOpCodeHandle An OpCcode Handle that contains the IFR opcode\r | |
2665 | that marks the end of a replace operation in\r | |
2666 | the form. This is an optional parameter that\r | |
2667 | may be NULL. If it is NULL, then an the IFR\r | |
2668 | opcodes specified by StartOpCodeHandle are \r | |
2669 | inserted into the form.\r | |
2670 | \r | |
2671 | @retval EFI_OUT_OF_RESOURCES No enough memory resource is allocated.\r | |
2672 | @retval EFI_NOT_FOUND The following cases will return EFI_NOT_FOUND.\r | |
2673 | 1) The form specified by HiiHandle, FormSetGuid, \r | |
2674 | and FormId could not be found in the HII Database.\r | |
2675 | 2) No IFR opcodes in the target form match the first\r | |
2676 | IFR opcode in StartOpCodeHandle.\r | |
2677 | 3) EndOpCOde is not NULL, and no IFR opcodes in the \r | |
2678 | target form following a matching start opcode match \r | |
2679 | the first IFR opcode in EndOpCodeHandle.\r | |
2680 | @retval EFI_SUCCESS The matched form is updated by StartOpcode.\r | |
2681 | \r | |
2682 | **/\r | |
2683 | EFI_STATUS\r | |
2684 | EFIAPI\r | |
2685 | HiiUpdateForm (\r | |
2686 | IN EFI_HII_HANDLE HiiHandle, \r | |
2687 | IN EFI_GUID *FormSetGuid, OPTIONAL\r | |
2688 | IN EFI_FORM_ID FormId,\r | |
2689 | IN VOID *StartOpcodeHandle,\r | |
2690 | IN VOID *EndOpcodeHandle OPTIONAL\r | |
2691 | )\r | |
2692 | {\r | |
2693 | EFI_STATUS Status;\r | |
2694 | EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;\r | |
2695 | UINT32 PackageListLength; \r | |
2696 | UINT32 Offset;\r | |
2697 | EFI_HII_PACKAGE_LIST_HEADER *UpdatePackageList;\r | |
2698 | UINTN BufferSize;\r | |
2699 | UINT8 *UpdateBufferPos;\r | |
2700 | EFI_HII_PACKAGE_HEADER *Package;\r | |
2701 | EFI_HII_PACKAGE_HEADER *TempPacakge;\r | |
2702 | EFI_HII_PACKAGE_HEADER PackageHeader;\r | |
2703 | BOOLEAN Updated;\r | |
2704 | HII_LIB_OPCODE_BUFFER *OpCodeBufferStart;\r | |
2705 | HII_LIB_OPCODE_BUFFER *OpCodeBufferEnd;\r | |
2706 | \r | |
2707 | //\r | |
2708 | // Input update data can't be NULL.\r | |
2709 | //\r | |
2710 | ASSERT (HiiHandle != NULL);\r | |
2711 | ASSERT (StartOpcodeHandle != NULL);\r | |
2712 | UpdatePackageList = NULL;\r | |
2713 | TempPacakge = NULL;\r | |
2714 | HiiPackageList = NULL;\r | |
2715 | \r | |
2716 | //\r | |
2717 | // Restrive buffer data from Opcode Handle\r | |
2718 | //\r | |
2719 | OpCodeBufferStart = (HII_LIB_OPCODE_BUFFER *) StartOpcodeHandle;\r | |
2720 | OpCodeBufferEnd = (HII_LIB_OPCODE_BUFFER *) EndOpcodeHandle;\r | |
2721 | \r | |
2722 | //\r | |
2723 | // Get the orginal package list\r | |
2724 | //\r | |
2725 | BufferSize = 0;\r | |
2726 | HiiPackageList = NULL;\r | |
2727 | Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, HiiHandle, &BufferSize, HiiPackageList);\r | |
2728 | //\r | |
2729 | // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.\r | |
2730 | //\r | |
2731 | if (Status != EFI_BUFFER_TOO_SMALL) {\r | |
2732 | return Status;\r | |
2733 | }\r | |
2734 | \r | |
2735 | HiiPackageList = AllocatePool (BufferSize);\r | |
2736 | if (HiiPackageList == NULL) {\r | |
2737 | Status = EFI_OUT_OF_RESOURCES;\r | |
2738 | goto Finish;\r | |
2739 | }\r | |
2740 | \r | |
2741 | Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, HiiHandle, &BufferSize, HiiPackageList);\r | |
2742 | if (EFI_ERROR (Status)) {\r | |
2743 | goto Finish;\r | |
2744 | }\r | |
2745 | \r | |
2746 | //\r | |
2747 | // Calculate and allocate space for retrieval of IFR data\r | |
2748 | //\r | |
2749 | BufferSize += OpCodeBufferStart->Position;\r | |
2750 | UpdatePackageList = AllocateZeroPool (BufferSize);\r | |
2751 | if (UpdatePackageList == NULL) {\r | |
2752 | Status = EFI_OUT_OF_RESOURCES;\r | |
2753 | goto Finish;\r | |
2754 | }\r | |
2755 | \r | |
2756 | //\r | |
2757 | // Allocate temp buffer to store the temp updated package buffer\r | |
2758 | //\r | |
2759 | TempPacakge = AllocateZeroPool (BufferSize);\r | |
2760 | if (TempPacakge == NULL) {\r | |
2761 | Status = EFI_OUT_OF_RESOURCES;\r | |
2762 | goto Finish;\r | |
2763 | }\r | |
2764 | \r | |
2765 | UpdateBufferPos = (UINT8 *) UpdatePackageList;\r | |
2766 | \r | |
2767 | //\r | |
2768 | // Copy the package list header\r | |
2769 | //\r | |
2770 | CopyMem (UpdateBufferPos, HiiPackageList, sizeof (EFI_HII_PACKAGE_LIST_HEADER));\r | |
2771 | UpdateBufferPos += sizeof (EFI_HII_PACKAGE_LIST_HEADER);\r | |
2772 | \r | |
2773 | //\r | |
2774 | // Go through each package to find the matched pacakge and update one by one\r | |
2775 | //\r | |
2776 | Updated = FALSE;\r | |
2777 | Offset = sizeof (EFI_HII_PACKAGE_LIST_HEADER);\r | |
2778 | PackageListLength = ReadUnaligned32 (&HiiPackageList->PackageLength);\r | |
2779 | while (Offset < PackageListLength) {\r | |
2780 | Package = (EFI_HII_PACKAGE_HEADER *) (((UINT8 *) HiiPackageList) + Offset);\r | |
2781 | CopyMem (&PackageHeader, Package, sizeof (EFI_HII_PACKAGE_HEADER));\r | |
2782 | Offset += Package->Length;\r | |
2783 | \r | |
2784 | if (Package->Type == EFI_HII_PACKAGE_FORMS) {\r | |
2785 | //\r | |
2786 | // Check this package is the matched package.\r | |
2787 | //\r | |
2788 | Status = InternalHiiUpdateFormPackageData (FormSetGuid, FormId, Package, OpCodeBufferStart, OpCodeBufferEnd, TempPacakge);\r | |
2789 | //\r | |
2790 | // The matched package is found. Its pacakge buffer will be updated by the input new data.\r | |
2791 | //\r | |
2792 | if (!EFI_ERROR(Status)) {\r | |
2793 | //\r | |
2794 | // Set Update Flag\r | |
2795 | // \r | |
2796 | Updated = TRUE;\r | |
2797 | //\r | |
2798 | // Add updated package buffer\r | |
2799 | //\r | |
2800 | Package = TempPacakge;\r | |
2801 | }\r | |
2802 | }\r | |
2803 | \r | |
2804 | //\r | |
2805 | // Add pacakge buffer\r | |
2806 | //\r | |
2807 | CopyMem (&PackageHeader, Package, sizeof (EFI_HII_PACKAGE_HEADER));\r | |
2808 | CopyMem (UpdateBufferPos, Package, PackageHeader.Length);\r | |
2809 | UpdateBufferPos += PackageHeader.Length;\r | |
2810 | }\r | |
2811 | \r | |
2812 | if (Updated) {\r | |
2813 | //\r | |
2814 | // Update package list length\r | |
2815 | //\r | |
2816 | BufferSize = UpdateBufferPos - (UINT8 *) UpdatePackageList;\r | |
2817 | WriteUnaligned32 (&UpdatePackageList->PackageLength, (UINT32) BufferSize);\r | |
2818 | \r | |
2819 | //\r | |
2820 | // Update Pacakge to show form\r | |
2821 | //\r | |
2822 | Status = gHiiDatabase->UpdatePackageList (gHiiDatabase, HiiHandle, UpdatePackageList);\r | |
2823 | } else {\r | |
2824 | //\r | |
2825 | // Not matched form is found and updated.\r | |
2826 | //\r | |
2827 | Status = EFI_NOT_FOUND;\r | |
2828 | }\r | |
2829 | \r | |
2830 | Finish:\r | |
2831 | if (HiiPackageList != NULL) {\r | |
2832 | FreePool (HiiPackageList);\r | |
2833 | }\r | |
2834 | \r | |
2835 | if (UpdatePackageList != NULL) {\r | |
2836 | FreePool (UpdatePackageList);\r | |
2837 | }\r | |
2838 | \r | |
2839 | if (TempPacakge != NULL) {\r | |
2840 | FreePool (TempPacakge);\r | |
2841 | }\r | |
2842 | \r | |
2843 | return Status; \r | |
2844 | }\r | |
2845 | \r | |
2846 | /**\r | |
2847 | Configure the buffer accrording to ConfigBody strings in the format of\r | |
2848 | <Length:4 bytes>, <Offset: 2 bytes>, <Width:2 bytes>, <Data:n bytes>.\r | |
2849 | This ConfigBody strings is generated by UEFI VfrCompiler for the default\r | |
2850 | values in a Form Set. The name of the ConfigBody strings is VfrMyIfrNVDataDefault0000\r | |
2851 | constructed following this rule: \r | |
2852 | "Vfr" + varstore.name + "Default" + defaultstore.attributes.\r | |
2853 | Check the generated C file in Output for details.\r | |
2854 | \r | |
2855 | @param Buffer The start address of buffer.\r | |
2856 | @param BufferSize The size of buffer.\r | |
2857 | @param Number The number of the strings.\r | |
2858 | @param ... Variable argument list for default value in <AltResp> format \r | |
2859 | generated by the tool.\r | |
2860 | \r | |
2861 | @retval EFI_BUFFER_TOO_SMALL the BufferSize is too small to operate.\r | |
2862 | @retval EFI_INVALID_PARAMETER Buffer is NULL or BufferSize is 0.\r | |
2863 | @retval EFI_SUCCESS Operation successful.\r | |
2864 | \r | |
2865 | **/\r | |
2866 | EFI_STATUS\r | |
2867 | EFIAPI\r | |
3c7449e4 | 2868 | HiiIfrLibExtractDefault(\r |
7e3bcccb LG |
2869 | IN VOID *Buffer,\r |
2870 | IN UINTN *BufferSize,\r | |
2871 | UINTN Number,\r | |
2872 | ...\r | |
2873 | )\r | |
2874 | {\r | |
2875 | VA_LIST Args;\r | |
2876 | UINTN Index;\r | |
2877 | UINT32 TotalLen;\r | |
2878 | UINT8 *BufCfgArray;\r | |
2879 | UINT8 *BufferPos;\r | |
2880 | UINT16 Offset;\r | |
2881 | UINT16 Width;\r | |
2882 | UINT8 *Value;\r | |
2883 | \r | |
2884 | if ((Buffer == NULL) || (BufferSize == NULL)) {\r | |
2885 | return EFI_INVALID_PARAMETER;\r | |
2886 | }\r | |
2887 | \r | |
2888 | Offset = 0;\r | |
2889 | Width = 0;\r | |
2890 | Value = NULL;\r | |
2891 | \r | |
2892 | VA_START (Args, Number);\r | |
2893 | for (Index = 0; Index < Number; Index++) {\r | |
2894 | BufCfgArray = (UINT8 *) VA_ARG (Args, VOID *);\r | |
2895 | TotalLen = ReadUnaligned32 ((UINT32 *)BufCfgArray);\r | |
2896 | BufferPos = BufCfgArray + sizeof (UINT32);\r | |
2897 | \r | |
2898 | while ((UINT32)(BufferPos - BufCfgArray) < TotalLen) {\r | |
2899 | Offset = ReadUnaligned16 ((UINT16 *)BufferPos);\r | |
2900 | BufferPos += sizeof (UINT16);\r | |
2901 | Width = ReadUnaligned16 ((UINT16 *)BufferPos);\r | |
2902 | BufferPos += sizeof (UINT16);\r | |
2903 | Value = BufferPos;\r | |
2904 | BufferPos += Width;\r | |
2905 | \r | |
2906 | if ((UINTN)(Offset + Width) > *BufferSize) {\r | |
2907 | return EFI_BUFFER_TOO_SMALL;\r | |
2908 | }\r | |
2909 | \r | |
2910 | CopyMem ((UINT8 *)Buffer + Offset, Value, Width);\r | |
2911 | }\r | |
2912 | }\r | |
2913 | VA_END (Args);\r | |
2914 | \r | |
2915 | *BufferSize = (UINTN)Offset;\r | |
2916 | \r | |
2917 | return EFI_SUCCESS;\r | |
2918 | }\r |