TianoCore EDK2 master
Loading...
Searching...
No Matches
VariableExLib.c
Go to the documentation of this file.
1
9#include "Variable.h"
10#include "VariableParsing.h"
11
31EFIAPI
33 IN CHAR16 *VariableName,
34 IN EFI_GUID *VendorGuid,
35 OUT AUTH_VARIABLE_INFO *AuthVariableInfo
36 )
37{
38 EFI_STATUS Status;
41
42 Status = FindVariable (
43 VariableName,
44 VendorGuid,
45 &Variable,
46 &mVariableModuleGlobal->VariableGlobal,
47 FALSE
48 );
49 if (EFI_ERROR (Status)) {
50 AuthVariableInfo->Data = NULL;
51 AuthVariableInfo->DataSize = 0;
52 AuthVariableInfo->Attributes = 0;
53 AuthVariableInfo->PubKeyIndex = 0;
54 AuthVariableInfo->MonotonicCount = 0;
55 AuthVariableInfo->TimeStamp = NULL;
56 return Status;
57 }
58
59 AuthVariableInfo->DataSize = DataSizeOfVariable (Variable.CurrPtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
60 AuthVariableInfo->Data = GetVariableDataPtr (Variable.CurrPtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
61 AuthVariableInfo->Attributes = Variable.CurrPtr->Attributes;
62 if (mVariableModuleGlobal->VariableGlobal.AuthFormat) {
63 AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *)Variable.CurrPtr;
64 AuthVariableInfo->PubKeyIndex = AuthVariable->PubKeyIndex;
65 AuthVariableInfo->MonotonicCount = ReadUnaligned64 (&(AuthVariable->MonotonicCount));
66 AuthVariableInfo->TimeStamp = &AuthVariable->TimeStamp;
67 }
68
69 return EFI_SUCCESS;
70}
71
91EFIAPI
93 IN CHAR16 *VariableName,
94 IN EFI_GUID *VendorGuid,
95 OUT AUTH_VARIABLE_INFO *AuthVariableInfo
96 )
97{
98 EFI_STATUS Status;
99 VARIABLE_HEADER *VariablePtr;
100 AUTHENTICATED_VARIABLE_HEADER *AuthVariablePtr;
101 VARIABLE_STORE_HEADER *VariableStoreHeader[VariableStoreTypeMax];
102
103 VariableStoreHeader[VariableStoreTypeVolatile] = (VARIABLE_STORE_HEADER *)(UINTN)mVariableModuleGlobal->VariableGlobal.VolatileVariableBase;
104 VariableStoreHeader[VariableStoreTypeHob] = (VARIABLE_STORE_HEADER *)(UINTN)mVariableModuleGlobal->VariableGlobal.HobVariableBase;
105 VariableStoreHeader[VariableStoreTypeNv] = mNvVariableCache;
106
108 VariableName,
109 VendorGuid,
110 VariableStoreHeader,
111 &VariablePtr,
112 mVariableModuleGlobal->VariableGlobal.AuthFormat
113 );
114 if (EFI_ERROR (Status)) {
115 AuthVariableInfo->VariableName = NULL;
116 AuthVariableInfo->VendorGuid = NULL;
117 AuthVariableInfo->Data = NULL;
118 AuthVariableInfo->DataSize = 0;
119 AuthVariableInfo->Attributes = 0;
120 AuthVariableInfo->PubKeyIndex = 0;
121 AuthVariableInfo->MonotonicCount = 0;
122 AuthVariableInfo->TimeStamp = NULL;
123 return Status;
124 }
125
126 AuthVariableInfo->VariableName = GetVariableNamePtr (VariablePtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
127 AuthVariableInfo->VendorGuid = GetVendorGuidPtr (VariablePtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
128 AuthVariableInfo->DataSize = DataSizeOfVariable (VariablePtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
129 AuthVariableInfo->Data = GetVariableDataPtr (VariablePtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
130 AuthVariableInfo->Attributes = VariablePtr->Attributes;
131 if (mVariableModuleGlobal->VariableGlobal.AuthFormat) {
132 AuthVariablePtr = (AUTHENTICATED_VARIABLE_HEADER *)VariablePtr;
133 AuthVariableInfo->PubKeyIndex = AuthVariablePtr->PubKeyIndex;
134 AuthVariableInfo->MonotonicCount = ReadUnaligned64 (&(AuthVariablePtr->MonotonicCount));
135 AuthVariableInfo->TimeStamp = &AuthVariablePtr->TimeStamp;
136 }
137
138 return EFI_SUCCESS;
139}
140
154EFIAPI
156 IN AUTH_VARIABLE_INFO *AuthVariableInfo
157 )
158{
159 VARIABLE_POINTER_TRACK Variable;
160
161 FindVariable (AuthVariableInfo->VariableName, AuthVariableInfo->VendorGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);
162 return UpdateVariable (
163 AuthVariableInfo->VariableName,
164 AuthVariableInfo->VendorGuid,
165 AuthVariableInfo->Data,
166 AuthVariableInfo->DataSize,
167 AuthVariableInfo->Attributes,
168 AuthVariableInfo->PubKeyIndex,
169 AuthVariableInfo->MonotonicCount,
170 &Variable,
171 AuthVariableInfo->TimeStamp
172 );
173}
174
188EFIAPI
190 IN OUT UINTN *ScratchBufferSize,
191 OUT VOID **ScratchBuffer
192 )
193{
194 UINTN MaxBufferSize;
195
196 MaxBufferSize = mVariableModuleGlobal->ScratchBufferSize;
197 if (*ScratchBufferSize > MaxBufferSize) {
198 *ScratchBufferSize = MaxBufferSize;
199 return EFI_UNSUPPORTED;
200 }
201
202 *ScratchBuffer = GetEndPointer ((VARIABLE_STORE_HEADER *)((UINTN)mVariableModuleGlobal->VariableGlobal.VolatileVariableBase));
203 return EFI_SUCCESS;
204}
205
225BOOLEAN
226EFIAPI
228 IN UINT32 Attributes,
229 ...
230 )
231{
232 VA_LIST Marker;
233 BOOLEAN Return;
234
235 VA_START (Marker, Attributes);
236
237 Return = CheckRemainingSpaceForConsistencyInternal (Attributes, Marker);
238
239 VA_END (Marker);
240
241 return Return;
242}
243
251BOOLEAN
252EFIAPI
254 VOID
255 )
256{
257 return AtRuntime ();
258}
UINT64 UINTN
UINT64 EFIAPI ReadUnaligned64(IN CONST UINT64 *Buffer)
Definition: Unaligned.c:204
BOOLEAN AtRuntime(VOID)
Definition: VariableDxe.c:63
#define NULL
Definition: Base.h:319
#define VA_START(Marker, Parameter)
Definition: Base.h:661
#define FALSE
Definition: Base.h:307
CHAR8 * VA_LIST
Definition: Base.h:643
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define VA_END(Marker)
Definition: Base.h:691
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
UINT8 * GetVariableDataPtr(IN VARIABLE_HEADER *Variable, IN VARIABLE_HEADER *VariableHeader, IN BOOLEAN AuthFlag)
Definition: Variable.c:300
CHAR16 * GetVariableNamePtr(IN VARIABLE_HEADER *Variable, IN BOOLEAN AuthFlag)
Definition: Variable.c:256
EFI_STATUS FindVariable(IN CONST CHAR16 *VariableName, IN CONST EFI_GUID *VendorGuid, OUT VARIABLE_POINTER_TRACK *PtrTrack, OUT VARIABLE_STORE_INFO *StoreInfo)
Definition: Variable.c:992
VARIABLE_HEADER * GetEndPointer(IN VARIABLE_STORE_HEADER *VarStoreHeader)
Definition: Variable.c:109
UINTN DataSizeOfVariable(IN VARIABLE_HEADER *Variable, IN BOOLEAN AuthFlag)
Definition: Variable.c:215
EFI_GUID * GetVendorGuidPtr(IN VARIABLE_HEADER *Variable, IN BOOLEAN AuthFlag)
Definition: Variable.c:274
EFI_STATUS UpdateVariable(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN VOID *Data, IN UINTN DataSize, IN UINT32 Attributes OPTIONAL, IN UINT32 KeyIndex OPTIONAL, IN UINT64 MonotonicCount OPTIONAL, IN OUT VARIABLE_POINTER_TRACK *CacheVariable, IN EFI_TIME *TimeStamp OPTIONAL)
Definition: Variable.c:1678
BOOLEAN EFIAPI CheckRemainingSpaceForConsistencyInternal(IN UINT32 Attributes, IN VA_LIST Marker)
Definition: Variable.c:1240
VARIABLE_STORE_HEADER * mNvVariableCache
Definition: Variable.c:39
EFI_STATUS EFIAPI VariableExLibGetScratchBuffer(IN OUT UINTN *ScratchBufferSize, OUT VOID **ScratchBuffer)
BOOLEAN EFIAPI VariableExLibAtRuntime(VOID)
BOOLEAN EFIAPI VariableExLibCheckRemainingSpaceForConsistency(IN UINT32 Attributes,...)
EFI_STATUS EFIAPI VariableExLibFindVariable(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT AUTH_VARIABLE_INFO *AuthVariableInfo)
Definition: VariableExLib.c:32
EFI_STATUS EFIAPI VariableExLibUpdateVariable(IN AUTH_VARIABLE_INFO *AuthVariableInfo)
EFI_STATUS EFIAPI VariableExLibFindNextVariable(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT AUTH_VARIABLE_INFO *AuthVariableInfo)
Definition: VariableExLib.c:92
EFI_STATUS EFIAPI VariableServiceGetNextVariableInternal(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN VARIABLE_STORE_HEADER **VariableStoreList, OUT VARIABLE_HEADER **VariablePtr, IN BOOLEAN AuthFormat)
Definition: Base.h:213