2 Internal file explorer functions for SecureBoot configuration module.
4 Copyright (c) 2012 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "SecureBootConfigImpl.h"
17 VOID
*mStartOpCodeHandle
= NULL
;
18 VOID
*mEndOpCodeHandle
= NULL
;
19 EFI_IFR_GUID_LABEL
*mStartLabel
= NULL
;
20 EFI_IFR_GUID_LABEL
*mEndLabel
= NULL
;
23 Refresh the global UpdateData structure.
32 // Free current updated date
34 if (mStartOpCodeHandle
!= NULL
) {
35 HiiFreeOpCodeHandle (mStartOpCodeHandle
);
39 // Create new OpCode Handle
41 mStartOpCodeHandle
= HiiAllocateOpCodeHandle ();
44 // Create Hii Extend Label OpCode as the start opcode
46 mStartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (
50 sizeof (EFI_IFR_GUID_LABEL
)
52 mStartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
56 Clean up the dynamic opcode at label and form specified by both LabelId.
58 @param[in] LabelId It is both the Form ID and Label ID for opcode deletion.
59 @param[in] PrivateData Module private data.
65 IN SECUREBOOT_CONFIG_PRIVATE_DATA
*PrivateData
71 // Remove all op-codes from dynamic page
73 mStartLabel
->Number
= LabelId
;
75 PrivateData
->HiiHandle
,
76 &gSecureBootConfigFormSetGuid
,
78 mStartOpCodeHandle
, // Label LabelId
79 mEndOpCodeHandle
// LABEL_END
84 This function will open a file or directory referenced by DevicePath.
86 This function opens a file with the open mode according to the file path. The
87 Attributes is valid only for EFI_FILE_MODE_CREATE.
89 @param[in, out] FilePath On input, the device path to the file.
90 On output, the remaining device path.
91 @param[out] FileHandle Pointer to the file handle.
92 @param[in] OpenMode The mode to open the file with.
93 @param[in] Attributes The file's file attributes.
95 @retval EFI_SUCCESS The information was set.
96 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
97 @retval EFI_UNSUPPORTED Could not open the file path.
98 @retval EFI_NOT_FOUND The specified file could not be found on the
99 device or the file system could not be found on
101 @retval EFI_NO_MEDIA The device has no medium.
102 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the
103 medium is no longer supported.
104 @retval EFI_DEVICE_ERROR The device reported an error.
105 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
106 @retval EFI_WRITE_PROTECTED The file or medium is write protected.
107 @retval EFI_ACCESS_DENIED The file was opened read only.
108 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the
110 @retval EFI_VOLUME_FULL The volume is full.
114 OpenFileByDevicePath(
115 IN OUT EFI_DEVICE_PATH_PROTOCOL
**FilePath
,
116 OUT EFI_FILE_HANDLE
*FileHandle
,
122 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*EfiSimpleFileSystemProtocol
;
123 EFI_FILE_PROTOCOL
*Handle1
;
124 EFI_FILE_PROTOCOL
*Handle2
;
125 EFI_HANDLE DeviceHandle
;
127 if ((FilePath
== NULL
|| FileHandle
== NULL
)) {
128 return EFI_INVALID_PARAMETER
;
131 Status
= gBS
->LocateDevicePath (
132 &gEfiSimpleFileSystemProtocolGuid
,
136 if (EFI_ERROR (Status
)) {
140 Status
= gBS
->OpenProtocol(
142 &gEfiSimpleFileSystemProtocolGuid
,
143 (VOID
**)&EfiSimpleFileSystemProtocol
,
146 EFI_OPEN_PROTOCOL_GET_PROTOCOL
148 if (EFI_ERROR (Status
)) {
152 Status
= EfiSimpleFileSystemProtocol
->OpenVolume(EfiSimpleFileSystemProtocol
, &Handle1
);
153 if (EFI_ERROR (Status
)) {
159 // go down directories one node at a time.
161 while (!IsDevicePathEnd (*FilePath
)) {
163 // For file system access each node should be a file path component
165 if (DevicePathType (*FilePath
) != MEDIA_DEVICE_PATH
||
166 DevicePathSubType (*FilePath
) != MEDIA_FILEPATH_DP
169 return (EFI_INVALID_PARAMETER
);
172 // Open this file path node
178 // Try to test opening an existing file
180 Status
= Handle2
->Open (
183 ((FILEPATH_DEVICE_PATH
*)*FilePath
)->PathName
,
184 OpenMode
&~EFI_FILE_MODE_CREATE
,
189 // see if the error was that it needs to be created
191 if ((EFI_ERROR (Status
)) && (OpenMode
!= (OpenMode
&~EFI_FILE_MODE_CREATE
))) {
192 Status
= Handle2
->Open (
195 ((FILEPATH_DEVICE_PATH
*)*FilePath
)->PathName
,
201 // Close the last node
203 Handle2
->Close (Handle2
);
205 if (EFI_ERROR(Status
)) {
212 *FilePath
= NextDevicePathNode (*FilePath
);
216 // This is a weak spot since if the undefined SHELL_FILE_HANDLE format changes this must change also!
218 *FileHandle
= (VOID
*)Handle1
;
224 Extract filename from device path. The returned buffer is allocated using AllocateCopyPool.
225 The caller is responsible for freeing the allocated buffer using FreePool().
227 @param DevicePath Device path.
229 @return A new allocated string that represents the file name.
233 ExtractFileNameFromDevicePath (
234 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
243 ASSERT(DevicePath
!= NULL
);
245 String
= DevicePathToStr(DevicePath
);
246 MatchString
= String
;
249 while(MatchString
!= NULL
){
250 LastMatch
= MatchString
+ 1;
251 MatchString
= StrStr(LastMatch
,L
"\\");
254 Length
= StrLen(LastMatch
);
255 FileName
= AllocateCopyPool ((Length
+ 1) * sizeof(CHAR16
), LastMatch
);
256 *(FileName
+ Length
) = 0;
265 Update the form base on the selected file.
267 @param FilePath Point to the file path.
268 @param FormId The form need to display.
270 @retval TRUE Exit caller function.
271 @retval FALSE Not exit caller function.
276 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
277 IN EFI_FORM_ID FormId
281 EFI_STRING_ID StringToken
;
283 if (FilePath
!= NULL
){
284 FileName
= ExtractFileNameFromDevicePath(FilePath
);
285 StringToken
= HiiSetString (gSecureBootPrivateData
->HiiHandle
, 0, FileName
, NULL
);
287 FileName
= HiiGetString (gSecureBootPrivateData
->HiiHandle
, STRING_TOKEN (STR_NULL
), NULL
);
288 ASSERT (FileName
!= NULL
);
289 StringToken
= HiiSetString (gSecureBootPrivateData
->HiiHandle
, 0, FileName
, NULL
);
292 gSecureBootPrivateData
->FileContext
->FileName
= FileName
;
294 OpenFileByDevicePath(
296 &gSecureBootPrivateData
->FileContext
->FHandle
,
301 // Create Subtitle op-code for the display string of the option.
303 RefreshUpdateData ();
304 mStartLabel
->Number
= FormId
;
306 HiiCreateSubTitleOpCode (
315 gSecureBootPrivateData
->HiiHandle
,
316 &gSecureBootConfigFormSetGuid
,
318 mStartOpCodeHandle
, // Label FormId
319 mEndOpCodeHandle
// LABEL_END
326 Update the PK form base on the input file path info.
328 @param FilePath Point to the file path.
330 @retval TRUE Exit caller function.
331 @retval FALSE Not exit caller function.
335 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
338 return UpdatePage(FilePath
, FORMID_ENROLL_PK_FORM
);
343 Update the KEK form base on the input file path info.
345 @param FilePath Point to the file path.
347 @retval TRUE Exit caller function.
348 @retval FALSE Not exit caller function.
352 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
355 return UpdatePage(FilePath
, FORMID_ENROLL_KEK_FORM
);
359 Update the DB form base on the input file path info.
361 @param FilePath Point to the file path.
363 @retval TRUE Exit caller function.
364 @retval FALSE Not exit caller function.
368 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
371 return UpdatePage(FilePath
, SECUREBOOT_ENROLL_SIGNATURE_TO_DB
);
375 Update the DBX form base on the input file path info.
377 @param FilePath Point to the file path.
379 @retval TRUE Exit caller function.
380 @retval FALSE Not exit caller function.
384 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
387 return UpdatePage(FilePath
, SECUREBOOT_ENROLL_SIGNATURE_TO_DBX
);
391 Update the DBT form base on the input file path info.
393 @param FilePath Point to the file path.
395 @retval TRUE Exit caller function.
396 @retval FALSE Not exit caller function.
400 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
403 return UpdatePage(FilePath
, SECUREBOOT_ENROLL_SIGNATURE_TO_DBT
);