From: vanjeff Date: Thu, 1 Jul 2010 01:30:23 +0000 (+0000) Subject: 1. fixed one bug to construct config request string header used child handle instead... X-Git-Tag: edk2-stable201903~15727 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=1dc1b43fc2a3739a01680a6dd848d0359bdc829d 1. fixed one bug to construct config request string header used child handle instead of NIC controller handle. 2. fixed one bug to calculate buffer size. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10617 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c index 9d7af66f33..c055db2b77 100644 --- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c +++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c @@ -20,6 +20,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include @@ -33,6 +34,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #define NIC_ITEM_CONFIG_SIZE sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * MAX_IP4_CONFIG_IN_VARIABLE @@ -1570,6 +1572,86 @@ NetMapIterate ( } +/** + Internal function to get the child handle of the NIC handle. + + @param[in] Controller NIC controller handle. + @param[out] ChildHandle Returned child handle. + + @retval EFI_SUCCESS Successfully to get child handle. + @retval Others Failed to get child handle. + +**/ +EFI_STATUS +NetGetChildHandle ( + IN EFI_HANDLE Controller, + OUT EFI_HANDLE *ChildHandle + ) +{ + EFI_STATUS Status; + EFI_HANDLE *Handles; + UINTN HandleCount; + UINTN Index; + EFI_DEVICE_PATH_PROTOCOL *ChildDeviceDevicePath; + VENDOR_DEVICE_PATH *VendorDeviceNode; + + // + // Locate all EFI Hii Config Access protocols + // + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiHiiConfigAccessProtocolGuid, + NULL, + &HandleCount, + &Handles + ); + if (EFI_ERROR (Status) || (HandleCount == 0)) { + return Status; + } + + Status = EFI_NOT_FOUND; + + for (Index = 0; Index < HandleCount; Index++) { + + Status = EfiTestChildHandle (Controller, Handles[Index], &gEfiManagedNetworkServiceBindingProtocolGuid); + if (!EFI_ERROR (Status)) { + // + // Get device path on the child handle + // + Status = gBS->HandleProtocol ( + Handles[Index], + &gEfiDevicePathProtocolGuid, + (VOID **) &ChildDeviceDevicePath + ); + + if (!EFI_ERROR (Status)) { + while (!IsDevicePathEnd (ChildDeviceDevicePath)) { + ChildDeviceDevicePath = NextDevicePathNode (ChildDeviceDevicePath); + // + // Parse one instance + // + if (ChildDeviceDevicePath->Type == HARDWARE_DEVICE_PATH && + ChildDeviceDevicePath->SubType == HW_VENDOR_DP) { + VendorDeviceNode = (VENDOR_DEVICE_PATH *) ChildDeviceDevicePath; + if (CompareMem (&VendorDeviceNode->Guid, &gEfiNicIp4ConfigVariableGuid, sizeof (EFI_GUID)) == 0) { + // + // Found item matched gEfiNicIp4ConfigVariableGuid + // + *ChildHandle = Handles[Index]; + FreePool (Handles); + return EFI_SUCCESS; + } + } + } + } + } + } + + FreePool (Handles); + return Status; +} + + /** This is the default unload handle for all the network drivers. @@ -2391,6 +2473,7 @@ NetLibDefaultAddressIsStatic ( EFI_STRING AccessProgress; EFI_STRING AccessResults; EFI_STRING String; + EFI_HANDLE ChildHandle; ConfigInfo = NULL; ConfigHdr = NULL; @@ -2408,10 +2491,15 @@ NetLibDefaultAddressIsStatic ( return TRUE; } + Status = NetGetChildHandle (Controller, &ChildHandle); + if (EFI_ERROR (Status)) { + return TRUE; + } + // // Construct config request string header // - ConfigHdr = HiiConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, Controller); + ConfigHdr = HiiConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, ChildHandle); if (ConfigHdr == NULL) { return TRUE; } @@ -2442,7 +2530,7 @@ NetLibDefaultAddressIsStatic ( goto ON_EXIT; } - ConfigInfo = AllocateZeroPool (sizeof (NIC_ITEM_CONFIG_SIZE)); + ConfigInfo = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE); if (ConfigInfo == NULL) { goto ON_EXIT; } @@ -2983,7 +3071,7 @@ NetLibStrToIp6andPrefix ( // If input string doesn't indicate the prefix length, return 0xff. // Length = 0xFF; - + // // Convert the string to prefix length // diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf index bf1c76ce1b..9b11c8211d 100644 --- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf +++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf @@ -49,7 +49,7 @@ HiiLib PrintLib -[Guids] +[Guids] gEfiNicIp4ConfigVariableGuid [Protocols] @@ -59,3 +59,4 @@ gEfiComponentNameProtocolGuid # PROTOCOL ALWAYS_CONSUMED gEfiComponentName2ProtocolGuid # PROTOCOL ALWAYS_CONSUMED gEfiHiiConfigRoutingProtocolGuid # PROTOCOL ALWAYS_CONSUMED + gEfiHiiConfigAccessProtocolGuid # PROTOCOL ALWAYS_CONSUMED