]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | HII Config Access protocol implementation of TREE configuration module.\r | |
3 | NOTE: This module is only for reference only, each platform should have its own setup page.\r | |
4 | \r | |
5 | Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r | |
6 | This program and the accompanying materials \r | |
7 | are licensed and made available under the terms and conditions of the BSD License \r | |
8 | which accompanies this distribution. The full text of the license may be found at \r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include "TrEEConfigImpl.h"\r | |
17 | #include <Library/PcdLib.h>\r | |
18 | #include <Library/Tpm2CommandLib.h>\r | |
19 | #include <Guid/TpmInstance.h>\r | |
20 | \r | |
21 | TPM_INSTANCE_ID mTpmInstanceId[TPM_DEVICE_MAX + 1] = TPM_INSTANCE_ID_LIST;\r | |
22 | \r | |
23 | TREE_CONFIG_PRIVATE_DATA mTrEEConfigPrivateDateTemplate = {\r | |
24 | TREE_CONFIG_PRIVATE_DATA_SIGNATURE,\r | |
25 | {\r | |
26 | TrEEExtractConfig,\r | |
27 | TrEERouteConfig,\r | |
28 | TrEECallback\r | |
29 | }\r | |
30 | };\r | |
31 | \r | |
32 | HII_VENDOR_DEVICE_PATH mTrEEHiiVendorDevicePath = {\r | |
33 | {\r | |
34 | {\r | |
35 | HARDWARE_DEVICE_PATH,\r | |
36 | HW_VENDOR_DP,\r | |
37 | {\r | |
38 | (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r | |
39 | (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r | |
40 | }\r | |
41 | },\r | |
42 | TREE_CONFIG_FORM_SET_GUID\r | |
43 | },\r | |
44 | {\r | |
45 | END_DEVICE_PATH_TYPE,\r | |
46 | END_ENTIRE_DEVICE_PATH_SUBTYPE,\r | |
47 | { \r | |
48 | (UINT8) (END_DEVICE_PATH_LENGTH),\r | |
49 | (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r | |
50 | }\r | |
51 | }\r | |
52 | };\r | |
53 | \r | |
54 | /**\r | |
55 | This function allows a caller to extract the current configuration for one\r | |
56 | or more named elements from the target driver.\r | |
57 | \r | |
58 | @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
59 | @param[in] Request A null-terminated Unicode string in\r | |
60 | <ConfigRequest> format.\r | |
61 | @param[out] Progress On return, points to a character in the Request\r | |
62 | string. Points to the string's null terminator if\r | |
63 | request was successful. Points to the most recent\r | |
64 | '&' before the first failing name/value pair (or\r | |
65 | the beginning of the string if the failure is in\r | |
66 | the first name/value pair) if the request was not\r | |
67 | successful.\r | |
68 | @param[out] Results A null-terminated Unicode string in\r | |
69 | <ConfigAltResp> format which has all values filled\r | |
70 | in for the names in the Request string. String to\r | |
71 | be allocated by the called function.\r | |
72 | \r | |
73 | @retval EFI_SUCCESS The Results is filled with the requested values.\r | |
74 | @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r | |
75 | @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.\r | |
76 | @retval EFI_NOT_FOUND Routing data doesn't match any storage in this\r | |
77 | driver.\r | |
78 | \r | |
79 | **/\r | |
80 | EFI_STATUS\r | |
81 | EFIAPI\r | |
82 | TrEEExtractConfig (\r | |
83 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
84 | IN CONST EFI_STRING Request,\r | |
85 | OUT EFI_STRING *Progress,\r | |
86 | OUT EFI_STRING *Results\r | |
87 | )\r | |
88 | {\r | |
89 | EFI_STATUS Status;\r | |
90 | UINTN BufferSize;\r | |
91 | TREE_CONFIGURATION Configuration;\r | |
92 | TREE_CONFIG_PRIVATE_DATA *PrivateData;\r | |
93 | EFI_STRING ConfigRequestHdr;\r | |
94 | EFI_STRING ConfigRequest;\r | |
95 | BOOLEAN AllocatedRequest;\r | |
96 | UINTN Size;\r | |
97 | UINTN Index;\r | |
98 | \r | |
99 | if (Progress == NULL || Results == NULL) {\r | |
100 | return EFI_INVALID_PARAMETER;\r | |
101 | }\r | |
102 | \r | |
103 | *Progress = Request;\r | |
104 | if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &gTrEEConfigFormSetGuid, TREE_STORAGE_NAME)) {\r | |
105 | return EFI_NOT_FOUND;\r | |
106 | }\r | |
107 | \r | |
108 | ConfigRequestHdr = NULL;\r | |
109 | ConfigRequest = NULL;\r | |
110 | AllocatedRequest = FALSE;\r | |
111 | Size = 0;\r | |
112 | \r | |
113 | PrivateData = TREE_CONFIG_PRIVATE_DATA_FROM_THIS (This);\r | |
114 | \r | |
115 | //\r | |
116 | // Convert buffer data to <ConfigResp> by helper function BlockToConfig()\r | |
117 | // \r | |
118 | BufferSize = sizeof (Configuration);\r | |
119 | Status = gRT->GetVariable (\r | |
120 | TREE_STORAGE_NAME,\r | |
121 | &gTrEEConfigFormSetGuid,\r | |
122 | NULL,\r | |
123 | &BufferSize,\r | |
124 | &Configuration\r | |
125 | );\r | |
126 | ASSERT_EFI_ERROR (Status);\r | |
127 | \r | |
128 | //\r | |
129 | // Get data from PCD to make sure data consistant - platform driver is suppose to construct this PCD accroding to Variable\r | |
130 | //\r | |
131 | for (Index = 0; Index < sizeof(mTpmInstanceId)/sizeof(mTpmInstanceId[0]); Index++) {\r | |
132 | if (CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &mTpmInstanceId[Index].TpmInstanceGuid)) {\r | |
133 | Configuration.TpmDevice = mTpmInstanceId[Index].TpmDevice;\r | |
134 | break;\r | |
135 | }\r | |
136 | }\r | |
137 | \r | |
138 | BufferSize = sizeof (Configuration);\r | |
139 | ConfigRequest = Request;\r | |
140 | if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {\r | |
141 | //\r | |
142 | // Request has no request element, construct full request string.\r | |
143 | // Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r | |
144 | // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r | |
145 | //\r | |
146 | ConfigRequestHdr = HiiConstructConfigHdr (&gTrEEConfigFormSetGuid, TREE_STORAGE_NAME, PrivateData->DriverHandle);\r | |
147 | Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r | |
148 | ConfigRequest = AllocateZeroPool (Size);\r | |
149 | ASSERT (ConfigRequest != NULL);\r | |
150 | AllocatedRequest = TRUE;\r | |
151 | UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64) BufferSize);\r | |
152 | FreePool (ConfigRequestHdr);\r | |
153 | }\r | |
154 | \r | |
155 | Status = gHiiConfigRouting->BlockToConfig (\r | |
156 | gHiiConfigRouting,\r | |
157 | ConfigRequest,\r | |
158 | (UINT8 *) &Configuration,\r | |
159 | BufferSize,\r | |
160 | Results,\r | |
161 | Progress\r | |
162 | );\r | |
163 | //\r | |
164 | // Free the allocated config request string.\r | |
165 | //\r | |
166 | if (AllocatedRequest) {\r | |
167 | FreePool (ConfigRequest);\r | |
168 | }\r | |
169 | //\r | |
170 | // Set Progress string to the original request string.\r | |
171 | //\r | |
172 | if (Request == NULL) {\r | |
173 | *Progress = NULL;\r | |
174 | } else if (StrStr (Request, L"OFFSET") == NULL) {\r | |
175 | *Progress = Request + StrLen (Request);\r | |
176 | }\r | |
177 | \r | |
178 | return Status;\r | |
179 | }\r | |
180 | \r | |
181 | /**\r | |
182 | Save TPM request to variable space.\r | |
183 | \r | |
184 | @param[in] PpRequest Physical Presence request command.\r | |
185 | \r | |
186 | @retval EFI_SUCCESS The operation is finished successfully.\r | |
187 | @retval Others Other errors as indicated.\r | |
188 | \r | |
189 | **/\r | |
190 | EFI_STATUS\r | |
191 | SaveTrEEPpRequest (\r | |
192 | IN UINT8 PpRequest\r | |
193 | )\r | |
194 | {\r | |
195 | EFI_STATUS Status;\r | |
196 | UINTN DataSize;\r | |
197 | EFI_TREE_PHYSICAL_PRESENCE PpData;\r | |
198 | \r | |
199 | //\r | |
200 | // Save TPM command to variable.\r | |
201 | //\r | |
202 | DataSize = sizeof (EFI_TREE_PHYSICAL_PRESENCE);\r | |
203 | Status = gRT->GetVariable (\r | |
204 | TREE_PHYSICAL_PRESENCE_VARIABLE,\r | |
205 | &gEfiTrEEPhysicalPresenceGuid,\r | |
206 | NULL,\r | |
207 | &DataSize,\r | |
208 | &PpData\r | |
209 | );\r | |
210 | if (EFI_ERROR (Status)) {\r | |
211 | return Status;\r | |
212 | } \r | |
213 | \r | |
214 | PpData.PPRequest = PpRequest;\r | |
215 | Status = gRT->SetVariable (\r | |
216 | TREE_PHYSICAL_PRESENCE_VARIABLE,\r | |
217 | &gEfiTrEEPhysicalPresenceGuid,\r | |
218 | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r | |
219 | DataSize,\r | |
220 | &PpData\r | |
221 | );\r | |
222 | if (EFI_ERROR(Status)) {\r | |
223 | return Status;\r | |
224 | }\r | |
225 | \r | |
226 | return EFI_SUCCESS;\r | |
227 | }\r | |
228 | \r | |
229 | /**\r | |
230 | This function processes the results of changes in configuration.\r | |
231 | \r | |
232 | @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
233 | @param[in] Configuration A null-terminated Unicode string in <ConfigResp>\r | |
234 | format.\r | |
235 | @param[out] Progress A pointer to a string filled in with the offset of\r | |
236 | the most recent '&' before the first failing\r | |
237 | name/value pair (or the beginning of the string if\r | |
238 | the failure is in the first name/value pair) or\r | |
239 | the terminating NULL if all was successful.\r | |
240 | \r | |
241 | @retval EFI_SUCCESS The Results is processed successfully.\r | |
242 | @retval EFI_INVALID_PARAMETER Configuration is NULL.\r | |
243 | @retval EFI_NOT_FOUND Routing data doesn't match any storage in this\r | |
244 | driver.\r | |
245 | \r | |
246 | **/\r | |
247 | EFI_STATUS\r | |
248 | EFIAPI\r | |
249 | TrEERouteConfig (\r | |
250 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
251 | IN CONST EFI_STRING Configuration,\r | |
252 | OUT EFI_STRING *Progress\r | |
253 | )\r | |
254 | {\r | |
255 | EFI_STATUS Status;\r | |
256 | UINTN BufferSize;\r | |
257 | TREE_CONFIGURATION TrEEConfiguration;\r | |
258 | \r | |
259 | if (Configuration == NULL || Progress == NULL) {\r | |
260 | return EFI_INVALID_PARAMETER;\r | |
261 | }\r | |
262 | \r | |
263 | *Progress = Configuration;\r | |
264 | if (!HiiIsConfigHdrMatch (Configuration, &gTrEEConfigFormSetGuid, TREE_STORAGE_NAME)) {\r | |
265 | return EFI_NOT_FOUND;\r | |
266 | }\r | |
267 | \r | |
268 | BufferSize = sizeof (TrEEConfiguration);\r | |
269 | Status = gRT->GetVariable (\r | |
270 | TREE_STORAGE_NAME,\r | |
271 | &gTrEEConfigFormSetGuid,\r | |
272 | NULL,\r | |
273 | &BufferSize,\r | |
274 | &TrEEConfiguration\r | |
275 | );\r | |
276 | ASSERT_EFI_ERROR (Status);\r | |
277 | \r | |
278 | //\r | |
279 | // Convert <ConfigResp> to buffer data by helper function ConfigToBlock()\r | |
280 | //\r | |
281 | BufferSize = sizeof (TREE_CONFIGURATION);\r | |
282 | Status = gHiiConfigRouting->ConfigToBlock (\r | |
283 | gHiiConfigRouting,\r | |
284 | Configuration,\r | |
285 | (UINT8 *) &TrEEConfiguration,\r | |
286 | &BufferSize,\r | |
287 | Progress\r | |
288 | );\r | |
289 | if (EFI_ERROR (Status)) {\r | |
290 | return Status;\r | |
291 | }\r | |
292 | \r | |
293 | //\r | |
294 | // Save to variable so platform driver can get it.\r | |
295 | //\r | |
296 | Status = gRT->SetVariable (\r | |
297 | TREE_STORAGE_NAME,\r | |
298 | &gTrEEConfigFormSetGuid,\r | |
299 | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r | |
300 | sizeof(TrEEConfiguration),\r | |
301 | &TrEEConfiguration\r | |
302 | );\r | |
303 | \r | |
304 | SaveTrEEPpRequest (TrEEConfiguration.Tpm2Operation\r | |
305 | );\r | |
306 | \r | |
307 | return Status;\r | |
308 | }\r | |
309 | \r | |
310 | /**\r | |
311 | This function processes the results of changes in configuration.\r | |
312 | \r | |
313 | @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
314 | @param[in] Action Specifies the type of action taken by the browser.\r | |
315 | @param[in] QuestionId A unique value which is sent to the original\r | |
316 | exporting driver so that it can identify the type\r | |
317 | of data to expect.\r | |
318 | @param[in] Type The type of value for the question.\r | |
319 | @param[in] Value A pointer to the data being sent to the original\r | |
320 | exporting driver.\r | |
321 | @param[out] ActionRequest On return, points to the action requested by the\r | |
322 | callback function.\r | |
323 | \r | |
324 | @retval EFI_SUCCESS The callback successfully handled the action.\r | |
325 | @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the\r | |
326 | variable and its data.\r | |
327 | @retval EFI_DEVICE_ERROR The variable could not be saved.\r | |
328 | @retval EFI_UNSUPPORTED The specified Action is not supported by the\r | |
329 | callback.\r | |
330 | \r | |
331 | **/\r | |
332 | EFI_STATUS\r | |
333 | EFIAPI\r | |
334 | TrEECallback (\r | |
335 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
336 | IN EFI_BROWSER_ACTION Action,\r | |
337 | IN EFI_QUESTION_ID QuestionId,\r | |
338 | IN UINT8 Type,\r | |
339 | IN EFI_IFR_TYPE_VALUE *Value,\r | |
340 | OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r | |
341 | )\r | |
342 | {\r | |
343 | if ((This == NULL) || (Value == NULL) || (ActionRequest == NULL)) {\r | |
344 | return EFI_INVALID_PARAMETER;\r | |
345 | }\r | |
346 | \r | |
347 | if ((Action != EFI_BROWSER_ACTION_CHANGED) ||\r | |
348 | (QuestionId != KEY_TPM_DEVICE)) {\r | |
349 | return EFI_UNSUPPORTED;\r | |
350 | }\r | |
351 | \r | |
352 | return EFI_SUCCESS;\r | |
353 | }\r | |
354 | \r | |
355 | /**\r | |
356 | This function publish the TREE configuration Form for TPM device.\r | |
357 | \r | |
358 | @param[in, out] PrivateData Points to TREE configuration private data.\r | |
359 | \r | |
360 | @retval EFI_SUCCESS HII Form is installed for this network device.\r | |
361 | @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.\r | |
362 | @retval Others Other errors as indicated.\r | |
363 | \r | |
364 | **/\r | |
365 | EFI_STATUS\r | |
366 | InstallTrEEConfigForm (\r | |
367 | IN OUT TREE_CONFIG_PRIVATE_DATA *PrivateData\r | |
368 | )\r | |
369 | {\r | |
370 | EFI_STATUS Status;\r | |
371 | EFI_HII_HANDLE HiiHandle;\r | |
372 | EFI_HANDLE DriverHandle;\r | |
373 | EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r | |
374 | \r | |
375 | DriverHandle = NULL;\r | |
376 | ConfigAccess = &PrivateData->ConfigAccess;\r | |
377 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
378 | &DriverHandle,\r | |
379 | &gEfiDevicePathProtocolGuid,\r | |
380 | &mTrEEHiiVendorDevicePath,\r | |
381 | &gEfiHiiConfigAccessProtocolGuid,\r | |
382 | ConfigAccess,\r | |
383 | NULL\r | |
384 | );\r | |
385 | if (EFI_ERROR (Status)) {\r | |
386 | return Status;\r | |
387 | }\r | |
388 | \r | |
389 | PrivateData->DriverHandle = DriverHandle;\r | |
390 | \r | |
391 | //\r | |
392 | // Publish the HII package list\r | |
393 | //\r | |
394 | HiiHandle = HiiAddPackages (\r | |
395 | &gTrEEConfigFormSetGuid,\r | |
396 | DriverHandle,\r | |
397 | TrEEConfigDxeStrings,\r | |
398 | TrEEConfigBin,\r | |
399 | NULL\r | |
400 | );\r | |
401 | if (HiiHandle == NULL) {\r | |
402 | gBS->UninstallMultipleProtocolInterfaces (\r | |
403 | DriverHandle,\r | |
404 | &gEfiDevicePathProtocolGuid,\r | |
405 | &mTrEEHiiVendorDevicePath,\r | |
406 | &gEfiHiiConfigAccessProtocolGuid,\r | |
407 | ConfigAccess,\r | |
408 | NULL\r | |
409 | ); \r | |
410 | \r | |
411 | return EFI_OUT_OF_RESOURCES;\r | |
412 | }\r | |
413 | \r | |
414 | PrivateData->HiiHandle = HiiHandle;\r | |
415 | \r | |
416 | return EFI_SUCCESS; \r | |
417 | }\r | |
418 | \r | |
419 | /**\r | |
420 | This function removes TREE configuration Form.\r | |
421 | \r | |
422 | @param[in, out] PrivateData Points to TREE configuration private data.\r | |
423 | \r | |
424 | **/\r | |
425 | VOID\r | |
426 | UninstallTrEEConfigForm (\r | |
427 | IN OUT TREE_CONFIG_PRIVATE_DATA *PrivateData\r | |
428 | )\r | |
429 | {\r | |
430 | //\r | |
431 | // Uninstall HII package list\r | |
432 | //\r | |
433 | if (PrivateData->HiiHandle != NULL) {\r | |
434 | HiiRemovePackages (PrivateData->HiiHandle);\r | |
435 | PrivateData->HiiHandle = NULL;\r | |
436 | }\r | |
437 | \r | |
438 | //\r | |
439 | // Uninstall HII Config Access Protocol\r | |
440 | //\r | |
441 | if (PrivateData->DriverHandle != NULL) {\r | |
442 | gBS->UninstallMultipleProtocolInterfaces (\r | |
443 | PrivateData->DriverHandle,\r | |
444 | &gEfiDevicePathProtocolGuid,\r | |
445 | &mTrEEHiiVendorDevicePath,\r | |
446 | &gEfiHiiConfigAccessProtocolGuid,\r | |
447 | &PrivateData->ConfigAccess,\r | |
448 | NULL\r | |
449 | );\r | |
450 | PrivateData->DriverHandle = NULL;\r | |
451 | }\r | |
452 | \r | |
453 | FreePool (PrivateData);\r | |
454 | }\r |