]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Tcg/TrEEConfig/TrEEConfigImpl.c
SecurityPkg: Tcg2Dxe: Report correct FinalEventLog size
[mirror_edk2.git] / SecurityPkg / Tcg / TrEEConfig / TrEEConfigImpl.c
CommitLineData
c1d93242
JY
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
56dea5e1 5Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>\r
c1d93242
JY
6This program and the accompanying materials \r
7are licensed and made available under the terms and conditions of the BSD License \r
8which accompanies this distribution. The full text of the license may be found at \r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
12WITHOUT 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
21TPM_INSTANCE_ID mTpmInstanceId[TPM_DEVICE_MAX + 1] = TPM_INSTANCE_ID_LIST;\r
22\r
23TREE_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
32HII_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
80EFI_STATUS\r
81EFIAPI\r
82TrEEExtractConfig (\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
56dea5e1
ED
89 if (Progress == NULL || Results == NULL) {\r
90 return EFI_INVALID_PARAMETER;\r
91 }\r
92\r
93 *Progress = Request;\r
94 return EFI_NOT_FOUND;\r
c1d93242
JY
95}\r
96\r
97/**\r
98 Save TPM request to variable space.\r
99\r
100 @param[in] PpRequest Physical Presence request command.\r
101\r
102 @retval EFI_SUCCESS The operation is finished successfully.\r
103 @retval Others Other errors as indicated.\r
104\r
105**/\r
106EFI_STATUS\r
107SaveTrEEPpRequest (\r
108 IN UINT8 PpRequest\r
109 )\r
110{\r
111 EFI_STATUS Status;\r
112 UINTN DataSize;\r
113 EFI_TREE_PHYSICAL_PRESENCE PpData;\r
114\r
115 //\r
116 // Save TPM command to variable.\r
117 //\r
118 DataSize = sizeof (EFI_TREE_PHYSICAL_PRESENCE);\r
119 Status = gRT->GetVariable (\r
120 TREE_PHYSICAL_PRESENCE_VARIABLE,\r
121 &gEfiTrEEPhysicalPresenceGuid,\r
122 NULL,\r
123 &DataSize,\r
124 &PpData\r
125 );\r
126 if (EFI_ERROR (Status)) {\r
127 return Status;\r
128 } \r
129 \r
130 PpData.PPRequest = PpRequest;\r
131 Status = gRT->SetVariable (\r
132 TREE_PHYSICAL_PRESENCE_VARIABLE,\r
133 &gEfiTrEEPhysicalPresenceGuid,\r
134 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
135 DataSize,\r
136 &PpData\r
137 );\r
138 if (EFI_ERROR(Status)) {\r
139 return Status;\r
140 }\r
141\r
142 return EFI_SUCCESS;\r
143}\r
144\r
145/**\r
146 This function processes the results of changes in configuration.\r
147\r
148 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
149 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>\r
150 format.\r
151 @param[out] Progress A pointer to a string filled in with the offset of\r
152 the most recent '&' before the first failing\r
153 name/value pair (or the beginning of the string if\r
154 the failure is in the first name/value pair) or\r
155 the terminating NULL if all was successful.\r
156\r
157 @retval EFI_SUCCESS The Results is processed successfully.\r
158 @retval EFI_INVALID_PARAMETER Configuration is NULL.\r
159 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this\r
160 driver.\r
161\r
162**/\r
163EFI_STATUS\r
164EFIAPI\r
165TrEERouteConfig (\r
166 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
167 IN CONST EFI_STRING Configuration,\r
168 OUT EFI_STRING *Progress\r
169 )\r
170{\r
56dea5e1
ED
171 if (Configuration == NULL || Progress == NULL) {\r
172 return EFI_INVALID_PARAMETER;\r
173 }\r
174\r
175 return EFI_NOT_FOUND;\r
c1d93242
JY
176}\r
177\r
178/**\r
179 This function processes the results of changes in configuration.\r
180\r
181 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
182 @param[in] Action Specifies the type of action taken by the browser.\r
183 @param[in] QuestionId A unique value which is sent to the original\r
184 exporting driver so that it can identify the type\r
185 of data to expect.\r
186 @param[in] Type The type of value for the question.\r
187 @param[in] Value A pointer to the data being sent to the original\r
188 exporting driver.\r
189 @param[out] ActionRequest On return, points to the action requested by the\r
190 callback function.\r
191\r
192 @retval EFI_SUCCESS The callback successfully handled the action.\r
193 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the\r
194 variable and its data.\r
195 @retval EFI_DEVICE_ERROR The variable could not be saved.\r
196 @retval EFI_UNSUPPORTED The specified Action is not supported by the\r
197 callback.\r
198\r
199**/\r
200EFI_STATUS\r
201EFIAPI\r
202TrEECallback (\r
203 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
204 IN EFI_BROWSER_ACTION Action,\r
205 IN EFI_QUESTION_ID QuestionId,\r
206 IN UINT8 Type,\r
207 IN EFI_IFR_TYPE_VALUE *Value,\r
208 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
209 )\r
210{\r
211 if ((This == NULL) || (Value == NULL) || (ActionRequest == NULL)) {\r
212 return EFI_INVALID_PARAMETER;\r
213 }\r
5437d457
JY
214 \r
215 if (Action == EFI_BROWSER_ACTION_CHANGED) {\r
216 if (QuestionId == KEY_TPM_DEVICE) {\r
217 return EFI_SUCCESS;\r
218 }\r
219 if (QuestionId == KEY_TPM2_OPERATION) {\r
220 return SaveTrEEPpRequest (Value->u8);\r
221 }\r
c1d93242
JY
222 }\r
223\r
5437d457 224 return EFI_UNSUPPORTED;\r
c1d93242
JY
225}\r
226\r
227/**\r
228 This function publish the TREE configuration Form for TPM device.\r
229\r
230 @param[in, out] PrivateData Points to TREE configuration private data.\r
231\r
232 @retval EFI_SUCCESS HII Form is installed for this network device.\r
233 @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.\r
234 @retval Others Other errors as indicated.\r
235\r
236**/\r
237EFI_STATUS\r
238InstallTrEEConfigForm (\r
239 IN OUT TREE_CONFIG_PRIVATE_DATA *PrivateData\r
240 )\r
241{\r
242 EFI_STATUS Status;\r
243 EFI_HII_HANDLE HiiHandle;\r
244 EFI_HANDLE DriverHandle;\r
245 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r
246\r
247 DriverHandle = NULL;\r
248 ConfigAccess = &PrivateData->ConfigAccess;\r
249 Status = gBS->InstallMultipleProtocolInterfaces (\r
250 &DriverHandle,\r
251 &gEfiDevicePathProtocolGuid,\r
252 &mTrEEHiiVendorDevicePath,\r
253 &gEfiHiiConfigAccessProtocolGuid,\r
254 ConfigAccess,\r
255 NULL\r
256 );\r
257 if (EFI_ERROR (Status)) {\r
258 return Status;\r
259 }\r
260\r
261 PrivateData->DriverHandle = DriverHandle;\r
262\r
263 //\r
264 // Publish the HII package list\r
265 //\r
266 HiiHandle = HiiAddPackages (\r
267 &gTrEEConfigFormSetGuid,\r
268 DriverHandle,\r
269 TrEEConfigDxeStrings,\r
270 TrEEConfigBin,\r
271 NULL\r
272 );\r
273 if (HiiHandle == NULL) {\r
274 gBS->UninstallMultipleProtocolInterfaces (\r
275 DriverHandle,\r
276 &gEfiDevicePathProtocolGuid,\r
277 &mTrEEHiiVendorDevicePath,\r
278 &gEfiHiiConfigAccessProtocolGuid,\r
279 ConfigAccess,\r
280 NULL\r
281 ); \r
282\r
283 return EFI_OUT_OF_RESOURCES;\r
284 }\r
285 \r
286 PrivateData->HiiHandle = HiiHandle;\r
287\r
5437d457
JY
288 //\r
289 // Update static data\r
290 //\r
291 switch (PrivateData->TpmDeviceDetected) {\r
292 case TPM_DEVICE_NULL:\r
293 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TREE_DEVICE_STATE_CONTENT), L"Not Found", NULL);\r
294 break;\r
295 case TPM_DEVICE_1_2:\r
296 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TREE_DEVICE_STATE_CONTENT), L"TPM 1.2", NULL);\r
297 break;\r
298 case TPM_DEVICE_2_0_DTPM:\r
299 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TREE_DEVICE_STATE_CONTENT), L"TPM 2.0 (DTPM)", NULL);\r
300 break;\r
301 default:\r
302 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TREE_DEVICE_STATE_CONTENT), L"Unknown", NULL);\r
303 break;\r
304 }\r
305\r
c1d93242
JY
306 return EFI_SUCCESS; \r
307}\r
308\r
309/**\r
310 This function removes TREE configuration Form.\r
311\r
312 @param[in, out] PrivateData Points to TREE configuration private data.\r
313\r
314**/\r
315VOID\r
316UninstallTrEEConfigForm (\r
317 IN OUT TREE_CONFIG_PRIVATE_DATA *PrivateData\r
318 )\r
319{\r
320 //\r
321 // Uninstall HII package list\r
322 //\r
323 if (PrivateData->HiiHandle != NULL) {\r
324 HiiRemovePackages (PrivateData->HiiHandle);\r
325 PrivateData->HiiHandle = NULL;\r
326 }\r
327\r
328 //\r
329 // Uninstall HII Config Access Protocol\r
330 //\r
331 if (PrivateData->DriverHandle != NULL) {\r
332 gBS->UninstallMultipleProtocolInterfaces (\r
333 PrivateData->DriverHandle,\r
334 &gEfiDevicePathProtocolGuid,\r
335 &mTrEEHiiVendorDevicePath,\r
336 &gEfiHiiConfigAccessProtocolGuid,\r
337 &PrivateData->ConfigAccess,\r
338 NULL\r
339 );\r
340 PrivateData->DriverHandle = NULL;\r
341 }\r
342 \r
343 FreePool (PrivateData);\r
344}\r