]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/VlanConfigDxe/VlanConfigImpl.c
NetworkPkg: Apply uncrustify changes
[mirror_edk2.git] / NetworkPkg / VlanConfigDxe / VlanConfigImpl.c
CommitLineData
779ae357 1/** @file\r
2 HII Config Access protocol implementation of VLAN configuration module.\r
3\r
d1102dba 4Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
9d510e61 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
779ae357 6\r
7**/\r
8\r
9#include "VlanConfigImpl.h"\r
10\r
d1050b9d
MK
11CHAR16 mVlanStorageName[] = L"VlanNvData";\r
12EFI_HII_CONFIG_ROUTING_PROTOCOL *mHiiConfigRouting = NULL;\r
779ae357 13\r
d1050b9d 14VLAN_CONFIG_PRIVATE_DATA mVlanConfigPrivateDateTemplate = {\r
779ae357 15 VLAN_CONFIG_PRIVATE_DATA_SIGNATURE,\r
16 {\r
17 VlanExtractConfig,\r
18 VlanRouteConfig,\r
19 VlanCallback\r
20 }\r
21};\r
22\r
d1050b9d 23VENDOR_DEVICE_PATH mHiiVendorDevicePathNode = {\r
779ae357 24 {\r
25 HARDWARE_DEVICE_PATH,\r
26 HW_VENDOR_DP,\r
27 {\r
d1050b9d
MK
28 (UINT8)(sizeof (VENDOR_DEVICE_PATH)),\r
29 (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
779ae357 30 }\r
31 },\r
c8ad2d7a 32 VLAN_CONFIG_FORM_SET_GUID\r
779ae357 33};\r
34\r
35/**\r
36 This function allows a caller to extract the current configuration for one\r
37 or more named elements from the target driver.\r
38\r
39 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
40 @param[in] Request A null-terminated Unicode string in\r
41 <ConfigRequest> format.\r
42 @param[out] Progress On return, points to a character in the Request\r
43 string. Points to the string's null terminator if\r
44 request was successful. Points to the most recent\r
45 '&' before the first failing name/value pair (or\r
46 the beginning of the string if the failure is in\r
47 the first name/value pair) if the request was not\r
48 successful.\r
49 @param[out] Results A null-terminated Unicode string in\r
50 <ConfigAltResp> format which has all values filled\r
51 in for the names in the Request string. String to\r
52 be allocated by the called function.\r
53\r
54 @retval EFI_SUCCESS The Results is filled with the requested values.\r
55 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r
5a157365 56 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.\r
779ae357 57 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this\r
58 driver.\r
59\r
60**/\r
61EFI_STATUS\r
62EFIAPI\r
63VlanExtractConfig (\r
d1050b9d
MK
64 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
65 IN CONST EFI_STRING Request,\r
66 OUT EFI_STRING *Progress,\r
67 OUT EFI_STRING *Results\r
779ae357 68 )\r
69{\r
d1050b9d
MK
70 EFI_STATUS Status;\r
71 UINTN BufferSize;\r
72 VLAN_CONFIGURATION Configuration;\r
59aefb7e 73 VLAN_CONFIG_PRIVATE_DATA *PrivateData;\r
d1050b9d
MK
74 EFI_STRING ConfigRequestHdr;\r
75 EFI_STRING ConfigRequest;\r
76 BOOLEAN AllocatedRequest;\r
77 UINTN Size;\r
59aefb7e 78\r
d1050b9d 79 if ((Progress == NULL) || (Results == NULL)) {\r
779ae357 80 return EFI_INVALID_PARAMETER;\r
81 }\r
82\r
59aefb7e 83 *Progress = Request;\r
c8ad2d7a 84 if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &gVlanConfigFormSetGuid, mVlanStorageName)) {\r
59aefb7e
LG
85 return EFI_NOT_FOUND;\r
86 }\r
87\r
88 ConfigRequestHdr = NULL;\r
89 ConfigRequest = NULL;\r
90 AllocatedRequest = FALSE;\r
91 Size = 0;\r
92\r
779ae357 93 //\r
94 // Retrieve the pointer to the UEFI HII Config Routing Protocol\r
95 //\r
96 if (mHiiConfigRouting == NULL) {\r
d1050b9d 97 gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **)&mHiiConfigRouting);\r
779ae357 98 }\r
d1050b9d 99\r
779ae357 100 ASSERT (mHiiConfigRouting != NULL);\r
101\r
102 //\r
103 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()\r
104 //\r
59aefb7e 105 PrivateData = VLAN_CONFIG_PRIVATE_DATA_FROM_THIS (This);\r
779ae357 106 ZeroMem (&Configuration, sizeof (VLAN_CONFIGURATION));\r
d1050b9d 107 BufferSize = sizeof (Configuration);\r
59aefb7e
LG
108 ConfigRequest = Request;\r
109 if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {\r
110 //\r
111 // Request has no request element, construct full request string.\r
112 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r
113 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r
114 //\r
c8ad2d7a 115 ConfigRequestHdr = HiiConstructConfigHdr (&gVlanConfigFormSetGuid, mVlanStorageName, PrivateData->DriverHandle);\r
d1050b9d
MK
116 Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r
117 ConfigRequest = AllocateZeroPool (Size);\r
59aefb7e
LG
118 ASSERT (ConfigRequest != NULL);\r
119 AllocatedRequest = TRUE;\r
120 UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);\r
121 FreePool (ConfigRequestHdr);\r
122 }\r
123\r
779ae357 124 Status = mHiiConfigRouting->BlockToConfig (\r
125 mHiiConfigRouting,\r
59aefb7e 126 ConfigRequest,\r
d1050b9d 127 (UINT8 *)&Configuration,\r
779ae357 128 BufferSize,\r
129 Results,\r
130 Progress\r
131 );\r
59aefb7e
LG
132 //\r
133 // Free the allocated config request string.\r
134 //\r
135 if (AllocatedRequest) {\r
136 FreePool (ConfigRequest);\r
137 ConfigRequest = NULL;\r
138 }\r
d1050b9d 139\r
59aefb7e
LG
140 //\r
141 // Set Progress string to the original request string.\r
142 //\r
143 if (Request == NULL) {\r
144 *Progress = NULL;\r
145 } else if (StrStr (Request, L"OFFSET") == NULL) {\r
146 *Progress = Request + StrLen (Request);\r
147 }\r
148\r
779ae357 149 return Status;\r
150}\r
151\r
779ae357 152/**\r
153 This function processes the results of changes in configuration.\r
154\r
155 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
156 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>\r
157 format.\r
158 @param[out] Progress A pointer to a string filled in with the offset of\r
159 the most recent '&' before the first failing\r
160 name/value pair (or the beginning of the string if\r
161 the failure is in the first name/value pair) or\r
162 the terminating NULL if all was successful.\r
163\r
164 @retval EFI_SUCCESS The Results is processed successfully.\r
165 @retval EFI_INVALID_PARAMETER Configuration is NULL.\r
166 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this\r
167 driver.\r
168\r
169**/\r
170EFI_STATUS\r
171EFIAPI\r
172VlanRouteConfig (\r
d1050b9d
MK
173 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
174 IN CONST EFI_STRING Configuration,\r
175 OUT EFI_STRING *Progress\r
779ae357 176 )\r
177{\r
d1050b9d 178 if ((Configuration == NULL) || (Progress == NULL)) {\r
779ae357 179 return EFI_INVALID_PARAMETER;\r
180 }\r
181\r
182 *Progress = Configuration;\r
c8ad2d7a 183 if (!HiiIsConfigHdrMatch (Configuration, &gVlanConfigFormSetGuid, mVlanStorageName)) {\r
779ae357 184 return EFI_NOT_FOUND;\r
185 }\r
186\r
187 *Progress = Configuration + StrLen (Configuration);\r
188 return EFI_SUCCESS;\r
189}\r
190\r
191/**\r
192 This function processes the results of changes in configuration.\r
193\r
194 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
195 @param[in] Action Specifies the type of action taken by the browser.\r
196 @param[in] QuestionId A unique value which is sent to the original\r
197 exporting driver so that it can identify the type\r
198 of data to expect.\r
199 @param[in] Type The type of value for the question.\r
200 @param[in] Value A pointer to the data being sent to the original\r
201 exporting driver.\r
202 @param[out] ActionRequest On return, points to the action requested by the\r
203 callback function.\r
204\r
205 @retval EFI_SUCCESS The callback successfully handled the action.\r
206 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the\r
207 variable and its data.\r
208 @retval EFI_DEVICE_ERROR The variable could not be saved.\r
209 @retval EFI_UNSUPPORTED The specified Action is not supported by the\r
210 callback.\r
211\r
212**/\r
213EFI_STATUS\r
214EFIAPI\r
215VlanCallback (\r
d1050b9d
MK
216 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
217 IN EFI_BROWSER_ACTION Action,\r
218 IN EFI_QUESTION_ID QuestionId,\r
219 IN UINT8 Type,\r
220 IN EFI_IFR_TYPE_VALUE *Value,\r
221 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
779ae357 222 )\r
223{\r
224 VLAN_CONFIG_PRIVATE_DATA *PrivateData;\r
225 VLAN_CONFIGURATION *Configuration;\r
226 EFI_VLAN_CONFIG_PROTOCOL *VlanConfig;\r
227 UINTN Index;\r
228 EFI_HANDLE VlanHandle;\r
229\r
230 PrivateData = VLAN_CONFIG_PRIVATE_DATA_FROM_THIS (This);\r
231\r
9ea13d79 232 if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) || (Action == EFI_BROWSER_ACTION_FORM_CLOSE)) {\r
779ae357 233 return EFI_SUCCESS;\r
234 }\r
235\r
3a4e7a3e 236 if ((Action != EFI_BROWSER_ACTION_CHANGED) && (Action != EFI_BROWSER_ACTION_CHANGING)) {\r
779ae357 237 //\r
3a4e7a3e 238 // All other action return unsupported.\r
779ae357 239 //\r
3a4e7a3e
ED
240 return EFI_UNSUPPORTED;\r
241 }\r
242\r
243 //\r
244 // Get Browser data\r
245 //\r
246 Configuration = AllocateZeroPool (sizeof (VLAN_CONFIGURATION));\r
247 ASSERT (Configuration != NULL);\r
d1050b9d 248 HiiGetBrowserData (&gVlanConfigFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *)Configuration);\r
779ae357 249\r
3a4e7a3e 250 VlanConfig = PrivateData->VlanConfig;\r
083f7c69 251\r
3a4e7a3e 252 if (Action == EFI_BROWSER_ACTION_CHANGED) {\r
083f7c69 253 switch (QuestionId) {\r
d1050b9d
MK
254 case VLAN_ADD_QUESTION_ID:\r
255 //\r
256 // Add a VLAN\r
779ae357 257 //\r
d1050b9d
MK
258 VlanConfig->Set (VlanConfig, Configuration->VlanId, Configuration->Priority);\r
259 VlanUpdateForm (PrivateData);\r
260\r
261 //\r
262 // Connect the newly created VLAN device\r
779ae357 263 //\r
d1050b9d
MK
264 VlanHandle = NetLibGetVlanHandle (PrivateData->ControllerHandle, Configuration->VlanId);\r
265 if (VlanHandle == NULL) {\r
083f7c69 266 //\r
d1050b9d 267 // There may be no child handle created for VLAN ID 0, connect the parent handle\r
083f7c69 268 //\r
d1050b9d 269 VlanHandle = PrivateData->ControllerHandle;\r
083f7c69 270 }\r
779ae357 271\r
d1050b9d
MK
272 gBS->ConnectController (VlanHandle, NULL, NULL, TRUE);\r
273\r
083f7c69 274 //\r
d1050b9d 275 // Clear UI data\r
083f7c69 276 //\r
d1050b9d
MK
277 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r
278 Configuration->VlanId = 0;\r
279 Configuration->Priority = 0;\r
280 break;\r
281\r
282 case VLAN_REMOVE_QUESTION_ID:\r
283 //\r
284 // Remove VLAN\r
285 //\r
286 ASSERT (PrivateData->NumberOfVlan <= MAX_VLAN_NUMBER);\r
287 for (Index = 0; Index < PrivateData->NumberOfVlan; Index++) {\r
288 if (Configuration->VlanList[Index] != 0) {\r
289 //\r
290 // Checkbox is selected, need remove this VLAN\r
291 //\r
292 VlanConfig->Remove (VlanConfig, PrivateData->VlanId[Index]);\r
293 }\r
294 }\r
295\r
296 VlanUpdateForm (PrivateData);\r
297 if (PrivateData->NumberOfVlan == 0) {\r
298 //\r
299 // No VLAN device now, connect the physical NIC handle.\r
300 // Note: PrivateData->NumberOfVlan has been updated by VlanUpdateForm()\r
301 //\r
302 gBS->ConnectController (PrivateData->ControllerHandle, NULL, NULL, TRUE);\r
303 }\r
083f7c69 304\r
d1050b9d
MK
305 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r
306 ZeroMem (Configuration->VlanList, MAX_VLAN_NUMBER);\r
307 break;\r
083f7c69 308\r
d1050b9d
MK
309 default:\r
310 break;\r
3a4e7a3e
ED
311 }\r
312 } else if (Action == EFI_BROWSER_ACTION_CHANGING) {\r
313 switch (QuestionId) {\r
d1050b9d
MK
314 case VLAN_UPDATE_QUESTION_ID:\r
315 //\r
316 // Update current VLAN list into Form.\r
317 //\r
318 VlanUpdateForm (PrivateData);\r
319 break;\r
320\r
321 default:\r
322 break;\r
083f7c69 323 }\r
779ae357 324 }\r
d1102dba 325\r
d1050b9d 326 HiiSetBrowserData (&gVlanConfigFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *)Configuration, NULL);\r
3a4e7a3e
ED
327 FreePool (Configuration);\r
328 return EFI_SUCCESS;\r
779ae357 329}\r
330\r
779ae357 331/**\r
332 This function update VLAN list in the VLAN configuration Form.\r
333\r
334 @param[in, out] PrivateData Points to VLAN configuration private data.\r
335\r
336**/\r
337VOID\r
338VlanUpdateForm (\r
d1050b9d 339 IN OUT VLAN_CONFIG_PRIVATE_DATA *PrivateData\r
779ae357 340 )\r
341{\r
342 EFI_VLAN_CONFIG_PROTOCOL *VlanConfig;\r
343 UINT16 NumberOfVlan;\r
344 UINTN Index;\r
345 EFI_VLAN_FIND_DATA *VlanData;\r
346 VOID *StartOpCodeHandle;\r
347 EFI_IFR_GUID_LABEL *StartLabel;\r
348 VOID *EndOpCodeHandle;\r
349 EFI_IFR_GUID_LABEL *EndLabel;\r
350 CHAR16 *String;\r
351 CHAR16 VlanStr[30];\r
352 CHAR16 VlanIdStr[6];\r
353 UINTN DigitalCount;\r
354 EFI_STRING_ID StringId;\r
355\r
356 //\r
357 // Find current VLAN configuration\r
358 //\r
d1050b9d 359 VlanData = NULL;\r
779ae357 360 NumberOfVlan = 0;\r
d1050b9d 361 VlanConfig = PrivateData->VlanConfig;\r
779ae357 362 VlanConfig->Find (VlanConfig, NULL, &NumberOfVlan, &VlanData);\r
363\r
364 //\r
365 // Update VLAN configuration in PrivateData\r
366 //\r
367 if (NumberOfVlan > MAX_VLAN_NUMBER) {\r
368 NumberOfVlan = MAX_VLAN_NUMBER;\r
369 }\r
d1050b9d 370\r
779ae357 371 PrivateData->NumberOfVlan = NumberOfVlan;\r
372\r
373 //\r
374 // Init OpCode Handle\r
375 //\r
376 StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
377 ASSERT (StartOpCodeHandle != NULL);\r
378\r
379 EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r
380 ASSERT (EndOpCodeHandle != NULL);\r
381\r
382 //\r
383 // Create Hii Extend Label OpCode as the start opcode\r
384 //\r
d1050b9d
MK
385 StartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (\r
386 StartOpCodeHandle,\r
387 &gEfiIfrTianoGuid,\r
388 NULL,\r
389 sizeof (EFI_IFR_GUID_LABEL)\r
390 );\r
779ae357 391 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
392 StartLabel->Number = LABEL_VLAN_LIST;\r
393\r
394 //\r
395 // Create Hii Extend Label OpCode as the end opcode\r
396 //\r
d1050b9d
MK
397 EndLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (\r
398 EndOpCodeHandle,\r
399 &gEfiIfrTianoGuid,\r
400 NULL,\r
401 sizeof (EFI_IFR_GUID_LABEL)\r
402 );\r
779ae357 403 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
404 EndLabel->Number = LABEL_END;\r
405\r
406 ZeroMem (PrivateData->VlanId, MAX_VLAN_NUMBER);\r
407 for (Index = 0; Index < NumberOfVlan; Index++) {\r
408 String = VlanStr;\r
409\r
206b5f51 410 StrCpyS (String, (sizeof (VlanStr) /sizeof (CHAR16)), L" VLAN ID:");\r
779ae357 411 String += 10;\r
412 //\r
413 // Pad VlanId string up to 4 characters with space\r
414 //\r
9f4048f7
HW
415 UnicodeValueToStringS (VlanIdStr, sizeof (VlanIdStr), 0, VlanData[Index].VlanId, 5);\r
416 DigitalCount = StrnLenS (VlanIdStr, ARRAY_SIZE (VlanIdStr));\r
779ae357 417 SetMem16 (String, (4 - DigitalCount) * sizeof (CHAR16), L' ');\r
206b5f51 418 StrCpyS (String + 4 - DigitalCount, (sizeof (VlanStr) /sizeof (CHAR16)) - 10 - (4 - DigitalCount), VlanIdStr);\r
779ae357 419 String += 4;\r
420\r
d1050b9d 421 StrCpyS (String, (sizeof (VlanStr) /sizeof (CHAR16)) - 10 - (4 - DigitalCount) - 4, L", Priority:");\r
779ae357 422 String += 11;\r
9f4048f7
HW
423 UnicodeValueToStringS (\r
424 String,\r
425 sizeof (VlanStr) - ((UINTN)String - (UINTN)VlanStr),\r
426 0,\r
427 VlanData[Index].Priority,\r
428 4\r
429 );\r
430 String += StrnLenS (String, ARRAY_SIZE (VlanStr) - ((UINTN)String - (UINTN)VlanStr) / sizeof (CHAR16));\r
779ae357 431 *String = 0;\r
432\r
433 StringId = HiiSetString (PrivateData->HiiHandle, 0, VlanStr, NULL);\r
434 ASSERT (StringId != 0);\r
435\r
436 HiiCreateCheckBoxOpCode (\r
437 StartOpCodeHandle,\r
d1050b9d 438 (EFI_QUESTION_ID)(VLAN_LIST_VAR_OFFSET + Index),\r
779ae357 439 VLAN_CONFIGURATION_VARSTORE_ID,\r
d1050b9d 440 (UINT16)(VLAN_LIST_VAR_OFFSET + Index),\r
779ae357 441 StringId,\r
442 STRING_TOKEN (STR_VLAN_VLAN_LIST_HELP),\r
443 0,\r
444 0,\r
445 NULL\r
446 );\r
447\r
448 //\r
449 // Save VLAN id to private data\r
450 //\r
451 PrivateData->VlanId[Index] = VlanData[Index].VlanId;\r
452 }\r
453\r
454 HiiUpdateForm (\r
455 PrivateData->HiiHandle, // HII handle\r
c8ad2d7a 456 &gVlanConfigFormSetGuid, // Formset GUID\r
779ae357 457 VLAN_CONFIGURATION_FORM_ID, // Form ID\r
458 StartOpCodeHandle, // Label for where to insert opcodes\r
459 EndOpCodeHandle // Replace data\r
460 );\r
461\r
462 HiiFreeOpCodeHandle (StartOpCodeHandle);\r
463 HiiFreeOpCodeHandle (EndOpCodeHandle);\r
464\r
465 if (VlanData != NULL) {\r
466 FreePool (VlanData);\r
467 }\r
468}\r
469\r
779ae357 470/**\r
471 This function publish the VLAN configuration Form for a network device. The\r
472 HII Config Access protocol will be installed on a child handle of the network\r
473 device.\r
474\r
475 @param[in, out] PrivateData Points to VLAN configuration private data.\r
476\r
477 @retval EFI_SUCCESS HII Form is installed for this network device.\r
478 @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.\r
479 @retval Others Other errors as indicated.\r
480\r
481**/\r
482EFI_STATUS\r
483InstallVlanConfigForm (\r
d1050b9d 484 IN OUT VLAN_CONFIG_PRIVATE_DATA *PrivateData\r
779ae357 485 )\r
486{\r
487 EFI_STATUS Status;\r
488 EFI_HII_HANDLE HiiHandle;\r
489 EFI_HANDLE DriverHandle;\r
e2851998 490 CHAR16 Str[26 + sizeof (EFI_MAC_ADDRESS) * 2 + 1];\r
779ae357 491 CHAR16 *MacString;\r
492 EFI_DEVICE_PATH_PROTOCOL *ChildDevicePath;\r
493 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r
216f7970 494 EFI_VLAN_CONFIG_PROTOCOL *VlanConfig;\r
779ae357 495\r
496 //\r
497 // Create child handle and install HII Config Access Protocol\r
498 //\r
499 ChildDevicePath = AppendDevicePathNode (\r
500 PrivateData->ParentDevicePath,\r
d1050b9d 501 (CONST EFI_DEVICE_PATH_PROTOCOL *)&mHiiVendorDevicePathNode\r
779ae357 502 );\r
503 if (ChildDevicePath == NULL) {\r
504 return EFI_OUT_OF_RESOURCES;\r
505 }\r
d1050b9d 506\r
779ae357 507 PrivateData->ChildDevicePath = ChildDevicePath;\r
508\r
509 DriverHandle = NULL;\r
510 ConfigAccess = &PrivateData->ConfigAccess;\r
d1050b9d
MK
511 Status = gBS->InstallMultipleProtocolInterfaces (\r
512 &DriverHandle,\r
513 &gEfiDevicePathProtocolGuid,\r
514 ChildDevicePath,\r
515 &gEfiHiiConfigAccessProtocolGuid,\r
516 ConfigAccess,\r
517 NULL\r
518 );\r
779ae357 519 if (EFI_ERROR (Status)) {\r
520 return Status;\r
521 }\r
d1050b9d 522\r
779ae357 523 PrivateData->DriverHandle = DriverHandle;\r
524\r
216f7970 525 //\r
526 // Establish the parent-child relationship between the new created\r
527 // child handle and the ControllerHandle.\r
528 //\r
529 Status = gBS->OpenProtocol (\r
530 PrivateData->ControllerHandle,\r
531 &gEfiVlanConfigProtocolGuid,\r
532 (VOID **)&VlanConfig,\r
533 PrivateData->ImageHandle,\r
534 PrivateData->DriverHandle,\r
535 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
536 );\r
537 if (EFI_ERROR (Status)) {\r
538 return Status;\r
539 }\r
540\r
779ae357 541 //\r
542 // Publish the HII package list\r
543 //\r
544 HiiHandle = HiiAddPackages (\r
c8ad2d7a 545 &gVlanConfigFormSetGuid,\r
779ae357 546 DriverHandle,\r
547 VlanConfigDxeStrings,\r
548 VlanConfigBin,\r
549 NULL\r
550 );\r
551 if (HiiHandle == NULL) {\r
552 return EFI_OUT_OF_RESOURCES;\r
553 }\r
d1050b9d 554\r
779ae357 555 PrivateData->HiiHandle = HiiHandle;\r
556\r
557 //\r
3ddc4cf2 558 // Update formset title help string.\r
779ae357 559 //\r
560 MacString = NULL;\r
d1050b9d 561 Status = NetLibGetMacString (PrivateData->ControllerHandle, PrivateData->ImageHandle, &MacString);\r
779ae357 562 if (EFI_ERROR (Status)) {\r
563 return Status;\r
564 }\r
d1050b9d 565\r
779ae357 566 PrivateData->MacString = MacString;\r
567\r
206b5f51
ZL
568 StrCpyS (Str, sizeof (Str) / sizeof (CHAR16), L"VLAN Configuration (MAC:");\r
569 StrCatS (Str, sizeof (Str) / sizeof (CHAR16), MacString);\r
570 StrCatS (Str, sizeof (Str) / sizeof (CHAR16), L")");\r
779ae357 571 HiiSetString (\r
572 HiiHandle,\r
c7f204db 573 STRING_TOKEN (STR_VLAN_FORM_SET_TITLE_HELP),\r
779ae357 574 Str,\r
575 NULL\r
576 );\r
577\r
578 //\r
3ddc4cf2 579 // Update form title help string.\r
779ae357 580 //\r
581 HiiSetString (\r
582 HiiHandle,\r
c7f204db 583 STRING_TOKEN (STR_VLAN_FORM_HELP),\r
779ae357 584 Str,\r
585 NULL\r
586 );\r
587\r
588 return EFI_SUCCESS;\r
589}\r
590\r
591/**\r
592 This function remove the VLAN configuration Form for a network device. The\r
593 child handle for HII Config Access protocol will be destroyed.\r
594\r
595 @param[in, out] PrivateData Points to VLAN configuration private data.\r
596\r
ca4e58d8
FS
597 @retval EFI_SUCCESS HII Form has been uninstalled successfully.\r
598 @retval Others Other errors as indicated.\r
599\r
779ae357 600**/\r
ca4e58d8 601EFI_STATUS\r
779ae357 602UninstallVlanConfigForm (\r
d1050b9d 603 IN OUT VLAN_CONFIG_PRIVATE_DATA *PrivateData\r
779ae357 604 )\r
605{\r
d1050b9d
MK
606 EFI_STATUS Status;\r
607 EFI_VLAN_CONFIG_PROTOCOL *VlanConfig;\r
d1102dba 608\r
216f7970 609 //\r
610 // End the parent-child relationship.\r
611 //\r
ca4e58d8
FS
612 Status = gBS->CloseProtocol (\r
613 PrivateData->ControllerHandle,\r
614 &gEfiVlanConfigProtocolGuid,\r
615 PrivateData->ImageHandle,\r
616 PrivateData->DriverHandle\r
617 );\r
618 if (EFI_ERROR (Status)) {\r
619 return Status;\r
620 }\r
216f7970 621\r
779ae357 622 //\r
623 // Uninstall HII Config Access Protocol\r
624 //\r
625 if (PrivateData->DriverHandle != NULL) {\r
ca4e58d8
FS
626 Status = gBS->UninstallMultipleProtocolInterfaces (\r
627 PrivateData->DriverHandle,\r
628 &gEfiDevicePathProtocolGuid,\r
629 PrivateData->ChildDevicePath,\r
630 &gEfiHiiConfigAccessProtocolGuid,\r
631 &PrivateData->ConfigAccess,\r
632 NULL\r
633 );\r
634 if (EFI_ERROR (Status)) {\r
635 gBS->OpenProtocol (\r
636 PrivateData->ControllerHandle,\r
637 &gEfiVlanConfigProtocolGuid,\r
638 (VOID **)&VlanConfig,\r
639 PrivateData->ImageHandle,\r
640 PrivateData->DriverHandle,\r
641 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
642 );\r
643 return Status;\r
644 }\r
d1050b9d 645\r
779ae357 646 PrivateData->DriverHandle = NULL;\r
647\r
648 if (PrivateData->ChildDevicePath != NULL) {\r
649 FreePool (PrivateData->ChildDevicePath);\r
650 PrivateData->ChildDevicePath = NULL;\r
651 }\r
652 }\r
ca4e58d8
FS
653\r
654 //\r
655 // Free MAC string\r
656 //\r
657 if (PrivateData->MacString != NULL) {\r
658 FreePool (PrivateData->MacString);\r
659 PrivateData->MacString = NULL;\r
660 }\r
661\r
662 //\r
663 // Uninstall HII package list\r
664 //\r
665 if (PrivateData->HiiHandle != NULL) {\r
666 HiiRemovePackages (PrivateData->HiiHandle);\r
667 PrivateData->HiiHandle = NULL;\r
668 }\r
d1050b9d 669\r
ca4e58d8 670 return EFI_SUCCESS;\r
779ae357 671}\r