X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FVlanConfigDxe%2FVlanConfigImpl.c;h=24d844cbf16fd48f8c7bf647d51e71a6015b395c;hp=ea70d5e28d0e0ba8fd65acf00c7bf942f5a4e4e2;hb=c0fd7f734e2d33e22215899b40a47b843129541d;hpb=c8ad2d7a296c851c2a91519f80dab479df0fdf46 diff --git a/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigImpl.c b/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigImpl.c index ea70d5e28d..24d844cbf1 100644 --- a/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigImpl.c +++ b/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigImpl.c @@ -1,15 +1,8 @@ /** @file HII Config Access protocol implementation of VLAN configuration module. -Copyright (c) 2009 - 2011, 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 **/ @@ -239,16 +232,23 @@ VlanCallback ( return EFI_SUCCESS; } - if (Action == EFI_BROWSER_ACTION_CHANGING) { + if ((Action != EFI_BROWSER_ACTION_CHANGED) && (Action != EFI_BROWSER_ACTION_CHANGING)) { // - // Get Browser data + // All other action return unsupported. // - Configuration = AllocateZeroPool (sizeof (VLAN_CONFIGURATION)); - ASSERT (Configuration != NULL); - HiiGetBrowserData (&gVlanConfigFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration); + return EFI_UNSUPPORTED; + } + + // + // Get Browser data + // + Configuration = AllocateZeroPool (sizeof (VLAN_CONFIGURATION)); + ASSERT (Configuration != NULL); + HiiGetBrowserData (&gVlanConfigFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration); - VlanConfig = PrivateData->VlanConfig; + VlanConfig = PrivateData->VlanConfig; + if (Action == EFI_BROWSER_ACTION_CHANGED) { switch (QuestionId) { case VLAN_ADD_QUESTION_ID: // @@ -304,6 +304,11 @@ VlanCallback ( ZeroMem (Configuration->VlanList, MAX_VLAN_NUMBER); break; + default: + break; + } + } else if (Action == EFI_BROWSER_ACTION_CHANGING) { + switch (QuestionId) { case VLAN_UPDATE_QUESTION_ID: // // Update current VLAN list into Form. @@ -314,16 +319,11 @@ VlanCallback ( default: break; } - - HiiSetBrowserData (&gVlanConfigFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration, NULL); - FreePool (Configuration); - return EFI_SUCCESS; } - // - // All other action return unsupported. - // - return EFI_UNSUPPORTED; + HiiSetBrowserData (&gVlanConfigFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration, NULL); + FreePool (Configuration); + return EFI_SUCCESS; } @@ -405,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); @@ -482,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 @@ -510,6 +519,22 @@ 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 // @@ -535,9 +560,9 @@ 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_HELP), @@ -564,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) { @@ -605,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; }