X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FVlanConfigDxe%2FVlanConfigImpl.c;h=0bdffa2ee4373a45cc4d6258e05b76846b6747f5;hb=dff73e4c73fd421421c622a9fd3762588144db96;hp=6d544f53214d22f3c1552ad8f42225881efd9e25;hpb=cd3d9a851ba7fac1b761c02acedb310b65fc2604;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigImpl.c b/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigImpl.c index 6d544f5321..0bdffa2ee4 100644 --- a/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigImpl.c +++ b/MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigImpl.c @@ -1,7 +1,7 @@ /** @file HII Config Access protocol implementation of VLAN configuration module. -Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
+Copyright (c) 2009 - 2018, 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 @@ -15,7 +15,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "VlanConfigImpl.h" -EFI_GUID mVlanFormSetGuid = VLAN_CONFIG_PRIVATE_GUID; CHAR16 mVlanStorageName[] = L"VlanNvData"; EFI_HII_CONFIG_ROUTING_PROTOCOL *mHiiConfigRouting = NULL; @@ -37,7 +36,7 @@ VENDOR_DEVICE_PATH mHiiVendorDevicePathNode = { (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) } }, - VLAN_CONFIG_PRIVATE_GUID + VLAN_CONFIG_FORM_SET_GUID }; /** @@ -89,7 +88,7 @@ VlanExtractConfig ( } *Progress = Request; - if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &mVlanFormSetGuid, mVlanStorageName)) { + if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &gVlanConfigFormSetGuid, mVlanStorageName)) { return EFI_NOT_FOUND; } @@ -119,7 +118,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 +186,7 @@ VlanRouteConfig ( } *Progress = Configuration; - if (!HiiIsConfigHdrMatch (Configuration, &mVlanFormSetGuid, mVlanStorageName)) { + if (!HiiIsConfigHdrMatch (Configuration, &gVlanConfigFormSetGuid, mVlanStorageName)) { return EFI_NOT_FOUND; } @@ -240,16 +239,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 (&mVlanFormSetGuid, 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: // @@ -305,6 +311,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. @@ -315,16 +326,11 @@ VlanCallback ( default: break; } - - HiiSetBrowserData (&mVlanFormSetGuid, 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; } @@ -406,19 +412,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); @@ -444,7 +458,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 @@ -483,6 +497,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 @@ -511,11 +526,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, @@ -536,9 +567,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), @@ -565,40 +596,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) { @@ -606,4 +651,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; }