]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.h
SecurityPkg: Implement AuthVariableLib library instance
[mirror_edk2.git] / SecurityPkg / VariableAuthenticated / RuntimeDxe / Variable.h
1 /** @file
2 The internal header file includes the common header files, defines
3 internal structure and functions used by Variable modules.
4
5 Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #ifndef _VARIABLE_H_
17 #define _VARIABLE_H_
18
19 #include <PiDxe.h>
20 #include <Protocol/VariableWrite.h>
21 #include <Protocol/FaultTolerantWrite.h>
22 #include <Protocol/FirmwareVolumeBlock.h>
23 #include <Protocol/Variable.h>
24 #include <Protocol/VariableLock.h>
25 #include <Protocol/VarCheck.h>
26 #include <Library/PcdLib.h>
27 #include <Library/HobLib.h>
28 #include <Library/UefiDriverEntryPoint.h>
29 #include <Library/DxeServicesTableLib.h>
30 #include <Library/UefiRuntimeLib.h>
31 #include <Library/DebugLib.h>
32 #include <Library/BaseMemoryLib.h>
33 #include <Library/UefiBootServicesTableLib.h>
34 #include <Library/UefiLib.h>
35 #include <Library/BaseLib.h>
36 #include <Library/SynchronizationLib.h>
37 #include <Library/MemoryAllocationLib.h>
38 #include <Library/BaseCryptLib.h>
39 #include <Library/PlatformSecureLib.h>
40 #include <Guid/GlobalVariable.h>
41 #include <Guid/EventGroup.h>
42 #include <Guid/AuthenticatedVariableFormat.h>
43 #include <Guid/ImageAuthentication.h>
44 #include <Guid/SystemNvDataGuid.h>
45 #include <Guid/FaultTolerantWrite.h>
46 #include <Guid/HardwareErrorVariable.h>
47 #include <Guid/VarErrorFlag.h>
48
49 #define EFI_VARIABLE_ATTRIBUTES_MASK (EFI_VARIABLE_NON_VOLATILE | \
50 EFI_VARIABLE_BOOTSERVICE_ACCESS | \
51 EFI_VARIABLE_RUNTIME_ACCESS | \
52 EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
53 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
54 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
55 EFI_VARIABLE_APPEND_WRITE)
56
57 #define VARIABLE_ATTRIBUTE_NV_BS (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS)
58 #define VARIABLE_ATTRIBUTE_BS_RT (EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS)
59 #define VARIABLE_ATTRIBUTE_NV_BS_RT (VARIABLE_ATTRIBUTE_BS_RT | EFI_VARIABLE_NON_VOLATILE)
60 #define VARIABLE_ATTRIBUTE_NV_BS_RT_AT (VARIABLE_ATTRIBUTE_NV_BS_RT | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS)
61 #define VARIABLE_ATTRIBUTE_NV_BS_RT_HR (VARIABLE_ATTRIBUTE_NV_BS_RT | EFI_VARIABLE_HARDWARE_ERROR_RECORD)
62 #define VARIABLE_ATTRIBUTE_NV_BS_RT_AW (VARIABLE_ATTRIBUTE_NV_BS_RT | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS)
63 #define VARIABLE_ATTRIBUTE_NV_BS_RT_AT_HR_AW (VARIABLE_ATTRIBUTE_NV_BS_RT_AT | EFI_VARIABLE_HARDWARE_ERROR_RECORD | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS)
64 #define VARIABLE_ATTRIBUTE_AT_AW (EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS)
65
66 #define MAX_NV_VARIABLE_SIZE (MAX (MAX (PcdGet32 (PcdMaxVariableSize), \
67 PcdGet32 (PcdMaxAuthVariableSize)), \
68 PcdGet32 (PcdMaxHardwareErrorVariableSize)))
69
70 ///
71 /// The size of a 3 character ISO639 language code.
72 ///
73 #define ISO_639_2_ENTRY_SIZE 3
74
75 typedef enum {
76 VariableStoreTypeVolatile,
77 VariableStoreTypeHob,
78 VariableStoreTypeNv,
79 VariableStoreTypeMax
80 } VARIABLE_STORE_TYPE;
81
82 typedef struct {
83 VARIABLE_HEADER *CurrPtr;
84 //
85 // If both ADDED and IN_DELETED_TRANSITION variable are present,
86 // InDeletedTransitionPtr will point to the IN_DELETED_TRANSITION one.
87 // Otherwise, CurrPtr will point to the ADDED or IN_DELETED_TRANSITION one,
88 // and InDeletedTransitionPtr will be NULL at the same time.
89 //
90 VARIABLE_HEADER *InDeletedTransitionPtr;
91 VARIABLE_HEADER *EndPtr;
92 VARIABLE_HEADER *StartPtr;
93 BOOLEAN Volatile;
94 } VARIABLE_POINTER_TRACK;
95
96 typedef struct {
97 EFI_PHYSICAL_ADDRESS HobVariableBase;
98 EFI_PHYSICAL_ADDRESS VolatileVariableBase;
99 EFI_PHYSICAL_ADDRESS NonVolatileVariableBase;
100 EFI_LOCK VariableServicesLock;
101 UINT32 ReentrantState;
102 } VARIABLE_GLOBAL;
103
104 typedef struct {
105 VARIABLE_GLOBAL VariableGlobal;
106 UINTN VolatileLastVariableOffset;
107 UINTN NonVolatileLastVariableOffset;
108 UINTN CommonVariableSpace;
109 UINTN CommonMaxUserVariableSpace;
110 UINTN CommonRuntimeVariableSpace;
111 UINTN CommonVariableTotalSize;
112 UINTN CommonUserVariableTotalSize;
113 UINTN HwErrVariableTotalSize;
114 UINTN MaxVariableSize;
115 UINTN MaxAuthVariableSize;
116 UINTN ScratchBufferSize;
117 CHAR8 *PlatformLangCodes;
118 CHAR8 *LangCodes;
119 CHAR8 *PlatformLang;
120 CHAR8 Lang[ISO_639_2_ENTRY_SIZE + 1];
121 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbInstance;
122 } VARIABLE_MODULE_GLOBAL;
123
124 typedef struct {
125 LIST_ENTRY Link;
126 EFI_GUID Guid;
127 //CHAR16 *Name;
128 } VARIABLE_ENTRY;
129
130 /**
131 Flush the HOB variable to flash.
132
133 @param[in] VariableName Name of variable has been updated or deleted.
134 @param[in] VendorGuid Guid of variable has been updated or deleted.
135
136 **/
137 VOID
138 FlushHobVariableToFlash (
139 IN CHAR16 *VariableName,
140 IN EFI_GUID *VendorGuid
141 );
142
143 /**
144 Writes a buffer to variable storage space, in the working block.
145
146 This function writes a buffer to variable storage space into a firmware
147 volume block device. The destination is specified by the parameter
148 VariableBase. Fault Tolerant Write protocol is used for writing.
149
150 @param VariableBase Base address of the variable to write.
151 @param VariableBuffer Point to the variable data buffer.
152
153 @retval EFI_SUCCESS The function completed successfully.
154 @retval EFI_NOT_FOUND Fail to locate Fault Tolerant Write protocol.
155 @retval EFI_ABORTED The function could not complete successfully.
156
157 **/
158 EFI_STATUS
159 FtwVariableSpace (
160 IN EFI_PHYSICAL_ADDRESS VariableBase,
161 IN VARIABLE_STORE_HEADER *VariableBuffer
162 );
163
164 /**
165 Finds variable in storage blocks of volatile and non-volatile storage areas.
166
167 This code finds variable in storage blocks of volatile and non-volatile storage areas.
168 If VariableName is an empty string, then we just return the first
169 qualified variable without comparing VariableName and VendorGuid.
170 If IgnoreRtCheck is TRUE, then we ignore the EFI_VARIABLE_RUNTIME_ACCESS attribute check
171 at runtime when searching existing variable, only VariableName and VendorGuid are compared.
172 Otherwise, variables without EFI_VARIABLE_RUNTIME_ACCESS are not visible at runtime.
173
174 @param[in] VariableName Name of the variable to be found.
175 @param[in] VendorGuid Vendor GUID to be found.
176 @param[out] PtrTrack VARIABLE_POINTER_TRACK structure for output,
177 including the range searched and the target position.
178 @param[in] Global Pointer to VARIABLE_GLOBAL structure, including
179 base of volatile variable storage area, base of
180 NV variable storage area, and a lock.
181 @param[in] IgnoreRtCheck Ignore EFI_VARIABLE_RUNTIME_ACCESS attribute
182 check at runtime when searching variable.
183
184 @retval EFI_INVALID_PARAMETER If VariableName is not an empty string, while
185 VendorGuid is NULL.
186 @retval EFI_SUCCESS Variable successfully found.
187 @retval EFI_NOT_FOUND Variable not found
188
189 **/
190 EFI_STATUS
191 FindVariable (
192 IN CHAR16 *VariableName,
193 IN EFI_GUID *VendorGuid,
194 OUT VARIABLE_POINTER_TRACK *PtrTrack,
195 IN VARIABLE_GLOBAL *Global,
196 IN BOOLEAN IgnoreRtCheck
197 );
198
199 /**
200
201 Gets the pointer to the end of the variable storage area.
202
203 This function gets pointer to the end of the variable storage
204 area, according to the input variable store header.
205
206 @param VarStoreHeader Pointer to the Variable Store Header.
207
208 @return Pointer to the end of the variable storage area.
209
210 **/
211 VARIABLE_HEADER *
212 GetEndPointer (
213 IN VARIABLE_STORE_HEADER *VarStoreHeader
214 );
215
216 /**
217
218 This code gets the pointer to the variable data.
219
220 @param Variable Pointer to the Variable Header.
221
222 @return Pointer to Variable Data.
223
224 **/
225 UINT8 *
226 GetVariableDataPtr (
227 IN VARIABLE_HEADER *Variable
228 );
229
230 /**
231
232 This code gets the size of variable data.
233
234 @param Variable Pointer to the Variable Header.
235
236 @return Size of variable in bytes.
237
238 **/
239 UINTN
240 DataSizeOfVariable (
241 IN VARIABLE_HEADER *Variable
242 );
243
244 /**
245 This function is to check if the remaining variable space is enough to set
246 all Variables from argument list successfully. The purpose of the check
247 is to keep the consistency of the Variables to be in variable storage.
248
249 Note: Variables are assumed to be in same storage.
250 The set sequence of Variables will be same with the sequence of VariableEntry from argument list,
251 so follow the argument sequence to check the Variables.
252
253 @param[in] Attributes Variable attributes for Variable entries.
254 @param ... The variable argument list with type VARIABLE_ENTRY_CONSISTENCY *.
255 A NULL terminates the list. The VariableSize of
256 VARIABLE_ENTRY_CONSISTENCY is the variable data size as input.
257 It will be changed to variable total size as output.
258
259 @retval TRUE Have enough variable space to set the Variables successfully.
260 @retval FALSE No enough variable space to set the Variables successfully.
261
262 **/
263 BOOLEAN
264 EFIAPI
265 CheckRemainingSpaceForConsistency (
266 IN UINT32 Attributes,
267 ...
268 );
269
270 /**
271 Update the variable region with Variable information. If EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS is set,
272 index of associated public key is needed.
273
274 @param[in] VariableName Name of variable.
275 @param[in] VendorGuid Guid of variable.
276 @param[in] Data Variable data.
277 @param[in] DataSize Size of data. 0 means delete.
278 @param[in] Attributes Attributes of the variable.
279 @param[in] KeyIndex Index of associated public key.
280 @param[in] MonotonicCount Value of associated monotonic count.
281 @param[in, out] Variable The variable information that is used to keep track of variable usage.
282
283 @param[in] TimeStamp Value of associated TimeStamp.
284
285 @retval EFI_SUCCESS The update operation is success.
286 @retval EFI_OUT_OF_RESOURCES Variable region is full, cannot write other data into this region.
287
288 **/
289 EFI_STATUS
290 UpdateVariable (
291 IN CHAR16 *VariableName,
292 IN EFI_GUID *VendorGuid,
293 IN VOID *Data,
294 IN UINTN DataSize,
295 IN UINT32 Attributes OPTIONAL,
296 IN UINT32 KeyIndex OPTIONAL,
297 IN UINT64 MonotonicCount OPTIONAL,
298 IN OUT VARIABLE_POINTER_TRACK *Variable,
299 IN EFI_TIME *TimeStamp OPTIONAL
300 );
301
302
303 /**
304 Return TRUE if ExitBootServices () has been called.
305
306 @retval TRUE If ExitBootServices () has been called.
307 **/
308 BOOLEAN
309 AtRuntime (
310 VOID
311 );
312
313 /**
314 Initializes a basic mutual exclusion lock.
315
316 This function initializes a basic mutual exclusion lock to the released state
317 and returns the lock. Each lock provides mutual exclusion access at its task
318 priority level. Since there is no preemption or multiprocessor support in EFI,
319 acquiring the lock only consists of raising to the locks TPL.
320 If Lock is NULL, then ASSERT().
321 If Priority is not a valid TPL value, then ASSERT().
322
323 @param Lock A pointer to the lock data structure to initialize.
324 @param Priority EFI TPL is associated with the lock.
325
326 @return The lock.
327
328 **/
329 EFI_LOCK *
330 InitializeLock (
331 IN OUT EFI_LOCK *Lock,
332 IN EFI_TPL Priority
333 );
334
335
336 /**
337 Acquires lock only at boot time. Simply returns at runtime.
338
339 This is a temperary function that will be removed when
340 EfiAcquireLock() in UefiLib can handle the call in UEFI
341 Runtimer driver in RT phase.
342 It calls EfiAcquireLock() at boot time, and simply returns
343 at runtime.
344
345 @param Lock A pointer to the lock to acquire.
346
347 **/
348 VOID
349 AcquireLockOnlyAtBootTime (
350 IN EFI_LOCK *Lock
351 );
352
353
354 /**
355 Releases lock only at boot time. Simply returns at runtime.
356
357 This is a temperary function which will be removed when
358 EfiReleaseLock() in UefiLib can handle the call in UEFI
359 Runtimer driver in RT phase.
360 It calls EfiReleaseLock() at boot time and simply returns
361 at runtime.
362
363 @param Lock A pointer to the lock to release.
364
365 **/
366 VOID
367 ReleaseLockOnlyAtBootTime (
368 IN EFI_LOCK *Lock
369 );
370
371 /**
372 Retrive the FVB protocol interface by HANDLE.
373
374 @param[in] FvBlockHandle The handle of FVB protocol that provides services for
375 reading, writing, and erasing the target block.
376 @param[out] FvBlock The interface of FVB protocol
377
378 @retval EFI_SUCCESS The interface information for the specified protocol was returned.
379 @retval EFI_UNSUPPORTED The device does not support the FVB protocol.
380 @retval EFI_INVALID_PARAMETER FvBlockHandle is not a valid EFI_HANDLE or FvBlock is NULL.
381
382 **/
383 EFI_STATUS
384 GetFvbByHandle (
385 IN EFI_HANDLE FvBlockHandle,
386 OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock
387 );
388
389
390 /**
391 Retrive the Swap Address Range protocol interface.
392
393 @param[out] SarProtocol The interface of SAR protocol
394
395 @retval EFI_SUCCESS The SAR protocol instance was found and returned in SarProtocol.
396 @retval EFI_NOT_FOUND The SAR protocol instance was not found.
397 @retval EFI_INVALID_PARAMETER SarProtocol is NULL.
398
399 **/
400 EFI_STATUS
401 GetSarProtocol (
402 OUT VOID **SarProtocol
403 );
404
405 /**
406 Function returns an array of handles that support the FVB protocol
407 in a buffer allocated from pool.
408
409 @param[out] NumberHandles The number of handles returned in Buffer.
410 @param[out] Buffer A pointer to the buffer to return the requested
411 array of handles that support FVB protocol.
412
413 @retval EFI_SUCCESS The array of handles was returned in Buffer, and the number of
414 handles in Buffer was returned in NumberHandles.
415 @retval EFI_NOT_FOUND No FVB handle was found.
416 @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the matching results.
417 @retval EFI_INVALID_PARAMETER NumberHandles is NULL or Buffer is NULL.
418
419 **/
420 EFI_STATUS
421 GetFvbCountAndBuffer (
422 OUT UINTN *NumberHandles,
423 OUT EFI_HANDLE **Buffer
424 );
425
426 /**
427 Initializes variable store area for non-volatile and volatile variable.
428
429 @retval EFI_SUCCESS Function successfully executed.
430 @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource.
431
432 **/
433 EFI_STATUS
434 VariableCommonInitialize (
435 VOID
436 );
437
438 /**
439
440 Variable store garbage collection and reclaim operation.
441
442 If ReclaimPubKeyStore is FALSE, reclaim variable space by deleting the obsoleted varaibles.
443 If ReclaimPubKeyStore is TRUE, reclaim invalid key in public key database and update the PubKeyIndex
444 for all the count-based authenticate variable in NV storage.
445
446 @param[in] VariableBase Base address of variable store.
447 @param[out] LastVariableOffset Offset of last variable.
448 @param[in] IsVolatile The variable store is volatile or not;
449 if it is non-volatile, need FTW.
450 @param[in, out] UpdatingPtrTrack Pointer to updating variable pointer track structure.
451 @param[in] NewVariable Pointer to new variable.
452 @param[in] NewVariableSize New variable size.
453 @param[in] ReclaimPubKeyStore Reclaim for public key database or not.
454
455 @return EFI_SUCCESS Reclaim operation has finished successfully.
456 @return EFI_OUT_OF_RESOURCES No enough memory resources or variable space.
457 @return EFI_DEVICE_ERROR The public key database doesn't exist.
458 @return Others Unexpect error happened during reclaim operation.
459
460 **/
461 EFI_STATUS
462 Reclaim (
463 IN EFI_PHYSICAL_ADDRESS VariableBase,
464 OUT UINTN *LastVariableOffset,
465 IN BOOLEAN IsVolatile,
466 IN OUT VARIABLE_POINTER_TRACK *UpdatingPtrTrack,
467 IN VARIABLE_HEADER *NewVariable,
468 IN UINTN NewVariableSize,
469 IN BOOLEAN ReclaimPubKeyStore
470 );
471
472 /**
473 This function reclaims variable storage if free size is below the threshold.
474
475 **/
476 VOID
477 ReclaimForOS(
478 VOID
479 );
480
481
482 /**
483 Initializes variable write service after FVB was ready.
484
485 @retval EFI_SUCCESS Function successfully executed.
486 @retval Others Fail to initialize the variable service.
487
488 **/
489 EFI_STATUS
490 VariableWriteServiceInitialize (
491 VOID
492 );
493
494 /**
495 Retrive the SMM Fault Tolerent Write protocol interface.
496
497 @param[out] FtwProtocol The interface of SMM Ftw protocol
498
499 @retval EFI_SUCCESS The SMM SAR protocol instance was found and returned in SarProtocol.
500 @retval EFI_NOT_FOUND The SMM SAR protocol instance was not found.
501 @retval EFI_INVALID_PARAMETER SarProtocol is NULL.
502
503 **/
504 EFI_STATUS
505 GetFtwProtocol (
506 OUT VOID **FtwProtocol
507 );
508
509 /**
510 Get the proper fvb handle and/or fvb protocol by the given Flash address.
511
512 @param[in] Address The Flash address.
513 @param[out] FvbHandle In output, if it is not NULL, it points to the proper FVB handle.
514 @param[out] FvbProtocol In output, if it is not NULL, it points to the proper FVB protocol.
515
516 **/
517 EFI_STATUS
518 GetFvbInfoByAddress (
519 IN EFI_PHYSICAL_ADDRESS Address,
520 OUT EFI_HANDLE *FvbHandle OPTIONAL,
521 OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvbProtocol OPTIONAL
522 );
523
524 /**
525
526 This code finds variable in storage blocks (Volatile or Non-Volatile).
527
528 Caution: This function may receive untrusted input.
529 This function may be invoked in SMM mode, and datasize and data are external input.
530 This function will do basic validation, before parse the data.
531
532 @param VariableName Name of Variable to be found.
533 @param VendorGuid Variable vendor GUID.
534 @param Attributes Attribute value of the variable found.
535 @param DataSize Size of Data found. If size is less than the
536 data, this value contains the required size.
537 @param Data Data pointer.
538
539 @return EFI_INVALID_PARAMETER Invalid parameter.
540 @return EFI_SUCCESS Find the specified variable.
541 @return EFI_NOT_FOUND Not found.
542 @return EFI_BUFFER_TO_SMALL DataSize is too small for the result.
543
544 **/
545 EFI_STATUS
546 EFIAPI
547 VariableServiceGetVariable (
548 IN CHAR16 *VariableName,
549 IN EFI_GUID *VendorGuid,
550 OUT UINT32 *Attributes OPTIONAL,
551 IN OUT UINTN *DataSize,
552 OUT VOID *Data
553 );
554
555 /**
556
557 This code Finds the Next available variable.
558
559 Caution: This function may receive untrusted input.
560 This function may be invoked in SMM mode. This function will do basic validation, before parse the data.
561
562 @param VariableNameSize Size of the variable name.
563 @param VariableName Pointer to variable name.
564 @param VendorGuid Variable Vendor Guid.
565
566 @return EFI_INVALID_PARAMETER Invalid parameter.
567 @return EFI_SUCCESS Find the specified variable.
568 @return EFI_NOT_FOUND Not found.
569 @return EFI_BUFFER_TO_SMALL DataSize is too small for the result.
570
571 **/
572 EFI_STATUS
573 EFIAPI
574 VariableServiceGetNextVariableName (
575 IN OUT UINTN *VariableNameSize,
576 IN OUT CHAR16 *VariableName,
577 IN OUT EFI_GUID *VendorGuid
578 );
579
580 /**
581
582 This code sets variable in storage blocks (Volatile or Non-Volatile).
583
584 Caution: This function may receive untrusted input.
585 This function may be invoked in SMM mode, and datasize and data are external input.
586 This function will do basic validation, before parse the data.
587 This function will parse the authentication carefully to avoid security issues, like
588 buffer overflow, integer overflow.
589 This function will check attribute carefully to avoid authentication bypass.
590
591 @param VariableName Name of Variable to be found.
592 @param VendorGuid Variable vendor GUID.
593 @param Attributes Attribute value of the variable found
594 @param DataSize Size of Data found. If size is less than the
595 data, this value contains the required size.
596 @param Data Data pointer.
597
598 @return EFI_INVALID_PARAMETER Invalid parameter.
599 @return EFI_SUCCESS Set successfully.
600 @return EFI_OUT_OF_RESOURCES Resource not enough to set variable.
601 @return EFI_NOT_FOUND Not found.
602 @return EFI_WRITE_PROTECTED Variable is read-only.
603
604 **/
605 EFI_STATUS
606 EFIAPI
607 VariableServiceSetVariable (
608 IN CHAR16 *VariableName,
609 IN EFI_GUID *VendorGuid,
610 IN UINT32 Attributes,
611 IN UINTN DataSize,
612 IN VOID *Data
613 );
614
615 /**
616
617 This code returns information about the EFI variables.
618
619 Caution: This function may receive untrusted input.
620 This function may be invoked in SMM mode. This function will do basic validation, before parse the data.
621
622 @param Attributes Attributes bitmask to specify the type of variables
623 on which to return information.
624 @param MaximumVariableStorageSize Pointer to the maximum size of the storage space available
625 for the EFI variables associated with the attributes specified.
626 @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available
627 for EFI variables associated with the attributes specified.
628 @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
629 associated with the attributes specified.
630
631 @return EFI_SUCCESS Query successfully.
632
633 **/
634 EFI_STATUS
635 EFIAPI
636 VariableServiceQueryVariableInfoInternal (
637 IN UINT32 Attributes,
638 OUT UINT64 *MaximumVariableStorageSize,
639 OUT UINT64 *RemainingVariableStorageSize,
640 OUT UINT64 *MaximumVariableSize
641 );
642
643 /**
644
645 This code returns information about the EFI variables.
646
647 Caution: This function may receive untrusted input.
648 This function may be invoked in SMM mode. This function will do basic validation, before parse the data.
649
650 @param Attributes Attributes bitmask to specify the type of variables
651 on which to return information.
652 @param MaximumVariableStorageSize Pointer to the maximum size of the storage space available
653 for the EFI variables associated with the attributes specified.
654 @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available
655 for EFI variables associated with the attributes specified.
656 @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
657 associated with the attributes specified.
658
659 @return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
660 @return EFI_SUCCESS Query successfully.
661 @return EFI_UNSUPPORTED The attribute is not supported on this platform.
662
663 **/
664 EFI_STATUS
665 EFIAPI
666 VariableServiceQueryVariableInfo (
667 IN UINT32 Attributes,
668 OUT UINT64 *MaximumVariableStorageSize,
669 OUT UINT64 *RemainingVariableStorageSize,
670 OUT UINT64 *MaximumVariableSize
671 );
672
673 /**
674 Mark a variable that will become read-only after leaving the DXE phase of execution.
675
676 @param[in] This The VARIABLE_LOCK_PROTOCOL instance.
677 @param[in] VariableName A pointer to the variable name that will be made read-only subsequently.
678 @param[in] VendorGuid A pointer to the vendor GUID that will be made read-only subsequently.
679
680 @retval EFI_SUCCESS The variable specified by the VariableName and the VendorGuid was marked
681 as pending to be read-only.
682 @retval EFI_INVALID_PARAMETER VariableName or VendorGuid is NULL.
683 Or VariableName is an empty string.
684 @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has
685 already been signaled.
686 @retval EFI_OUT_OF_RESOURCES There is not enough resource to hold the lock request.
687 **/
688 EFI_STATUS
689 EFIAPI
690 VariableLockRequestToLock (
691 IN CONST EDKII_VARIABLE_LOCK_PROTOCOL *This,
692 IN CHAR16 *VariableName,
693 IN EFI_GUID *VendorGuid
694 );
695
696 /**
697 Check if a Unicode character is a hexadecimal character.
698
699 This function checks if a Unicode character is a
700 hexadecimal character. The valid hexadecimal character is
701 L'0' to L'9', L'a' to L'f', or L'A' to L'F'.
702
703
704 @param Char The character to check against.
705
706 @retval TRUE If the Char is a hexadecmial character.
707 @retval FALSE If the Char is not a hexadecmial character.
708
709 **/
710 BOOLEAN
711 EFIAPI
712 IsHexaDecimalDigitCharacter (
713 IN CHAR16 Char
714 );
715
716 /**
717 Internal SetVariable check.
718
719 @param[in] VariableName Name of Variable to set.
720 @param[in] VendorGuid Variable vendor GUID.
721 @param[in] Attributes Attribute value of the variable.
722 @param[in] DataSize Size of Data to set.
723 @param[in] Data Data pointer.
724
725 @retval EFI_SUCCESS The SetVariable check result was success.
726 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID were supplied,
727 or the DataSize exceeds the minimum or maximum allowed,
728 or the Data value is not following UEFI spec for UEFI defined variables.
729 @retval EFI_WRITE_PROTECTED The variable in question is read-only.
730 @retval Others The return status from check handler.
731
732 **/
733 EFI_STATUS
734 EFIAPI
735 InternalVarCheckSetVariableCheck (
736 IN CHAR16 *VariableName,
737 IN EFI_GUID *VendorGuid,
738 IN UINT32 Attributes,
739 IN UINTN DataSize,
740 IN VOID *Data
741 );
742
743 /**
744 Register SetVariable check handler.
745
746 @param[in] Handler Pointer to check handler.
747
748 @retval EFI_SUCCESS The SetVariable check handler was registered successfully.
749 @retval EFI_INVALID_PARAMETER Handler is NULL.
750 @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has
751 already been signaled.
752 @retval EFI_OUT_OF_RESOURCES There is not enough resource for the SetVariable check handler register request.
753 @retval EFI_UNSUPPORTED This interface is not implemented.
754 For example, it is unsupported in VarCheck protocol if both VarCheck and SmmVarCheck protocols are present.
755
756 **/
757 EFI_STATUS
758 EFIAPI
759 VarCheckRegisterSetVariableCheckHandler (
760 IN VAR_CHECK_SET_VARIABLE_CHECK_HANDLER Handler
761 );
762
763 /**
764 Internal variable property get.
765
766 @param[in] Name Pointer to the variable name.
767 @param[in] Guid Pointer to the vendor GUID.
768 @param[out] VariableProperty Pointer to the output variable property.
769
770 @retval EFI_SUCCESS The property of variable specified by the Name and Guid was got successfully.
771 @retval EFI_NOT_FOUND The property of variable specified by the Name and Guid was not found.
772
773 **/
774 EFI_STATUS
775 EFIAPI
776 InternalVarCheckVariablePropertyGet (
777 IN CHAR16 *Name,
778 IN EFI_GUID *Guid,
779 OUT VAR_CHECK_VARIABLE_PROPERTY *VariableProperty
780 );
781
782 /**
783 Variable property set.
784
785 @param[in] Name Pointer to the variable name.
786 @param[in] Guid Pointer to the vendor GUID.
787 @param[in] VariableProperty Pointer to the input variable property.
788
789 @retval EFI_SUCCESS The property of variable specified by the Name and Guid was set successfully.
790 @retval EFI_INVALID_PARAMETER Name, Guid or VariableProperty is NULL, or Name is an empty string,
791 or the fields of VariableProperty are not valid.
792 @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has
793 already been signaled.
794 @retval EFI_OUT_OF_RESOURCES There is not enough resource for the variable property set request.
795
796 **/
797 EFI_STATUS
798 EFIAPI
799 VarCheckVariablePropertySet (
800 IN CHAR16 *Name,
801 IN EFI_GUID *Guid,
802 IN VAR_CHECK_VARIABLE_PROPERTY *VariableProperty
803 );
804
805 /**
806 Variable property get.
807
808 @param[in] Name Pointer to the variable name.
809 @param[in] Guid Pointer to the vendor GUID.
810 @param[out] VariableProperty Pointer to the output variable property.
811
812 @retval EFI_SUCCESS The property of variable specified by the Name and Guid was got successfully.
813 @retval EFI_INVALID_PARAMETER Name, Guid or VariableProperty is NULL, or Name is an empty string.
814 @retval EFI_NOT_FOUND The property of variable specified by the Name and Guid was not found.
815
816 **/
817 EFI_STATUS
818 EFIAPI
819 VarCheckVariablePropertyGet (
820 IN CHAR16 *Name,
821 IN EFI_GUID *Guid,
822 OUT VAR_CHECK_VARIABLE_PROPERTY *VariableProperty
823 );
824
825 /**
826 Initialize variable quota.
827
828 **/
829 VOID
830 InitializeVariableQuota (
831 VOID
832 );
833
834 extern VARIABLE_MODULE_GLOBAL *mVariableModuleGlobal;
835
836 #endif