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