]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/MnpDxe/MnpDriver.c
Fix a bug for vlan ping failure.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / MnpDxe / MnpDriver.c
index e3abd48cf393072fff81e4d2388f7e4fdd2bb68f..2ddcec8962bf8399ffa0e67a376426656c18f102 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Implementation of driver entry point and driver binding protocol.\r
 \r
-Copyright (c) 2005 - 2009, Intel Corporation.<BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2005 - 2012, 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
 text of the license may be found at<BR>\r
@@ -26,6 +26,52 @@ EFI_DRIVER_BINDING_PROTOCOL gMnpDriverBinding = {
   NULL\r
 };\r
 \r
+/**\r
+  Callback function which provided by user to remove one node in NetDestroyLinkList process.\r
+  \r
+  @param[in]    Entry           The entry to be removed.\r
+  @param[in]    Context         Pointer to the callback context corresponds to the Context in NetDestroyLinkList.\r
+\r
+  @retval EFI_SUCCESS           The entry has been removed successfully.\r
+  @retval Others                Fail to remove the entry.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MnpDestroyServiceDataEntry (\r
+  IN LIST_ENTRY         *Entry,\r
+  IN VOID               *Context\r
+  )\r
+{\r
+  MNP_SERVICE_DATA              *MnpServiceData;\r
+  \r
+  MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);\r
+  return MnpDestroyServiceData (MnpServiceData);\r
+}\r
+\r
+/**\r
+  Callback function which provided by user to remove one node in NetDestroyLinkList process.\r
+  \r
+  @param[in]    Entry           The entry to be removed.\r
+  @param[in]    Context         Pointer to the callback context corresponds to the Context in NetDestroyLinkList.\r
+\r
+  @retval EFI_SUCCESS           The entry has been removed successfully.\r
+  @retval Others                Fail to remove the entry.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MnpDestroyServiceChildEntry (\r
+  IN LIST_ENTRY         *Entry,\r
+  IN VOID               *Context\r
+  )\r
+{\r
+  MNP_SERVICE_DATA              *MnpServiceData;\r
+\r
+  MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);\r
+  return MnpDestroyServiceChild (MnpServiceData);\r
+}\r
+\r
 /**\r
   Test to see if this driver supports ControllerHandle. This service\r
   is called by the EFI boot service ConnectController(). In\r
@@ -276,8 +322,8 @@ MnpDriverBindingStop (
   EFI_VLAN_CONFIG_PROTOCOL      *VlanConfig;\r
   MNP_DEVICE_DATA               *MnpDeviceData;\r
   MNP_SERVICE_DATA              *MnpServiceData;\r
-  BOOLEAN                       AllChildrenStopped;\r
-  LIST_ENTRY                    *Entry;\r
+  LIST_ENTRY                    *List;\r
+  UINTN                         ListLength;\r
 \r
   //\r
   // Try to retrieve MNP service binding protocol from the ControllerHandle\r
@@ -317,10 +363,15 @@ MnpDriverBindingStop (
     //\r
     // Destroy all MNP service data\r
     //\r
-    while (!IsListEmpty (&MnpDeviceData->ServiceList)) {\r
-      Entry = GetFirstNode (&MnpDeviceData->ServiceList);\r
-      MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);\r
-      MnpDestroyServiceData (MnpServiceData);\r
+    List = &MnpDeviceData->ServiceList;\r
+    Status = NetDestroyLinkList (\r
+               List,\r
+               MnpDestroyServiceDataEntry,\r
+               NULL,\r
+               &ListLength\r
+               );\r
+    if (EFI_ERROR (Status) || ListLength !=0) {\r
+      return EFI_DEVICE_ERROR;\r
     }\r
 \r
     //\r
@@ -336,28 +387,29 @@ MnpDriverBindingStop (
     }\r
 \r
     //\r
-    // Destroy the Mnp device data\r
+    // Destroy Mnp Device Data\r
     //\r
     MnpDestroyDeviceData (MnpDeviceData, This->DriverBindingHandle);\r
     FreePool (MnpDeviceData);\r
 \r
+    if (gMnpControllerNameTable != NULL) {\r
+      FreeUnicodeStringTable (gMnpControllerNameTable);\r
+      gMnpControllerNameTable = NULL;\r
+    }\r
     return EFI_SUCCESS;\r
   }\r
 \r
   //\r
   // Stop all MNP child\r
   //\r
-  AllChildrenStopped = TRUE;\r
-  NET_LIST_FOR_EACH (Entry, &MnpDeviceData->ServiceList) {\r
-    MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);\r
-\r
-    Status = MnpDestroyServiceChild (MnpServiceData);\r
-    if (EFI_ERROR (Status)) {\r
-      AllChildrenStopped = FALSE;\r
-    }\r
-  }\r
-\r
-  if (!AllChildrenStopped) {\r
+  List = &MnpDeviceData->ServiceList;\r
+  Status = NetDestroyLinkList (\r
+             List,\r
+             MnpDestroyServiceChildEntry,\r
+             NULL,\r
+             &ListLength\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
@@ -465,6 +517,7 @@ ErrorExit:
     if (Instance->Handle != NULL) {\r
 \r
       gBS->UninstallMultipleProtocolInterfaces (\r
+            Instance->Handle,\r
             &gEfiManagedNetworkProtocolGuid,\r
             &Instance->ManagedNetwork,\r
             NULL\r
@@ -492,7 +545,7 @@ ErrorExit:
   @retval EFI_SUCCES             The protocol was removed from ChildHandle.\r
   @retval EFI_UNSUPPORTED        ChildHandle does not support the protocol that\r
                                  is being removed.\r
-  @retval EFI_INVALID_PARAMETER  ChildHandle is not a valid UEFI handle.\r
+  @retval EFI_INVALID_PARAMETER  ChildHandle is NULL.\r
   @retval EFI_ACCESS_DENIED      The protocol could not be removed from the\r
                                  ChildHandle because its services are being\r
                                  used.\r