/** @file\r
HII Config Access protocol implementation of VLAN configuration module.\r
\r
-Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions\r
of the BSD License which accompanies this distribution. The full\r
\r
#include "VlanConfigImpl.h"\r
\r
-EFI_GUID mVlanFormSetGuid = VLAN_CONFIG_PRIVATE_GUID;\r
CHAR16 mVlanStorageName[] = L"VlanNvData";\r
EFI_HII_CONFIG_ROUTING_PROTOCOL *mHiiConfigRouting = NULL;\r
\r
(UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
}\r
},\r
- VLAN_CONFIG_PRIVATE_GUID\r
+ VLAN_CONFIG_FORM_SET_GUID\r
};\r
\r
/**\r
}\r
\r
*Progress = Request;\r
- if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &mVlanFormSetGuid, mVlanStorageName)) {\r
+ if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &gVlanConfigFormSetGuid, mVlanStorageName)) {\r
return EFI_NOT_FOUND;\r
}\r
\r
// Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r
// followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r
//\r
- ConfigRequestHdr = HiiConstructConfigHdr (&mVlanFormSetGuid, mVlanStorageName, PrivateData->DriverHandle);\r
+ ConfigRequestHdr = HiiConstructConfigHdr (&gVlanConfigFormSetGuid, mVlanStorageName, PrivateData->DriverHandle);\r
Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r
ConfigRequest = AllocateZeroPool (Size);\r
ASSERT (ConfigRequest != NULL);\r
}\r
\r
*Progress = Configuration;\r
- if (!HiiIsConfigHdrMatch (Configuration, &mVlanFormSetGuid, mVlanStorageName)) {\r
+ if (!HiiIsConfigHdrMatch (Configuration, &gVlanConfigFormSetGuid, mVlanStorageName)) {\r
return EFI_NOT_FOUND;\r
}\r
\r
\r
PrivateData = VLAN_CONFIG_PRIVATE_DATA_FROM_THIS (This);\r
\r
- if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {\r
- if (QuestionId == VLAN_ADD_QUESTION_ID) {\r
- //\r
- // Update current VLAN list into Form when Form is opened.\r
- // This will be done only in FORM_OPEN CallBack of question with VLAN_ADD_QUESTION_ID.\r
- //\r
- VlanUpdateForm (PrivateData);\r
- }\r
+ if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) || (Action == EFI_BROWSER_ACTION_FORM_CLOSE)) {\r
return EFI_SUCCESS;\r
}\r
\r
- if (Action == EFI_BROWSER_ACTION_FORM_CLOSE) {\r
+ if ((Action != EFI_BROWSER_ACTION_CHANGED) && (Action != EFI_BROWSER_ACTION_CHANGING)) {\r
//\r
- // Do nothing for UEFI FORM_CLOSE action\r
+ // All other action return unsupported.\r
//\r
- return EFI_SUCCESS;\r
+ return EFI_UNSUPPORTED;\r
}\r
\r
//\r
//\r
Configuration = AllocateZeroPool (sizeof (VLAN_CONFIGURATION));\r
ASSERT (Configuration != NULL);\r
- HiiGetBrowserData (&mVlanFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration);\r
+ HiiGetBrowserData (&gVlanConfigFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration);\r
\r
VlanConfig = PrivateData->VlanConfig;\r
\r
- switch (QuestionId) {\r
- case VLAN_ADD_QUESTION_ID:\r
- //\r
- // Add a VLAN\r
- //\r
- VlanConfig->Set (VlanConfig, Configuration->VlanId, Configuration->Priority);\r
- VlanUpdateForm (PrivateData);\r
+ if (Action == EFI_BROWSER_ACTION_CHANGED) {\r
+ switch (QuestionId) {\r
+ case VLAN_ADD_QUESTION_ID:\r
+ //\r
+ // Add a VLAN\r
+ //\r
+ VlanConfig->Set (VlanConfig, Configuration->VlanId, Configuration->Priority);\r
+ VlanUpdateForm (PrivateData);\r
\r
- //\r
- // Connect the newly created VLAN device\r
- //\r
- VlanHandle = NetLibGetVlanHandle (PrivateData->ControllerHandle, Configuration->VlanId);\r
- if (VlanHandle == NULL) {\r
//\r
- // There may be no child handle created for VLAN ID 0, connect the parent handle\r
+ // Connect the newly created VLAN device\r
//\r
- VlanHandle = PrivateData->ControllerHandle;\r
- }\r
- gBS->ConnectController (VlanHandle, NULL, NULL, TRUE);\r
+ VlanHandle = NetLibGetVlanHandle (PrivateData->ControllerHandle, Configuration->VlanId);\r
+ if (VlanHandle == NULL) {\r
+ //\r
+ // There may be no child handle created for VLAN ID 0, connect the parent handle\r
+ //\r
+ VlanHandle = PrivateData->ControllerHandle;\r
+ }\r
+ gBS->ConnectController (VlanHandle, NULL, NULL, TRUE);\r
\r
- //\r
- // Clear UI data\r
- //\r
- *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r
- Configuration->VlanId = 0;\r
- Configuration->Priority = 0;\r
- break;\r
+ //\r
+ // Clear UI data\r
+ //\r
+ *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r
+ Configuration->VlanId = 0;\r
+ Configuration->Priority = 0;\r
+ break;\r
\r
- case VLAN_REMOVE_QUESTION_ID:\r
- //\r
- // Remove VLAN\r
- //\r
- ASSERT (PrivateData->NumberOfVlan <= MAX_VLAN_NUMBER);\r
- for (Index = 0; Index < PrivateData->NumberOfVlan; Index++) {\r
- if (Configuration->VlanList[Index] != 0) {\r
+ case VLAN_REMOVE_QUESTION_ID:\r
+ //\r
+ // Remove VLAN\r
+ //\r
+ ASSERT (PrivateData->NumberOfVlan <= MAX_VLAN_NUMBER);\r
+ for (Index = 0; Index < PrivateData->NumberOfVlan; Index++) {\r
+ if (Configuration->VlanList[Index] != 0) {\r
+ //\r
+ // Checkbox is selected, need remove this VLAN\r
+ //\r
+ VlanConfig->Remove (VlanConfig, PrivateData->VlanId[Index]);\r
+ }\r
+ }\r
+\r
+ VlanUpdateForm (PrivateData);\r
+ if (PrivateData->NumberOfVlan == 0) {\r
//\r
- // Checkbox is selected, need remove this VLAN\r
+ // No VLAN device now, connect the physical NIC handle.\r
+ // Note: PrivateData->NumberOfVlan has been updated by VlanUpdateForm()\r
//\r
- VlanConfig->Remove (VlanConfig, PrivateData->VlanId[Index]);\r
+ gBS->ConnectController (PrivateData->ControllerHandle, NULL, NULL, TRUE);\r
}\r
- }\r
\r
- VlanUpdateForm (PrivateData);\r
- if (PrivateData->NumberOfVlan == 0) {\r
+ *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r
+ ZeroMem (Configuration->VlanList, MAX_VLAN_NUMBER);\r
+ break;\r
+\r
+ default:\r
+ break;\r
+ }\r
+ } else if (Action == EFI_BROWSER_ACTION_CHANGING) {\r
+ switch (QuestionId) {\r
+ case VLAN_UPDATE_QUESTION_ID:\r
//\r
- // No VLAN device now, connect the physical NIC handle.\r
- // Note: PrivateData->NumberOfVlan has been updated by VlanUpdateForm()\r
+ // Update current VLAN list into Form.\r
//\r
- gBS->ConnectController (PrivateData->ControllerHandle, NULL, NULL, TRUE);\r
- }\r
-\r
- *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r
- ZeroMem (Configuration->VlanList, MAX_VLAN_NUMBER);\r
- break;\r
+ VlanUpdateForm (PrivateData);\r
+ break;\r
\r
- default:\r
- break;\r
+ default:\r
+ break;\r
+ }\r
}\r
\r
- HiiSetBrowserData (&mVlanFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration, NULL);\r
+ HiiSetBrowserData (&gVlanConfigFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration, NULL);\r
FreePool (Configuration);\r
return EFI_SUCCESS;\r
}\r
for (Index = 0; Index < NumberOfVlan; Index++) {\r
String = VlanStr;\r
\r
- StrCpy (String, L" VLAN ID:");\r
+ StrCpyS (String, (sizeof (VlanStr) /sizeof (CHAR16)), L" VLAN ID:");\r
String += 10;\r
//\r
// Pad VlanId string up to 4 characters with space\r
//\r
- DigitalCount = UnicodeValueToString (VlanIdStr, 0, VlanData[Index].VlanId, 5);\r
+ UnicodeValueToStringS (VlanIdStr, sizeof (VlanIdStr), 0, VlanData[Index].VlanId, 5);\r
+ DigitalCount = StrnLenS (VlanIdStr, ARRAY_SIZE (VlanIdStr));\r
SetMem16 (String, (4 - DigitalCount) * sizeof (CHAR16), L' ');\r
- StrCpy (String + 4 - DigitalCount, VlanIdStr);\r
+ StrCpyS (String + 4 - DigitalCount, (sizeof (VlanStr) /sizeof (CHAR16)) - 10 - (4 - DigitalCount), VlanIdStr);\r
String += 4;\r
\r
- StrCpy (String, L", Priority:");\r
+ StrCpyS (String, (sizeof (VlanStr) /sizeof (CHAR16)) - 10 - (4 - DigitalCount) - 4, L", Priority:");\r
String += 11;\r
- String += UnicodeValueToString (String, 0, VlanData[Index].Priority, 4);\r
+ UnicodeValueToStringS (\r
+ String,\r
+ sizeof (VlanStr) - ((UINTN)String - (UINTN)VlanStr),\r
+ 0,\r
+ VlanData[Index].Priority,\r
+ 4\r
+ );\r
+ String += StrnLenS (String, ARRAY_SIZE (VlanStr) - ((UINTN)String - (UINTN)VlanStr) / sizeof (CHAR16));\r
*String = 0;\r
\r
StringId = HiiSetString (PrivateData->HiiHandle, 0, VlanStr, NULL);\r
\r
HiiUpdateForm (\r
PrivateData->HiiHandle, // HII handle\r
- &mVlanFormSetGuid, // Formset GUID\r
+ &gVlanConfigFormSetGuid, // Formset GUID\r
VLAN_CONFIGURATION_FORM_ID, // Form ID\r
StartOpCodeHandle, // Label for where to insert opcodes\r
EndOpCodeHandle // Replace data\r
CHAR16 *MacString;\r
EFI_DEVICE_PATH_PROTOCOL *ChildDevicePath;\r
EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r
+ EFI_VLAN_CONFIG_PROTOCOL *VlanConfig;\r
\r
//\r
// Create child handle and install HII Config Access Protocol\r
}\r
PrivateData->DriverHandle = DriverHandle;\r
\r
+ //\r
+ // Establish the parent-child relationship between the new created\r
+ // child handle and the ControllerHandle.\r
+ //\r
+ Status = gBS->OpenProtocol (\r
+ PrivateData->ControllerHandle,\r
+ &gEfiVlanConfigProtocolGuid,\r
+ (VOID **)&VlanConfig,\r
+ PrivateData->ImageHandle,\r
+ PrivateData->DriverHandle,\r
+ EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
//\r
// Publish the HII package list\r
//\r
HiiHandle = HiiAddPackages (\r
- &mVlanFormSetGuid,\r
+ &gVlanConfigFormSetGuid,\r
DriverHandle,\r
VlanConfigDxeStrings,\r
VlanConfigBin,\r
PrivateData->HiiHandle = HiiHandle;\r
\r
//\r
- // Update formset title\r
+ // Update formset title help string.\r
//\r
MacString = NULL;\r
Status = NetLibGetMacString (PrivateData->ControllerHandle, PrivateData->ImageHandle, &MacString);\r
}\r
PrivateData->MacString = MacString;\r
\r
- StrCpy (Str, L"VLAN Configuration (MAC:");\r
- StrnCat (Str, MacString, sizeof (EFI_MAC_ADDRESS) * 2);\r
- StrCat (Str, L")");\r
+ StrCpyS (Str, sizeof (Str) / sizeof (CHAR16), L"VLAN Configuration (MAC:");\r
+ StrCatS (Str, sizeof (Str) / sizeof (CHAR16), MacString);\r
+ StrCatS (Str, sizeof (Str) / sizeof (CHAR16), L")");\r
HiiSetString (\r
HiiHandle,\r
- STRING_TOKEN (STR_VLAN_FORM_SET_TITLE),\r
+ STRING_TOKEN (STR_VLAN_FORM_SET_TITLE_HELP),\r
Str,\r
NULL\r
);\r
\r
//\r
- // Update form title\r
+ // Update form title help string.\r
//\r
HiiSetString (\r
HiiHandle,\r
- STRING_TOKEN (STR_VLAN_FORM_TITLE),\r
+ STRING_TOKEN (STR_VLAN_FORM_HELP),\r
Str,\r
NULL\r
);\r
\r
@param[in, out] PrivateData Points to VLAN configuration private data.\r
\r
+ @retval EFI_SUCCESS HII Form has been uninstalled successfully.\r
+ @retval Others Other errors as indicated.\r
+\r
**/\r
-VOID\r
+EFI_STATUS\r
UninstallVlanConfigForm (\r
IN OUT VLAN_CONFIG_PRIVATE_DATA *PrivateData\r
)\r
{\r
- //\r
- // Free MAC string\r
- //\r
- if (PrivateData->MacString != NULL) {\r
- FreePool (PrivateData->MacString);\r
- PrivateData->MacString = NULL;\r
- }\r
+ EFI_STATUS Status;\r
+ EFI_VLAN_CONFIG_PROTOCOL *VlanConfig;\r
\r
//\r
- // Uninstall HII package list\r
+ // End the parent-child relationship.\r
//\r
- if (PrivateData->HiiHandle != NULL) {\r
- HiiRemovePackages (PrivateData->HiiHandle);\r
- PrivateData->HiiHandle = NULL;\r
+ Status = gBS->CloseProtocol (\r
+ PrivateData->ControllerHandle,\r
+ &gEfiVlanConfigProtocolGuid,\r
+ PrivateData->ImageHandle,\r
+ PrivateData->DriverHandle\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
}\r
\r
//\r
// Uninstall HII Config Access Protocol\r
//\r
if (PrivateData->DriverHandle != NULL) {\r
- gBS->UninstallMultipleProtocolInterfaces (\r
- PrivateData->DriverHandle,\r
- &gEfiDevicePathProtocolGuid,\r
- PrivateData->ChildDevicePath,\r
- &gEfiHiiConfigAccessProtocolGuid,\r
- &PrivateData->ConfigAccess,\r
- NULL\r
- );\r
+ Status = gBS->UninstallMultipleProtocolInterfaces (\r
+ PrivateData->DriverHandle,\r
+ &gEfiDevicePathProtocolGuid,\r
+ PrivateData->ChildDevicePath,\r
+ &gEfiHiiConfigAccessProtocolGuid,\r
+ &PrivateData->ConfigAccess,\r
+ NULL\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ gBS->OpenProtocol (\r
+ PrivateData->ControllerHandle,\r
+ &gEfiVlanConfigProtocolGuid,\r
+ (VOID **)&VlanConfig,\r
+ PrivateData->ImageHandle,\r
+ PrivateData->DriverHandle,\r
+ EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+ );\r
+ return Status;\r
+ }\r
PrivateData->DriverHandle = NULL;\r
\r
if (PrivateData->ChildDevicePath != NULL) {\r
PrivateData->ChildDevicePath = NULL;\r
}\r
}\r
+\r
+ //\r
+ // Free MAC string\r
+ //\r
+ if (PrivateData->MacString != NULL) {\r
+ FreePool (PrivateData->MacString);\r
+ PrivateData->MacString = NULL;\r
+ }\r
+\r
+ //\r
+ // Uninstall HII package list\r
+ //\r
+ if (PrivateData->HiiHandle != NULL) {\r
+ HiiRemovePackages (PrivateData->HiiHandle);\r
+ PrivateData->HiiHandle = NULL;\r
+ }\r
+ return EFI_SUCCESS;\r
}\r