]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c
SecurityPkg: Apply uncrustify changes
[mirror_edk2.git] / SecurityPkg / VariableAuthenticated / SecureBootConfigDxe / SecureBootConfigFileExplorer.c
CommitLineData
ecc722ad 1/** @file\r
2 Internal file explorer functions for SecureBoot configuration module.\r
3\r
762d8ddb 4Copyright (c) 2012 - 2016, Intel Corporation. All rights reserved.<BR>\r
289b714b 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
ecc722ad 6\r
7**/\r
8\r
9#include "SecureBootConfigImpl.h"\r
10\r
c411b485
MK
11VOID *mStartOpCodeHandle = NULL;\r
12VOID *mEndOpCodeHandle = NULL;\r
13EFI_IFR_GUID_LABEL *mStartLabel = NULL;\r
14EFI_IFR_GUID_LABEL *mEndLabel = NULL;\r
ecc722ad 15\r
16/**\r
762d8ddb 17 Refresh the global UpdateData structure.\r
ecc722ad 18\r
19**/\r
762d8ddb
DB
20VOID\r
21RefreshUpdateData (\r
22 VOID\r
ecc722ad 23 )\r
24{\r
ecc722ad 25 //\r
762d8ddb 26 // Free current updated date\r
ecc722ad 27 //\r
762d8ddb
DB
28 if (mStartOpCodeHandle != NULL) {\r
29 HiiFreeOpCodeHandle (mStartOpCodeHandle);\r
ecc722ad 30 }\r
ecc722ad 31\r
ecc722ad 32 //\r
762d8ddb 33 // Create new OpCode Handle\r
ecc722ad 34 //\r
762d8ddb 35 mStartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
ecc722ad 36\r
37 //\r
762d8ddb 38 // Create Hii Extend Label OpCode as the start opcode\r
ecc722ad 39 //\r
c411b485
MK
40 mStartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (\r
41 mStartOpCodeHandle,\r
42 &gEfiIfrTianoGuid,\r
43 NULL,\r
44 sizeof (EFI_IFR_GUID_LABEL)\r
45 );\r
762d8ddb 46 mStartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
ecc722ad 47}\r
48\r
49/**\r
762d8ddb 50 Clean up the dynamic opcode at label and form specified by both LabelId.\r
ecc722ad 51\r
762d8ddb
DB
52 @param[in] LabelId It is both the Form ID and Label ID for opcode deletion.\r
53 @param[in] PrivateData Module private data.\r
20333c6d 54\r
ecc722ad 55**/\r
56VOID\r
762d8ddb 57CleanUpPage (\r
c411b485
MK
58 IN UINT16 LabelId,\r
59 IN SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData\r
ecc722ad 60 )\r
61{\r
762d8ddb 62 RefreshUpdateData ();\r
ecc722ad 63\r
64 //\r
762d8ddb 65 // Remove all op-codes from dynamic page\r
ecc722ad 66 //\r
762d8ddb
DB
67 mStartLabel->Number = LabelId;\r
68 HiiUpdateForm (\r
69 PrivateData->HiiHandle,\r
70 &gSecureBootConfigFormSetGuid,\r
71 LabelId,\r
72 mStartOpCodeHandle, // Label LabelId\r
73 mEndOpCodeHandle // LABEL_END\r
74 );\r
ecc722ad 75}\r
76\r
ecc722ad 77/**\r
762d8ddb 78 Extract filename from device path. The returned buffer is allocated using AllocateCopyPool.\r
ed2992b3
DB
79 The caller is responsible for freeing the allocated buffer using FreePool(). If return NULL\r
80 means not enough memory resource.\r
ecc722ad 81\r
762d8ddb 82 @param DevicePath Device path.\r
ecc722ad 83\r
ba562ca0 84 @retval NULL Not enough memory resource for AllocateCopyPool.\r
ed2992b3 85 @retval Other A new allocated string that represents the file name.\r
ecc722ad 86\r
87**/\r
762d8ddb
DB
88CHAR16 *\r
89ExtractFileNameFromDevicePath (\r
c411b485 90 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
ecc722ad 91 )\r
92{\r
c411b485
MK
93 CHAR16 *String;\r
94 CHAR16 *MatchString;\r
95 CHAR16 *LastMatch;\r
96 CHAR16 *FileName;\r
97 UINTN Length;\r
ecc722ad 98\r
c411b485 99 ASSERT (DevicePath != NULL);\r
ecc722ad 100\r
c411b485 101 String = DevicePathToStr (DevicePath);\r
762d8ddb
DB
102 MatchString = String;\r
103 LastMatch = String;\r
ed2992b3 104 FileName = NULL;\r
ecc722ad 105\r
c411b485 106 while (MatchString != NULL) {\r
762d8ddb 107 LastMatch = MatchString + 1;\r
c411b485 108 MatchString = StrStr (LastMatch, L"\\");\r
ecc722ad 109 }\r
110\r
c411b485
MK
111 Length = StrLen (LastMatch);\r
112 FileName = AllocateCopyPool ((Length + 1) * sizeof (CHAR16), LastMatch);\r
ed2992b3
DB
113 if (FileName != NULL) {\r
114 *(FileName + Length) = 0;\r
115 }\r
ecc722ad 116\r
c411b485 117 FreePool (String);\r
20333c6d 118\r
762d8ddb 119 return FileName;\r
ecc722ad 120}\r
121\r
ecc722ad 122/**\r
762d8ddb 123 Update the form base on the selected file.\r
ecc722ad 124\r
762d8ddb
DB
125 @param FilePath Point to the file path.\r
126 @param FormId The form need to display.\r
ecc722ad 127\r
762d8ddb
DB
128 @retval TRUE Exit caller function.\r
129 @retval FALSE Not exit caller function.\r
ecc722ad 130\r
131**/\r
762d8ddb 132BOOLEAN\r
c411b485 133UpdatePage (\r
762d8ddb
DB
134 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r
135 IN EFI_FORM_ID FormId\r
ecc722ad 136 )\r
137{\r
c411b485
MK
138 CHAR16 *FileName;\r
139 EFI_STRING_ID StringToken;\r
ecc722ad 140\r
ed2992b3
DB
141 FileName = NULL;\r
142\r
143 if (FilePath != NULL) {\r
c411b485 144 FileName = ExtractFileNameFromDevicePath (FilePath);\r
ecc722ad 145 }\r
c411b485 146\r
ed2992b3
DB
147 if (FileName == NULL) {\r
148 //\r
149 // FileName = NULL has two case:\r
150 // 1. FilePath == NULL, not select file.\r
151 // 2. FilePath != NULL, but ExtractFileNameFromDevicePath return NULL not enough memory resource.\r
152 // In these two case, no need to update the form, and exit the caller function.\r
153 //\r
154 return TRUE;\r
155 }\r
c411b485 156\r
ed2992b3 157 StringToken = HiiSetString (gSecureBootPrivateData->HiiHandle, 0, FileName, NULL);\r
ecc722ad 158\r
762d8ddb 159 gSecureBootPrivateData->FileContext->FileName = FileName;\r
20333c6d 160\r
1bf50074 161 EfiOpenFileByDevicePath (\r
762d8ddb
DB
162 &FilePath,\r
163 &gSecureBootPrivateData->FileContext->FHandle,\r
164 EFI_FILE_MODE_READ,\r
165 0\r
166 );\r
ecc722ad 167 //\r
762d8ddb 168 // Create Subtitle op-code for the display string of the option.\r
ecc722ad 169 //\r
762d8ddb
DB
170 RefreshUpdateData ();\r
171 mStartLabel->Number = FormId;\r
ecc722ad 172\r
762d8ddb
DB
173 HiiCreateSubTitleOpCode (\r
174 mStartOpCodeHandle,\r
175 StringToken,\r
176 0,\r
177 0,\r
178 0\r
c411b485 179 );\r
762d8ddb
DB
180\r
181 HiiUpdateForm (\r
182 gSecureBootPrivateData->HiiHandle,\r
183 &gSecureBootConfigFormSetGuid,\r
184 FormId,\r
185 mStartOpCodeHandle, // Label FormId\r
186 mEndOpCodeHandle // LABEL_END\r
187 );\r
188\r
189 return TRUE;\r
ecc722ad 190}\r
191\r
192/**\r
762d8ddb 193 Update the PK form base on the input file path info.\r
ecc722ad 194\r
762d8ddb
DB
195 @param FilePath Point to the file path.\r
196\r
197 @retval TRUE Exit caller function.\r
198 @retval FALSE Not exit caller function.\r
ecc722ad 199**/\r
762d8ddb 200BOOLEAN\r
bac308be 201EFIAPI\r
762d8ddb 202UpdatePKFromFile (\r
c411b485 203 IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r
ecc722ad 204 )\r
205{\r
c411b485 206 return UpdatePage (FilePath, FORMID_ENROLL_PK_FORM);\r
ecc722ad 207}\r
208\r
209/**\r
762d8ddb 210 Update the KEK form base on the input file path info.\r
ecc722ad 211\r
762d8ddb 212 @param FilePath Point to the file path.\r
ecc722ad 213\r
762d8ddb
DB
214 @retval TRUE Exit caller function.\r
215 @retval FALSE Not exit caller function.\r
ecc722ad 216**/\r
762d8ddb 217BOOLEAN\r
bac308be 218EFIAPI\r
762d8ddb 219UpdateKEKFromFile (\r
c411b485 220 IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r
ecc722ad 221 )\r
222{\r
c411b485 223 return UpdatePage (FilePath, FORMID_ENROLL_KEK_FORM);\r
ecc722ad 224}\r
225\r
226/**\r
762d8ddb 227 Update the DB form base on the input file path info.\r
ecc722ad 228\r
762d8ddb 229 @param FilePath Point to the file path.\r
ecc722ad 230\r
762d8ddb
DB
231 @retval TRUE Exit caller function.\r
232 @retval FALSE Not exit caller function.\r
ecc722ad 233**/\r
234BOOLEAN\r
bac308be 235EFIAPI\r
762d8ddb 236UpdateDBFromFile (\r
c411b485 237 IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r
ecc722ad 238 )\r
239{\r
c411b485 240 return UpdatePage (FilePath, SECUREBOOT_ENROLL_SIGNATURE_TO_DB);\r
762d8ddb 241}\r
ecc722ad 242\r
762d8ddb
DB
243/**\r
244 Update the DBX form base on the input file path info.\r
ecc722ad 245\r
762d8ddb 246 @param FilePath Point to the file path.\r
ecc722ad 247\r
762d8ddb
DB
248 @retval TRUE Exit caller function.\r
249 @retval FALSE Not exit caller function.\r
250**/\r
251BOOLEAN\r
bac308be 252EFIAPI\r
762d8ddb 253UpdateDBXFromFile (\r
c411b485 254 IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r
762d8ddb
DB
255 )\r
256{\r
c411b485 257 return UpdatePage (FilePath, SECUREBOOT_ENROLL_SIGNATURE_TO_DBX);\r
ecc722ad 258}\r
259\r
260/**\r
762d8ddb 261 Update the DBT form base on the input file path info.\r
ecc722ad 262\r
762d8ddb 263 @param FilePath Point to the file path.\r
ecc722ad 264\r
762d8ddb
DB
265 @retval TRUE Exit caller function.\r
266 @retval FALSE Not exit caller function.\r
ecc722ad 267**/\r
762d8ddb 268BOOLEAN\r
bac308be 269EFIAPI\r
762d8ddb 270UpdateDBTFromFile (\r
c411b485 271 IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r
ecc722ad 272 )\r
273{\r
c411b485 274 return UpdatePage (FilePath, SECUREBOOT_ENROLL_SIGNATURE_TO_DBT);\r
ecc722ad 275}\r