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