]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigImpl.c
Remove dependency on PCI Root Bridge I/O Protocol. This library should only layer...
[mirror_edk2.git] / MdeModulePkg / Universal / Network / VlanConfigDxe / VlanConfigImpl.c
CommitLineData
779ae357 1/** @file\r
2 HII Config Access protocol implementation of VLAN configuration module.\r
3\r
4Copyright (c) 2009, Intel Corporation.<BR>\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions\r
7of the BSD License which accompanies this distribution. The full\r
8text of the license may be found at<BR>\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 "VlanConfigImpl.h"\r
17\r
18EFI_GUID mVlanFormSetGuid = VLAN_CONFIG_PRIVATE_GUID;\r
19CHAR16 mVlanStorageName[] = L"VlanNvData";\r
20EFI_HII_CONFIG_ROUTING_PROTOCOL *mHiiConfigRouting = NULL;\r
21\r
22VLAN_CONFIG_PRIVATE_DATA mVlanConfigPrivateDateTemplate = {\r
23 VLAN_CONFIG_PRIVATE_DATA_SIGNATURE,\r
24 {\r
25 VlanExtractConfig,\r
26 VlanRouteConfig,\r
27 VlanCallback\r
28 }\r
29};\r
30\r
31VENDOR_DEVICE_PATH mHiiVendorDevicePathNode = {\r
32 {\r
33 HARDWARE_DEVICE_PATH,\r
34 HW_VENDOR_DP,\r
35 {\r
36 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
37 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
38 }\r
39 },\r
40 VLAN_CONFIG_PRIVATE_GUID\r
41};\r
42\r
43/**\r
44 This function allows a caller to extract the current configuration for one\r
45 or more named elements from the target driver.\r
46\r
47 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
48 @param[in] Request A null-terminated Unicode string in\r
49 <ConfigRequest> format.\r
50 @param[out] Progress On return, points to a character in the Request\r
51 string. Points to the string's null terminator if\r
52 request was successful. Points to the most recent\r
53 '&' before the first failing name/value pair (or\r
54 the beginning of the string if the failure is in\r
55 the first name/value pair) if the request was not\r
56 successful.\r
57 @param[out] Results A null-terminated Unicode string in\r
58 <ConfigAltResp> format which has all values filled\r
59 in for the names in the Request string. String to\r
60 be allocated by the called function.\r
61\r
62 @retval EFI_SUCCESS The Results is filled with the requested values.\r
63 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r
64 @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.\r
65 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this\r
66 driver.\r
67\r
68**/\r
69EFI_STATUS\r
70EFIAPI\r
71VlanExtractConfig (\r
72 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
73 IN CONST EFI_STRING Request,\r
74 OUT EFI_STRING *Progress,\r
75 OUT EFI_STRING *Results\r
76 )\r
77{\r
78 EFI_STATUS Status;\r
79 UINTN BufferSize;\r
80 VLAN_CONFIGURATION Configuration;\r
81\r
82 if (Request == NULL) {\r
83 return EFI_INVALID_PARAMETER;\r
84 }\r
85\r
86 //\r
87 // Retrieve the pointer to the UEFI HII Config Routing Protocol\r
88 //\r
89 if (mHiiConfigRouting == NULL) {\r
90 gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **) &mHiiConfigRouting);\r
91 }\r
92 ASSERT (mHiiConfigRouting != NULL);\r
93\r
94 //\r
95 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()\r
96 //\r
97 ZeroMem (&Configuration, sizeof (VLAN_CONFIGURATION));\r
98 BufferSize = sizeof (VLAN_CONFIG_PRIVATE_DATA);\r
99 Status = mHiiConfigRouting->BlockToConfig (\r
100 mHiiConfigRouting,\r
101 Request,\r
102 (UINT8 *) &Configuration,\r
103 BufferSize,\r
104 Results,\r
105 Progress\r
106 );\r
107 return Status;\r
108}\r
109\r
110\r
111/**\r
112 This function processes the results of changes in configuration.\r
113\r
114 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
115 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>\r
116 format.\r
117 @param[out] Progress A pointer to a string filled in with the offset of\r
118 the most recent '&' before the first failing\r
119 name/value pair (or the beginning of the string if\r
120 the failure is in the first name/value pair) or\r
121 the terminating NULL if all was successful.\r
122\r
123 @retval EFI_SUCCESS The Results is processed successfully.\r
124 @retval EFI_INVALID_PARAMETER Configuration is NULL.\r
125 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this\r
126 driver.\r
127\r
128**/\r
129EFI_STATUS\r
130EFIAPI\r
131VlanRouteConfig (\r
132 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
133 IN CONST EFI_STRING Configuration,\r
134 OUT EFI_STRING *Progress\r
135 )\r
136{\r
137 if (Configuration == NULL || Progress == NULL) {\r
138 return EFI_INVALID_PARAMETER;\r
139 }\r
140\r
141 *Progress = Configuration;\r
142 if (!HiiIsConfigHdrMatch (Configuration, &mVlanFormSetGuid, mVlanStorageName)) {\r
143 return EFI_NOT_FOUND;\r
144 }\r
145\r
146 *Progress = Configuration + StrLen (Configuration);\r
147 return EFI_SUCCESS;\r
148}\r
149\r
150/**\r
151 This function processes the results of changes in configuration.\r
152\r
153 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
154 @param[in] Action Specifies the type of action taken by the browser.\r
155 @param[in] QuestionId A unique value which is sent to the original\r
156 exporting driver so that it can identify the type\r
157 of data to expect.\r
158 @param[in] Type The type of value for the question.\r
159 @param[in] Value A pointer to the data being sent to the original\r
160 exporting driver.\r
161 @param[out] ActionRequest On return, points to the action requested by the\r
162 callback function.\r
163\r
164 @retval EFI_SUCCESS The callback successfully handled the action.\r
165 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the\r
166 variable and its data.\r
167 @retval EFI_DEVICE_ERROR The variable could not be saved.\r
168 @retval EFI_UNSUPPORTED The specified Action is not supported by the\r
169 callback.\r
170\r
171**/\r
172EFI_STATUS\r
173EFIAPI\r
174VlanCallback (\r
175 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
176 IN EFI_BROWSER_ACTION Action,\r
177 IN EFI_QUESTION_ID QuestionId,\r
178 IN UINT8 Type,\r
179 IN EFI_IFR_TYPE_VALUE *Value,\r
180 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
181 )\r
182{\r
183 VLAN_CONFIG_PRIVATE_DATA *PrivateData;\r
184 VLAN_CONFIGURATION *Configuration;\r
185 EFI_VLAN_CONFIG_PROTOCOL *VlanConfig;\r
186 UINTN Index;\r
187 EFI_HANDLE VlanHandle;\r
188\r
189 PrivateData = VLAN_CONFIG_PRIVATE_DATA_FROM_THIS (This);\r
190\r
191 if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {\r
192 //\r
193 // On FORM_OPEN event, update current VLAN list\r
194 //\r
195 VlanUpdateForm (PrivateData);\r
196\r
197 return EFI_SUCCESS;\r
198 }\r
199\r
200 //\r
201 // Get Browser data\r
202 //\r
203 Configuration = AllocateZeroPool (sizeof (VLAN_CONFIGURATION));\r
204 ASSERT (Configuration != NULL);\r
205 HiiGetBrowserData (&mVlanFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration);\r
206\r
207 VlanConfig = PrivateData->VlanConfig;\r
208\r
209 switch (QuestionId) {\r
210 case VLAN_ADD_QUESTION_ID:\r
211 //\r
212 // Add a VLAN\r
213 //\r
214 VlanConfig->Set (VlanConfig, Configuration->VlanId, Configuration->Priority);\r
215 VlanUpdateForm (PrivateData);\r
216\r
217 //\r
218 // Connect the newly created VLAN device\r
219 //\r
220 VlanHandle = NetLibGetVlanHandle (PrivateData->ControllerHandle, Configuration->VlanId);\r
221 if (VlanHandle == NULL) {\r
222 //\r
223 // There may be no child handle created for VLAN ID 0, connect the parent handle\r
224 //\r
225 VlanHandle = PrivateData->ControllerHandle;\r
226 }\r
227 gBS->ConnectController (VlanHandle, NULL, NULL, TRUE);\r
228\r
229 //\r
230 // Clear UI data\r
231 //\r
232 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r
233 Configuration->VlanId = 0;\r
234 Configuration->Priority = 0;\r
235 break;\r
236\r
237 case VLAN_REMOVE_QUESTION_ID:\r
238 //\r
239 // Remove VLAN\r
240 //\r
241 for (Index = 0; Index < PrivateData->NumberOfVlan; Index++) {\r
242 if (Configuration->VlanList[Index] != 0) {\r
243 //\r
244 // Checkbox is selected, need remove this VLAN\r
245 //\r
246 VlanConfig->Remove (VlanConfig, PrivateData->VlanId[Index]);\r
247 }\r
248 }\r
249\r
250 VlanUpdateForm (PrivateData);\r
251 if (PrivateData->NumberOfVlan == 0) {\r
252 //\r
253 // No VLAN device now, connect the physical NIC handle.\r
254 // Note: PrivateData->NumberOfVlan has been updated by VlanUpdateForm()\r
255 //\r
256 gBS->ConnectController (PrivateData->ControllerHandle, NULL, NULL, TRUE);\r
257 }\r
258\r
259 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r
260 ZeroMem (Configuration->VlanList, MAX_VLAN_NUMBER);\r
261 break;\r
262\r
263 default:\r
264 break;\r
265 }\r
266\r
267 HiiSetBrowserData (&mVlanFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration, NULL);\r
268 FreePool (Configuration);\r
269 return EFI_SUCCESS;\r
270}\r
271\r
272\r
273/**\r
274 This function update VLAN list in the VLAN configuration Form.\r
275\r
276 @param[in, out] PrivateData Points to VLAN configuration private data.\r
277\r
278**/\r
279VOID\r
280VlanUpdateForm (\r
281 IN OUT VLAN_CONFIG_PRIVATE_DATA *PrivateData\r
282 )\r
283{\r
284 EFI_VLAN_CONFIG_PROTOCOL *VlanConfig;\r
285 UINT16 NumberOfVlan;\r
286 UINTN Index;\r
287 EFI_VLAN_FIND_DATA *VlanData;\r
288 VOID *StartOpCodeHandle;\r
289 EFI_IFR_GUID_LABEL *StartLabel;\r
290 VOID *EndOpCodeHandle;\r
291 EFI_IFR_GUID_LABEL *EndLabel;\r
292 CHAR16 *String;\r
293 CHAR16 VlanStr[30];\r
294 CHAR16 VlanIdStr[6];\r
295 UINTN DigitalCount;\r
296 EFI_STRING_ID StringId;\r
297\r
298 //\r
299 // Find current VLAN configuration\r
300 //\r
301 VlanData = NULL;\r
302 NumberOfVlan = 0;\r
303 VlanConfig = PrivateData->VlanConfig;\r
304 VlanConfig->Find (VlanConfig, NULL, &NumberOfVlan, &VlanData);\r
305\r
306 //\r
307 // Update VLAN configuration in PrivateData\r
308 //\r
309 if (NumberOfVlan > MAX_VLAN_NUMBER) {\r
310 NumberOfVlan = MAX_VLAN_NUMBER;\r
311 }\r
312 PrivateData->NumberOfVlan = NumberOfVlan;\r
313\r
314 //\r
315 // Init OpCode Handle\r
316 //\r
317 StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
318 ASSERT (StartOpCodeHandle != NULL);\r
319\r
320 EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r
321 ASSERT (EndOpCodeHandle != NULL);\r
322\r
323 //\r
324 // Create Hii Extend Label OpCode as the start opcode\r
325 //\r
326 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (\r
327 StartOpCodeHandle,\r
328 &gEfiIfrTianoGuid,\r
329 NULL,\r
330 sizeof (EFI_IFR_GUID_LABEL)\r
331 );\r
332 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
333 StartLabel->Number = LABEL_VLAN_LIST;\r
334\r
335 //\r
336 // Create Hii Extend Label OpCode as the end opcode\r
337 //\r
338 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (\r
339 EndOpCodeHandle,\r
340 &gEfiIfrTianoGuid,\r
341 NULL,\r
342 sizeof (EFI_IFR_GUID_LABEL)\r
343 );\r
344 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
345 EndLabel->Number = LABEL_END;\r
346\r
347 ZeroMem (PrivateData->VlanId, MAX_VLAN_NUMBER);\r
348 for (Index = 0; Index < NumberOfVlan; Index++) {\r
349 String = VlanStr;\r
350\r
351 StrCpy (String, L" VLAN ID:");\r
352 String += 10;\r
353 //\r
354 // Pad VlanId string up to 4 characters with space\r
355 //\r
356 DigitalCount = UnicodeValueToString (VlanIdStr, 0, VlanData[Index].VlanId, 5);\r
357 SetMem16 (String, (4 - DigitalCount) * sizeof (CHAR16), L' ');\r
358 StrCpy (String + 4 - DigitalCount, VlanIdStr);\r
359 String += 4;\r
360\r
361 StrCpy (String, L", Priority:");\r
362 String += 11;\r
363 String += UnicodeValueToString (String, 0, VlanData[Index].Priority, 4);\r
364 *String = 0;\r
365\r
366 StringId = HiiSetString (PrivateData->HiiHandle, 0, VlanStr, NULL);\r
367 ASSERT (StringId != 0);\r
368\r
369 HiiCreateCheckBoxOpCode (\r
370 StartOpCodeHandle,\r
371 (EFI_QUESTION_ID) (VLAN_LIST_VAR_OFFSET + Index),\r
372 VLAN_CONFIGURATION_VARSTORE_ID,\r
373 (UINT16) (VLAN_LIST_VAR_OFFSET + Index),\r
374 StringId,\r
375 STRING_TOKEN (STR_VLAN_VLAN_LIST_HELP),\r
376 0,\r
377 0,\r
378 NULL\r
379 );\r
380\r
381 //\r
382 // Save VLAN id to private data\r
383 //\r
384 PrivateData->VlanId[Index] = VlanData[Index].VlanId;\r
385 }\r
386\r
387 HiiUpdateForm (\r
388 PrivateData->HiiHandle, // HII handle\r
389 &mVlanFormSetGuid, // Formset GUID\r
390 VLAN_CONFIGURATION_FORM_ID, // Form ID\r
391 StartOpCodeHandle, // Label for where to insert opcodes\r
392 EndOpCodeHandle // Replace data\r
393 );\r
394\r
395 HiiFreeOpCodeHandle (StartOpCodeHandle);\r
396 HiiFreeOpCodeHandle (EndOpCodeHandle);\r
397\r
398 if (VlanData != NULL) {\r
399 FreePool (VlanData);\r
400 }\r
401}\r
402\r
403\r
404/**\r
405 This function publish the VLAN configuration Form for a network device. The\r
406 HII Config Access protocol will be installed on a child handle of the network\r
407 device.\r
408\r
409 @param[in, out] PrivateData Points to VLAN configuration private data.\r
410\r
411 @retval EFI_SUCCESS HII Form is installed for this network device.\r
412 @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.\r
413 @retval Others Other errors as indicated.\r
414\r
415**/\r
416EFI_STATUS\r
417InstallVlanConfigForm (\r
418 IN OUT VLAN_CONFIG_PRIVATE_DATA *PrivateData\r
419 )\r
420{\r
421 EFI_STATUS Status;\r
422 EFI_HII_HANDLE HiiHandle;\r
423 EFI_HANDLE DriverHandle;\r
424 CHAR16 Str[40];\r
425 CHAR16 *MacString;\r
426 EFI_DEVICE_PATH_PROTOCOL *ChildDevicePath;\r
427 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r
428\r
429 //\r
430 // Create child handle and install HII Config Access Protocol\r
431 //\r
432 ChildDevicePath = AppendDevicePathNode (\r
433 PrivateData->ParentDevicePath,\r
434 (CONST EFI_DEVICE_PATH_PROTOCOL *) &mHiiVendorDevicePathNode\r
435 );\r
436 if (ChildDevicePath == NULL) {\r
437 return EFI_OUT_OF_RESOURCES;\r
438 }\r
439 PrivateData->ChildDevicePath = ChildDevicePath;\r
440\r
441 DriverHandle = NULL;\r
442 ConfigAccess = &PrivateData->ConfigAccess;\r
443 Status = gBS->InstallMultipleProtocolInterfaces (\r
444 &DriverHandle,\r
445 &gEfiDevicePathProtocolGuid,\r
446 ChildDevicePath,\r
447 &gEfiHiiConfigAccessProtocolGuid,\r
448 ConfigAccess,\r
449 NULL\r
450 );\r
451 if (EFI_ERROR (Status)) {\r
452 return Status;\r
453 }\r
454 PrivateData->DriverHandle = DriverHandle;\r
455\r
456 //\r
457 // Publish the HII package list\r
458 //\r
459 HiiHandle = HiiAddPackages (\r
460 &mVlanFormSetGuid,\r
461 DriverHandle,\r
462 VlanConfigDxeStrings,\r
463 VlanConfigBin,\r
464 NULL\r
465 );\r
466 if (HiiHandle == NULL) {\r
467 return EFI_OUT_OF_RESOURCES;\r
468 }\r
469 PrivateData->HiiHandle = HiiHandle;\r
470\r
471 //\r
472 // Update formset title\r
473 //\r
474 MacString = NULL;\r
475 Status = NetLibGetMacString (PrivateData->ControllerHandle, PrivateData->ImageHandle, &MacString);\r
476 if (EFI_ERROR (Status)) {\r
477 return Status;\r
478 }\r
479 PrivateData->MacString = MacString;\r
480\r
481 StrCpy (Str, L"VLAN Configuration (MAC:");\r
482 StrCat (Str, MacString);\r
483 StrCat (Str, L")");\r
484 HiiSetString (\r
485 HiiHandle,\r
486 STRING_TOKEN (STR_VLAN_FORM_SET_TITLE),\r
487 Str,\r
488 NULL\r
489 );\r
490\r
491 //\r
492 // Update form title\r
493 //\r
494 HiiSetString (\r
495 HiiHandle,\r
496 STRING_TOKEN (STR_VLAN_FORM_TITLE),\r
497 Str,\r
498 NULL\r
499 );\r
500\r
501 return EFI_SUCCESS;\r
502}\r
503\r
504/**\r
505 This function remove the VLAN configuration Form for a network device. The\r
506 child handle for HII Config Access protocol will be destroyed.\r
507\r
508 @param[in, out] PrivateData Points to VLAN configuration private data.\r
509\r
510**/\r
511VOID\r
512UninstallVlanConfigForm (\r
513 IN OUT VLAN_CONFIG_PRIVATE_DATA *PrivateData\r
514 )\r
515{\r
516 //\r
517 // Free MAC string\r
518 //\r
519 if (PrivateData->MacString != NULL) {\r
520 FreePool (PrivateData->MacString);\r
521 PrivateData->MacString = NULL;\r
522 }\r
523\r
524 //\r
525 // Uninstall HII package list\r
526 //\r
527 if (PrivateData->HiiHandle != NULL) {\r
528 HiiRemovePackages (PrivateData->HiiHandle);\r
529 PrivateData->HiiHandle = NULL;\r
530 }\r
531\r
532 //\r
533 // Uninstall HII Config Access Protocol\r
534 //\r
535 if (PrivateData->DriverHandle != NULL) {\r
536 gBS->UninstallMultipleProtocolInterfaces (\r
537 PrivateData->DriverHandle,\r
538 &gEfiDevicePathProtocolGuid,\r
539 PrivateData->ChildDevicePath,\r
540 &gEfiHiiConfigAccessProtocolGuid,\r
541 &PrivateData->ConfigAccess,\r
542 NULL\r
543 );\r
544 PrivateData->DriverHandle = NULL;\r
545\r
546 if (PrivateData->ChildDevicePath != NULL) {\r
547 FreePool (PrivateData->ChildDevicePath);\r
548 PrivateData->ChildDevicePath = NULL;\r
549 }\r
550 }\r
551}\r