TianoCore EDK2 master
Loading...
Searching...
No Matches
WifiConnectionMgrFileUtil.c
Go to the documentation of this file.
1
11
12CHAR16 *mDerPemEncodedSuffix[] = {
13 L".cer",
14 L".der",
15 L".crt",
16 L".pem",
17 NULL
18};
19
29BOOLEAN
31 IN CONST CHAR16 *FileSuffix
32 )
33{
34 UINTN Index;
35
36 for (Index = 0; mDerPemEncodedSuffix[Index] != NULL; Index++) {
37 if (StrCmp (FileSuffix, mDerPemEncodedSuffix[Index]) == 0) {
38 return TRUE;
39 }
40 }
41
42 return FALSE;
43}
44
63 IN EFI_FILE_HANDLE FileHandle,
64 IN OUT VOID **BufferPtr,
65 OUT UINTN *FileSize,
66 IN UINTN AddtionAllocateSize
67 )
68{
69 UINTN BufferSize;
70 UINT64 SourceFileSize;
71 VOID *Buffer;
72 EFI_STATUS Status;
73
74 if ((FileHandle == NULL) || (FileSize == NULL)) {
75 return EFI_INVALID_PARAMETER;
76 }
77
78 Buffer = NULL;
79
80 //
81 // Get the file size
82 //
83 Status = FileHandle->SetPosition (FileHandle, (UINT64)-1);
84 if (EFI_ERROR (Status)) {
85 goto ON_EXIT;
86 }
87
88 Status = FileHandle->GetPosition (FileHandle, &SourceFileSize);
89 if (EFI_ERROR (Status)) {
90 goto ON_EXIT;
91 }
92
93 Status = FileHandle->SetPosition (FileHandle, 0);
94 if (EFI_ERROR (Status)) {
95 goto ON_EXIT;
96 }
97
98 BufferSize = (UINTN)SourceFileSize + AddtionAllocateSize;
99 Buffer = AllocateZeroPool (BufferSize);
100 if (Buffer == NULL) {
101 return EFI_OUT_OF_RESOURCES;
102 }
103
104 BufferSize = (UINTN)SourceFileSize;
105 *FileSize = BufferSize;
106
107 Status = FileHandle->Read (FileHandle, &BufferSize, Buffer);
108 if (EFI_ERROR (Status) || (BufferSize != *FileSize)) {
109 FreePool (Buffer);
110 Buffer = NULL;
111 Status = EFI_BAD_BUFFER_SIZE;
112 goto ON_EXIT;
113 }
114
115ON_EXIT:
116
117 *BufferPtr = Buffer;
118 return Status;
119}
120
129CHAR16 *
130EFIAPI
133 )
134{
136 DevPath,
137 FALSE,
138 TRUE
139 );
140}
141
153CHAR16 *
155 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
156 )
157{
158 CHAR16 *String;
159 CHAR16 *MatchString;
160 CHAR16 *LastMatch;
161 CHAR16 *FileName;
162 UINTN Length;
163
164 ASSERT (DevicePath != NULL);
165
166 String = DevicePathToStr (DevicePath);
167 if (String == NULL) {
168 return NULL;
169 }
170
171 MatchString = String;
172 LastMatch = String;
173 FileName = NULL;
174
175 while (MatchString != NULL) {
176 LastMatch = MatchString + 1;
177 MatchString = StrStr (LastMatch, L"\\");
178 }
179
180 Length = StrLen (LastMatch);
181 FileName = AllocateCopyPool ((Length + 1) * sizeof (CHAR16), LastMatch);
182 if (FileName != NULL) {
183 *(FileName + Length) = 0;
184 }
185
186 FreePool (String);
187
188 return FileName;
189}
190
202BOOLEAN
204 IN WIFI_MGR_PRIVATE_DATA *Private,
206 IN EFI_FORM_ID FormId
207 )
208{
209 CHAR16 *FileName;
210 EFI_STATUS Status;
211
212 FileName = NULL;
213
214 if (FilePath != NULL) {
215 FileName = ExtractFileNameFromDevicePath (FilePath);
216 }
217
218 if (FileName == NULL) {
219 //
220 // FileName = NULL has two cases:
221 // 1. FilePath == NULL, not select file.
222 // 2. FilePath != NULL, but ExtractFileNameFromDevicePath return NULL not enough memory resource.
223 // In these two case, no need to update the form, and exit the caller function.
224 //
225 return TRUE;
226 }
227
228 //
229 // Close the previous file handle before open a new one.
230 //
231 if (Private->FileContext->FHandle != NULL) {
232 Private->FileContext->FHandle->Close (Private->FileContext->FHandle);
233 }
234
235 Private->FileContext->FHandle = NULL;
236
237 Status = EfiOpenFileByDevicePath (
238 &FilePath,
239 &Private->FileContext->FHandle,
240 EFI_FILE_MODE_READ,
241 0
242 );
243 if (EFI_ERROR (Status)) {
244 if (FormId == FORMID_ENROLL_CERT) {
246 Private->RegisteredHandle,
247 STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME),
248 L"",
249 NULL
250 );
251 } else if (FormId == FORMID_ENROLL_PRIVATE_KEY) {
253 Private->RegisteredHandle,
254 STRING_TOKEN (STR_EAP_ENROLLED_PRIVATE_KEY_NAME),
255 L"",
256 NULL
257 );
258 }
259 } else {
260 if (Private->FileContext->FileName != NULL) {
261 FreePool (Private->FileContext->FileName);
262 Private->FileContext->FileName = NULL;
263 }
264
265 Private->FileContext->FileName = FileName;
266
267 if (FormId == FORMID_ENROLL_CERT) {
269 Private->RegisteredHandle,
270 STRING_TOKEN (STR_EAP_ENROLLED_CERT_NAME),
271 FileName,
272 NULL
273 );
274 } else if (FormId == FORMID_ENROLL_PRIVATE_KEY) {
276 Private->RegisteredHandle,
277 STRING_TOKEN (STR_EAP_ENROLLED_PRIVATE_KEY_NAME),
278 FileName,
279 NULL
280 );
281 }
282 }
283
284 return TRUE;
285}
286
297BOOLEAN
299 IN WIFI_MGR_PRIVATE_DATA *Private,
301 )
302{
303 return UpdatePage (Private, FilePath, FORMID_ENROLL_CERT);
304}
305
316BOOLEAN
318 IN WIFI_MGR_PRIVATE_DATA *Private,
320 )
321{
322 return UpdatePage (Private, FilePath, FORMID_ENROLL_PRIVATE_KEY);
323}
UINT64 UINTN
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
Definition: String.c:109
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
CHAR16 *EFIAPI StrStr(IN CONST CHAR16 *String, IN CONST CHAR16 *SearchString)
Definition: String.c:224
CHAR16 *EFIAPI ConvertDevicePathToText(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN BOOLEAN DisplayOnly, IN BOOLEAN AllowShortcuts)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
EFI_STRING_ID EFIAPI HiiSetString(IN EFI_HII_HANDLE HiiHandle, IN EFI_STRING_ID StringId OPTIONAL, IN CONST EFI_STRING String, IN CONST CHAR8 *SupportedLanguages OPTIONAL)
Definition: HiiString.c:52
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define STRING_TOKEN(t)
EFI_STATUS EFIAPI EfiOpenFileByDevicePath(IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath, OUT EFI_FILE_PROTOCOL **File, IN UINT64 OpenMode, IN UINT64 Attributes)
Definition: UefiLib.c:1806
BOOLEAN IsDerPemEncodeCertificate(IN CONST CHAR16 *FileSuffix)
EFI_STATUS ReadFileContent(IN EFI_FILE_HANDLE FileHandle, IN OUT VOID **BufferPtr, OUT UINTN *FileSize, IN UINTN AddtionAllocateSize)
BOOLEAN UpdateCAFromFile(IN WIFI_MGR_PRIVATE_DATA *Private, IN EFI_DEVICE_PATH_PROTOCOL *FilePath)
BOOLEAN UpdatePage(IN WIFI_MGR_PRIVATE_DATA *Private, IN EFI_DEVICE_PATH_PROTOCOL *FilePath, IN EFI_FORM_ID FormId)
CHAR16 *EFIAPI DevicePathToStr(IN EFI_DEVICE_PATH_PROTOCOL *DevPath)
BOOLEAN UpdatePrivateKeyFromFile(IN WIFI_MGR_PRIVATE_DATA *Private, IN EFI_DEVICE_PATH_PROTOCOL *FilePath)
CHAR16 * ExtractFileNameFromDevicePath(IN EFI_DEVICE_PATH_PROTOCOL *DevicePath)