]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/Mtftp6Dxe/Mtftp6Driver.c
NetworkPkg: Clean up source files
[mirror_edk2.git] / NetworkPkg / Mtftp6Dxe / Mtftp6Driver.c
index d448c78a347db8029f9c562c9369c643fdccaeaa..a4888c0c0e4ce59b34d76437b5c906c14a6c5aa7 100644 (file)
@@ -2,7 +2,7 @@
   Driver Binding functions and Service Binding functions\r
   implementation for Mtftp6 Driver.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -33,7 +33,7 @@ EFI_SERVICE_BINDING_PROTOCOL  gMtftp6ServiceBindingTemplate = {
 \r
 \r
 /**\r
-  Destory the MTFTP6 service. The MTFTP6 service may be partly initialized,\r
+  Destroy the MTFTP6 service. The MTFTP6 service may be partly initialized,\r
   or partly destroyed. If a resource is destroyed, it is marked as such in\r
   case the destroy failed and is called again later.\r
 \r
@@ -46,7 +46,7 @@ Mtftp6DestroyService (
   )\r
 {\r
   //\r
-  // Make sure all children instances have been already destoryed.\r
+  // Make sure all children instances have been already destroyed.\r
   //\r
   ASSERT (Service->ChildrenNum == 0);\r
 \r
@@ -98,7 +98,6 @@ Mtftp6CreateService (
   Mtftp6Srv->Signature      = MTFTP6_SERVICE_SIGNATURE;\r
   Mtftp6Srv->Controller     = Controller;\r
   Mtftp6Srv->Image          = Image;\r
-  Mtftp6Srv->InDestory      = FALSE;\r
   Mtftp6Srv->ChildrenNum    = 0;\r
 \r
   CopyMem (\r
@@ -219,7 +218,7 @@ Mtftp6CreateInstance (
   }\r
 \r
   Mtftp6Ins->Signature = MTFTP6_INSTANCE_SIGNATURE;\r
-  Mtftp6Ins->InDestory = FALSE;\r
+  Mtftp6Ins->InDestroy = FALSE;\r
   Mtftp6Ins->Service   = Service;\r
 \r
   CopyMem (\r
@@ -237,6 +236,45 @@ Mtftp6CreateInstance (
 }\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
+Mtftp6DestroyChildEntryInHandleBuffer (\r
+  IN LIST_ENTRY         *Entry,\r
+  IN VOID               *Context\r
+  )\r
+{\r
+  MTFTP6_INSTANCE               *Instance;\r
+  EFI_SERVICE_BINDING_PROTOCOL  *ServiceBinding;\r
+  UINTN                         NumberOfChildren;\r
+  EFI_HANDLE                    *ChildHandleBuffer;\r
+\r
+  if (Entry == NULL || Context == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Instance = NET_LIST_USER_STRUCT_S (Entry, MTFTP6_INSTANCE, Link, MTFTP6_INSTANCE_SIGNATURE);\r
+  ServiceBinding    = ((MTFTP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ServiceBinding;\r
+  NumberOfChildren  = ((MTFTP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->NumberOfChildren;\r
+  ChildHandleBuffer = ((MTFTP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ChildHandleBuffer;\r
+\r
+  if (!NetIsInHandleBuffer (Instance->Handle, NumberOfChildren, ChildHandleBuffer)) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  return ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle);\r
+}\r
+\r
+\r
 /**\r
   This is the declaration of an EFI image entry point. This entry point is\r
   the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers, including\r
@@ -270,7 +308,7 @@ Mtftp6DriverEntryPoint (
 \r
 \r
 /**\r
-  Test to see if this driver supports ControllerHandle. This service\r
+  Test to see if this driver supports Controller. This service\r
   is called by the EFI boot service ConnectController(). In\r
   order to make drivers as small as possible, there are calling\r
   restrictions for this service. ConnectController() must\r
@@ -278,7 +316,7 @@ Mtftp6DriverEntryPoint (
   Supported(), it must also follow these calling restrictions.\r
 \r
   @param[in]  This                Protocol instance pointer.\r
-  @param[in]  ControllerHandle    Handle of device to test\r
+  @param[in]  Controller          Handle of device to test\r
   @param[in]  RemainingDevicePath Optional parameter use to pick a specific child.\r
                                   device to start.\r
 \r
@@ -306,7 +344,7 @@ Mtftp6DriverBindingSupported (
 \r
 \r
 /**\r
-  Start this driver on ControllerHandle. This service is called by the\r
+  Start this driver on Controller. This service is called by the\r
   EFI boot service ConnectController(). In order to make\r
   drivers as small as possible, there are calling restrictions for\r
   this service. ConnectController() must follow these\r
@@ -314,12 +352,12 @@ Mtftp6DriverBindingSupported (
   must also follow these calling restrictions.\r
 \r
   @param[in]  This                 Protocol instance pointer.\r
-  @param[in]  ControllerHandle     Handle of device to bind driver to.\r
+  @param[in]  Controller           Handle of device to bind driver to.\r
   @param[in]  RemainingDevicePath  Optional parameter use to pick a specific child\r
                                    device to start.\r
 \r
-  @retval EFI_SUCCESS          This driver is added to ControllerHandle.\r
-  @retval EFI_ALREADY_STARTED  This driver is already running on ControllerHandle.\r
+  @retval EFI_SUCCESS          This driver is added to Controller.\r
+  @retval EFI_ALREADY_STARTED  This driver is already running on Controller.\r
   @retval Others               This driver does not support this device.\r
 \r
 **/\r
@@ -402,20 +440,20 @@ ON_ERROR:
 \r
 \r
 /**\r
-  Stop this driver on ControllerHandle. This service is called by the\r
+  Stop this driver on Controller. This service is called by the\r
   EFI boot service DisconnectController(). In order to\r
-  make drivers as small as possible, there are a few calling\r
+  make drivers as small as possible, there are calling\r
   restrictions for this service. DisconnectController()\r
   must follow these calling restrictions. If any other agent wishes\r
-  to call Stop() it must also follow these calling restrictions.\r
+  to call Stop(), it must also follow these calling restrictions.\r
 \r
   @param[in]  This              Protocol instance pointer.\r
-  @param[in]  ControllerHandle  Handle of device to stop driver on\r
+  @param[in]  Controller        Handle of device to stop driver on\r
   @param[in]  NumberOfChildren  Number of Handles in ChildHandleBuffer. If number of\r
                                 children is zero, stop the entire bus driver.\r
   @param[in]  ChildHandleBuffer List of Child Handles to Stop.\r
 \r
-  @retval EFI_SUCCESS       This driver is removed ControllerHandle.\r
+  @retval EFI_SUCCESS       This driver is removed Controller.\r
   @retval EFI_DEVICE_ERROR  An unexpected error.\r
   @retval Others            This driver was not removed from this device.\r
 \r
@@ -429,12 +467,12 @@ Mtftp6DriverBindingStop (
   IN  EFI_HANDLE                  *ChildHandleBuffer\r
   )\r
 {\r
-  EFI_SERVICE_BINDING_PROTOCOL  *ServiceBinding;\r
-  MTFTP6_SERVICE                *Service;\r
-  MTFTP6_INSTANCE               *Instance;\r
-  EFI_HANDLE                    NicHandle;\r
-  EFI_STATUS                    Status;\r
-  EFI_TPL                       OldTpl;\r
+  EFI_SERVICE_BINDING_PROTOCOL               *ServiceBinding;\r
+  MTFTP6_SERVICE                             *Service;\r
+  EFI_HANDLE                                 NicHandle;\r
+  EFI_STATUS                                 Status;\r
+  LIST_ENTRY                                 *List;\r
+  MTFTP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context;\r
 \r
   //\r
   // Locate the Nic handle to retrieve the Mtftp6 private data.\r
@@ -442,7 +480,7 @@ Mtftp6DriverBindingStop (
   NicHandle = NetLibGetNicHandle (Controller, &gEfiUdp6ProtocolGuid);\r
 \r
   if (NicHandle == NULL) {\r
-    return EFI_DEVICE_ERROR;\r
+    return EFI_SUCCESS;\r
   }\r
 \r
   Status = gBS->OpenProtocol (\r
@@ -460,18 +498,26 @@ Mtftp6DriverBindingStop (
 \r
   Service = MTFTP6_SERVICE_FROM_THIS (ServiceBinding);\r
 \r
-  if (Service->InDestory) {\r
-    return EFI_SUCCESS;\r
+  if (!IsListEmpty (&Service->Children)) {\r
+    //\r
+    // Destroy the Mtftp6 child instance in ChildHandleBuffer.\r
+    //\r
+    List = &Service->Children;\r
+    Context.ServiceBinding    = ServiceBinding;\r
+    Context.NumberOfChildren  = NumberOfChildren;\r
+    Context.ChildHandleBuffer = ChildHandleBuffer;\r
+    Status = NetDestroyLinkList (\r
+               List,\r
+               Mtftp6DestroyChildEntryInHandleBuffer,\r
+               &Context,\r
+               NULL\r
+               );\r
   }\r
 \r
-  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
-\r
-  if (NumberOfChildren == 0) {\r
+  if (NumberOfChildren == 0 && IsListEmpty (&Service->Children)) {\r
     //\r
-    // Destory the Mtftp6 service if there is no Mtftp6 child instance left.\r
+    // Destroy the Mtftp6 service if there is no Mtftp6 child instance left.\r
     //\r
-    Service->InDestory = TRUE;\r
-\r
     gBS->UninstallProtocolInterface (\r
            NicHandle,\r
            &gEfiMtftp6ServiceBindingProtocolGuid,\r
@@ -479,22 +525,9 @@ Mtftp6DriverBindingStop (
            );\r
 \r
     Mtftp6DestroyService (Service);\r
-\r
-  } else {\r
-    //\r
-    // Destory the Mtftp6 child instance one by one.\r
-    //\r
-    while (!IsListEmpty (&Service->Children)) {\r
-      Instance = NET_LIST_HEAD (&Service->Children, MTFTP6_INSTANCE, Link);\r
-      Mtftp6ServiceBindingDestroyChild (ServiceBinding, Instance->Handle);\r
-    }\r
-\r
-    if (Service->ChildrenNum != 0) {\r
-      Status = EFI_DEVICE_ERROR;\r
-    }\r
+    Status = EFI_SUCCESS;\r
   }\r
 \r
-  gBS->RestoreTPL (OldTpl);\r
   return Status;\r
 }\r
 \r
@@ -612,7 +645,7 @@ ON_ERROR:
 \r
   @retval EFI_SUCCES            The protocol was removed from ChildHandle.\r
   @retval EFI_UNSUPPORTED       ChildHandle does not support the protocol that is being removed.\r
-  @retval EFI_INVALID_PARAMETER Child handle is not a valid UEFI Handle.\r
+  @retval EFI_INVALID_PARAMETER Child handle is NULL.\r
   @retval Others                The child handle was not destroyed\r
 \r
 **/\r
@@ -657,15 +690,15 @@ Mtftp6ServiceBindingDestroyChild (
   }\r
 \r
   //\r
-  // Check whether the instance already in destory state.\r
+  // Check whether the instance already in Destroy state.\r
   //\r
-  if (Instance->InDestory) {\r
+  if (Instance->InDestroy) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
-  Instance->InDestory = TRUE;\r
+  Instance->InDestroy = TRUE;\r
 \r
   gBS->CloseProtocol (\r
          Service->DummyUdpIo->UdpHandle,\r
@@ -674,17 +707,36 @@ Mtftp6ServiceBindingDestroyChild (
          ChildHandle\r
          );\r
 \r
+  if (Instance->UdpIo != NULL) {\r
+    gBS->CloseProtocol (\r
+         Instance->UdpIo->UdpHandle,\r
+         &gEfiUdp6ProtocolGuid,\r
+         gMtftp6DriverBinding.DriverBindingHandle,\r
+         Instance->Handle\r
+         );\r
+  }\r
+\r
+  if (Instance->McastUdpIo != NULL) {\r
+    gBS->CloseProtocol (\r
+           Instance->McastUdpIo->UdpHandle,\r
+           &gEfiUdp6ProtocolGuid,\r
+           gMtftp6DriverBinding.DriverBindingHandle,\r
+           Instance->Handle\r
+           );\r
+  }\r
+\r
   //\r
   // Uninstall the MTFTP6 protocol first to enable a top down destruction.\r
   //\r
+  gBS->RestoreTPL (OldTpl);\r
   Status = gBS->UninstallProtocolInterface (\r
                   ChildHandle,\r
                   &gEfiMtftp6ProtocolGuid,\r
                   Mtftp6\r
                   );\r
-\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
   if (EFI_ERROR (Status)) {\r
-    Instance->InDestory = FALSE;\r
+    Instance->InDestroy = FALSE;\r
     gBS->RestoreTPL (OldTpl);\r
     return Status;\r
   }\r
@@ -695,9 +747,9 @@ Mtftp6ServiceBindingDestroyChild (
   RemoveEntryList (&Instance->Link);\r
   Service->ChildrenNum --;\r
 \r
-  Mtftp6DestroyInstance (Instance);\r
-\r
   gBS->RestoreTPL (OldTpl);\r
 \r
+  Mtftp6DestroyInstance (Instance);\r
+\r
   return EFI_SUCCESS;\r
 }\r