X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FVlanConfigDxe%2FVlanConfigImpl.c;h=24d844cbf16fd48f8c7bf647d51e71a6015b395c;hp=2c4e0249fce02e0be0ffd5385388915878ca4c2c;hb=c0fd7f734e2d33e22215899b40a47b843129541d;hpb=5a15736588938f47c3e0c70c26361f3017a395ef diff --git a/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigImpl.c b/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigImpl.c index 2c4e0249fc..24d844cbf1 100644 --- a/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigImpl.c +++ b/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigImpl.c @@ -1,21 +1,13 @@ /** @file HII Config Access protocol implementation of VLAN configuration module. -Copyright (c) 2009 - 2010, Intel Corporation.
-All rights reserved. This program and the accompanying materials -are licensed and made available under the terms and conditions -of the BSD License which accompanies this distribution. The full -text of the license may be found at
-http://opensource.org/licenses/bsd-license.php - -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include "VlanConfigImpl.h" -EFI_GUID mVlanFormSetGuid = VLAN_CONFIG_PRIVATE_GUID; CHAR16 mVlanStorageName[] = L"VlanNvData"; EFI_HII_CONFIG_ROUTING_PROTOCOL *mHiiConfigRouting = NULL; @@ -37,7 +29,7 @@ VENDOR_DEVICE_PATH mHiiVendorDevicePathNode = { (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) } }, - VLAN_CONFIG_PRIVATE_GUID + VLAN_CONFIG_FORM_SET_GUID }; /** @@ -89,7 +81,7 @@ VlanExtractConfig ( } *Progress = Request; - if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &mVlanFormSetGuid, mVlanStorageName)) { + if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &gVlanConfigFormSetGuid, mVlanStorageName)) { return EFI_NOT_FOUND; } @@ -119,7 +111,7 @@ VlanExtractConfig ( // Allocate and fill a buffer large enough to hold the template // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator // - ConfigRequestHdr = HiiConstructConfigHdr (&mVlanFormSetGuid, mVlanStorageName, PrivateData->DriverHandle); + ConfigRequestHdr = HiiConstructConfigHdr (&gVlanConfigFormSetGuid, mVlanStorageName, PrivateData->DriverHandle); Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16); ConfigRequest = AllocateZeroPool (Size); ASSERT (ConfigRequest != NULL); @@ -187,7 +179,7 @@ VlanRouteConfig ( } *Progress = Configuration; - if (!HiiIsConfigHdrMatch (Configuration, &mVlanFormSetGuid, mVlanStorageName)) { + if (!HiiIsConfigHdrMatch (Configuration, &gVlanConfigFormSetGuid, mVlanStorageName)) { return EFI_NOT_FOUND; } @@ -236,13 +228,15 @@ VlanCallback ( PrivateData = VLAN_CONFIG_PRIVATE_DATA_FROM_THIS (This); - if (Action == EFI_BROWSER_ACTION_FORM_OPEN) { + if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) || (Action == EFI_BROWSER_ACTION_FORM_CLOSE)) { + return EFI_SUCCESS; + } + + if ((Action != EFI_BROWSER_ACTION_CHANGED) && (Action != EFI_BROWSER_ACTION_CHANGING)) { // - // On FORM_OPEN event, update current VLAN list + // All other action return unsupported. // - VlanUpdateForm (PrivateData); - - return EFI_SUCCESS; + return EFI_UNSUPPORTED; } // @@ -250,70 +244,84 @@ VlanCallback ( // Configuration = AllocateZeroPool (sizeof (VLAN_CONFIGURATION)); ASSERT (Configuration != NULL); - HiiGetBrowserData (&mVlanFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration); + HiiGetBrowserData (&gVlanConfigFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration); VlanConfig = PrivateData->VlanConfig; - switch (QuestionId) { - case VLAN_ADD_QUESTION_ID: - // - // Add a VLAN - // - VlanConfig->Set (VlanConfig, Configuration->VlanId, Configuration->Priority); - VlanUpdateForm (PrivateData); + if (Action == EFI_BROWSER_ACTION_CHANGED) { + switch (QuestionId) { + case VLAN_ADD_QUESTION_ID: + // + // Add a VLAN + // + VlanConfig->Set (VlanConfig, Configuration->VlanId, Configuration->Priority); + VlanUpdateForm (PrivateData); - // - // Connect the newly created VLAN device - // - VlanHandle = NetLibGetVlanHandle (PrivateData->ControllerHandle, Configuration->VlanId); - if (VlanHandle == NULL) { // - // There may be no child handle created for VLAN ID 0, connect the parent handle + // Connect the newly created VLAN device // - VlanHandle = PrivateData->ControllerHandle; - } - gBS->ConnectController (VlanHandle, NULL, NULL, TRUE); + VlanHandle = NetLibGetVlanHandle (PrivateData->ControllerHandle, Configuration->VlanId); + if (VlanHandle == NULL) { + // + // There may be no child handle created for VLAN ID 0, connect the parent handle + // + VlanHandle = PrivateData->ControllerHandle; + } + gBS->ConnectController (VlanHandle, NULL, NULL, TRUE); - // - // Clear UI data - // - *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT; - Configuration->VlanId = 0; - Configuration->Priority = 0; - break; + // + // Clear UI data + // + *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY; + Configuration->VlanId = 0; + Configuration->Priority = 0; + break; - case VLAN_REMOVE_QUESTION_ID: - // - // Remove VLAN - // - ASSERT (PrivateData->NumberOfVlan <= MAX_VLAN_NUMBER); - for (Index = 0; Index < PrivateData->NumberOfVlan; Index++) { - if (Configuration->VlanList[Index] != 0) { + case VLAN_REMOVE_QUESTION_ID: + // + // Remove VLAN + // + ASSERT (PrivateData->NumberOfVlan <= MAX_VLAN_NUMBER); + for (Index = 0; Index < PrivateData->NumberOfVlan; Index++) { + if (Configuration->VlanList[Index] != 0) { + // + // Checkbox is selected, need remove this VLAN + // + VlanConfig->Remove (VlanConfig, PrivateData->VlanId[Index]); + } + } + + VlanUpdateForm (PrivateData); + if (PrivateData->NumberOfVlan == 0) { // - // Checkbox is selected, need remove this VLAN + // No VLAN device now, connect the physical NIC handle. + // Note: PrivateData->NumberOfVlan has been updated by VlanUpdateForm() // - VlanConfig->Remove (VlanConfig, PrivateData->VlanId[Index]); + gBS->ConnectController (PrivateData->ControllerHandle, NULL, NULL, TRUE); } - } - VlanUpdateForm (PrivateData); - if (PrivateData->NumberOfVlan == 0) { + *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY; + ZeroMem (Configuration->VlanList, MAX_VLAN_NUMBER); + break; + + default: + break; + } + } else if (Action == EFI_BROWSER_ACTION_CHANGING) { + switch (QuestionId) { + case VLAN_UPDATE_QUESTION_ID: // - // No VLAN device now, connect the physical NIC handle. - // Note: PrivateData->NumberOfVlan has been updated by VlanUpdateForm() + // Update current VLAN list into Form. // - gBS->ConnectController (PrivateData->ControllerHandle, NULL, NULL, TRUE); - } + VlanUpdateForm (PrivateData); + break; - *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT; - ZeroMem (Configuration->VlanList, MAX_VLAN_NUMBER); - break; - - default: - break; + default: + break; + } } - HiiSetBrowserData (&mVlanFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration, NULL); + HiiSetBrowserData (&gVlanConfigFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration, NULL); FreePool (Configuration); return EFI_SUCCESS; } @@ -397,19 +405,27 @@ VlanUpdateForm ( for (Index = 0; Index < NumberOfVlan; Index++) { String = VlanStr; - StrCpy (String, L" VLAN ID:"); + StrCpyS (String, (sizeof (VlanStr) /sizeof (CHAR16)), L" VLAN ID:"); String += 10; // // Pad VlanId string up to 4 characters with space // - DigitalCount = UnicodeValueToString (VlanIdStr, 0, VlanData[Index].VlanId, 5); + UnicodeValueToStringS (VlanIdStr, sizeof (VlanIdStr), 0, VlanData[Index].VlanId, 5); + DigitalCount = StrnLenS (VlanIdStr, ARRAY_SIZE (VlanIdStr)); SetMem16 (String, (4 - DigitalCount) * sizeof (CHAR16), L' '); - StrCpy (String + 4 - DigitalCount, VlanIdStr); + StrCpyS (String + 4 - DigitalCount, (sizeof (VlanStr) /sizeof (CHAR16)) - 10 - (4 - DigitalCount), VlanIdStr); String += 4; - StrCpy (String, L", Priority:"); + StrCpyS (String, (sizeof (VlanStr) /sizeof (CHAR16)) - 10 - (4 - DigitalCount) - 4, L", Priority:"); String += 11; - String += UnicodeValueToString (String, 0, VlanData[Index].Priority, 4); + UnicodeValueToStringS ( + String, + sizeof (VlanStr) - ((UINTN)String - (UINTN)VlanStr), + 0, + VlanData[Index].Priority, + 4 + ); + String += StrnLenS (String, ARRAY_SIZE (VlanStr) - ((UINTN)String - (UINTN)VlanStr) / sizeof (CHAR16)); *String = 0; StringId = HiiSetString (PrivateData->HiiHandle, 0, VlanStr, NULL); @@ -435,7 +451,7 @@ VlanUpdateForm ( HiiUpdateForm ( PrivateData->HiiHandle, // HII handle - &mVlanFormSetGuid, // Formset GUID + &gVlanConfigFormSetGuid, // Formset GUID VLAN_CONFIGURATION_FORM_ID, // Form ID StartOpCodeHandle, // Label for where to insert opcodes EndOpCodeHandle // Replace data @@ -474,6 +490,7 @@ InstallVlanConfigForm ( CHAR16 *MacString; EFI_DEVICE_PATH_PROTOCOL *ChildDevicePath; EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess; + EFI_VLAN_CONFIG_PROTOCOL *VlanConfig; // // Create child handle and install HII Config Access Protocol @@ -502,11 +519,27 @@ InstallVlanConfigForm ( } PrivateData->DriverHandle = DriverHandle; + // + // Establish the parent-child relationship between the new created + // child handle and the ControllerHandle. + // + Status = gBS->OpenProtocol ( + PrivateData->ControllerHandle, + &gEfiVlanConfigProtocolGuid, + (VOID **)&VlanConfig, + PrivateData->ImageHandle, + PrivateData->DriverHandle, + EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER + ); + if (EFI_ERROR (Status)) { + return Status; + } + // // Publish the HII package list // HiiHandle = HiiAddPackages ( - &mVlanFormSetGuid, + &gVlanConfigFormSetGuid, DriverHandle, VlanConfigDxeStrings, VlanConfigBin, @@ -518,7 +551,7 @@ InstallVlanConfigForm ( PrivateData->HiiHandle = HiiHandle; // - // Update formset title + // Update formset title help string. // MacString = NULL; Status = NetLibGetMacString (PrivateData->ControllerHandle, PrivateData->ImageHandle, &MacString); @@ -527,22 +560,22 @@ InstallVlanConfigForm ( } PrivateData->MacString = MacString; - StrCpy (Str, L"VLAN Configuration (MAC:"); - StrnCat (Str, MacString, sizeof (EFI_MAC_ADDRESS) * 2); - StrCat (Str, L")"); + StrCpyS (Str, sizeof (Str) / sizeof (CHAR16), L"VLAN Configuration (MAC:"); + StrCatS (Str, sizeof (Str) / sizeof (CHAR16), MacString); + StrCatS (Str, sizeof (Str) / sizeof (CHAR16), L")"); HiiSetString ( HiiHandle, - STRING_TOKEN (STR_VLAN_FORM_SET_TITLE), + STRING_TOKEN (STR_VLAN_FORM_SET_TITLE_HELP), Str, NULL ); // - // Update form title + // Update form title help string. // HiiSetString ( HiiHandle, - STRING_TOKEN (STR_VLAN_FORM_TITLE), + STRING_TOKEN (STR_VLAN_FORM_HELP), Str, NULL ); @@ -556,40 +589,54 @@ InstallVlanConfigForm ( @param[in, out] PrivateData Points to VLAN configuration private data. + @retval EFI_SUCCESS HII Form has been uninstalled successfully. + @retval Others Other errors as indicated. + **/ -VOID +EFI_STATUS UninstallVlanConfigForm ( IN OUT VLAN_CONFIG_PRIVATE_DATA *PrivateData ) { - // - // Free MAC string - // - if (PrivateData->MacString != NULL) { - FreePool (PrivateData->MacString); - PrivateData->MacString = NULL; - } + EFI_STATUS Status; + EFI_VLAN_CONFIG_PROTOCOL *VlanConfig; // - // Uninstall HII package list + // End the parent-child relationship. // - if (PrivateData->HiiHandle != NULL) { - HiiRemovePackages (PrivateData->HiiHandle); - PrivateData->HiiHandle = NULL; + Status = gBS->CloseProtocol ( + PrivateData->ControllerHandle, + &gEfiVlanConfigProtocolGuid, + PrivateData->ImageHandle, + PrivateData->DriverHandle + ); + if (EFI_ERROR (Status)) { + return Status; } // // Uninstall HII Config Access Protocol // if (PrivateData->DriverHandle != NULL) { - gBS->UninstallMultipleProtocolInterfaces ( - PrivateData->DriverHandle, - &gEfiDevicePathProtocolGuid, - PrivateData->ChildDevicePath, - &gEfiHiiConfigAccessProtocolGuid, - &PrivateData->ConfigAccess, - NULL - ); + Status = gBS->UninstallMultipleProtocolInterfaces ( + PrivateData->DriverHandle, + &gEfiDevicePathProtocolGuid, + PrivateData->ChildDevicePath, + &gEfiHiiConfigAccessProtocolGuid, + &PrivateData->ConfigAccess, + NULL + ); + if (EFI_ERROR (Status)) { + gBS->OpenProtocol ( + PrivateData->ControllerHandle, + &gEfiVlanConfigProtocolGuid, + (VOID **)&VlanConfig, + PrivateData->ImageHandle, + PrivateData->DriverHandle, + EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER + ); + return Status; + } PrivateData->DriverHandle = NULL; if (PrivateData->ChildDevicePath != NULL) { @@ -597,4 +644,21 @@ UninstallVlanConfigForm ( PrivateData->ChildDevicePath = NULL; } } + + // + // Free MAC string + // + if (PrivateData->MacString != NULL) { + FreePool (PrivateData->MacString); + PrivateData->MacString = NULL; + } + + // + // Uninstall HII package list + // + if (PrivateData->HiiHandle != NULL) { + HiiRemovePackages (PrivateData->HiiHandle); + PrivateData->HiiHandle = NULL; + } + return EFI_SUCCESS; }