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