]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/Ip6Dxe/Ip6Driver.c
MdeModulePkg: introduce PE/COFF image emulator protocol
[mirror_edk2.git] / NetworkPkg / Ip6Dxe / Ip6Driver.c
index 16617c12b174163bfc7279e082c44582b07e1493..7dc9e45af7b668aa4c663d91ad29f6f8472b837b 100644 (file)
@@ -1,16 +1,10 @@
 /** @file\r
   The driver binding and service binding protocol for IP6 driver.\r
 \r
-  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.<BR>\r
   (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<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
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php.\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -41,14 +35,20 @@ IpSec2InstalledCallback (
   IN VOID       *Context\r
   )\r
 {\r
+  EFI_STATUS    Status;\r
   //\r
-  // Close the event so it does not get called again.\r
+  // Test if protocol was even found.\r
+  // Notification function will be called at least once.\r
   //\r
-  gBS->CloseEvent (Event);\r
-\r
-  mIpSec2Installed = TRUE;\r
+  Status = gBS->LocateProtocol (&gEfiIpSec2ProtocolGuid, NULL, (VOID **)&mIpSec);\r
+  if (Status == EFI_SUCCESS && mIpSec != NULL) {\r
+    //\r
+    // Close the event so it does not get called again.\r
+    //\r
+    gBS->CloseEvent (Event);\r
 \r
-  return;\r
+    mIpSec2Installed = TRUE;\r
+  }\r
 }\r
 \r
 /**\r
@@ -149,6 +149,22 @@ Ip6CleanService (
   EFI_IPv6_ADDRESS          AllNodes;\r
   IP6_NEIGHBOR_ENTRY        *NeighborCache;\r
 \r
+  IpSb->State     = IP6_SERVICE_DESTROY;\r
+\r
+  if (IpSb->Timer != NULL) {\r
+    gBS->SetTimer (IpSb->Timer, TimerCancel, 0);\r
+    gBS->CloseEvent (IpSb->Timer);\r
+\r
+    IpSb->Timer = NULL;\r
+  }\r
+\r
+  if (IpSb->FasterTimer != NULL) {\r
+    gBS->SetTimer (IpSb->FasterTimer, TimerCancel, 0);\r
+    gBS->CloseEvent (IpSb->FasterTimer);\r
+\r
+    IpSb->FasterTimer = NULL;\r
+  }\r
+\r
   Ip6ConfigCleanInstance (&IpSb->Ip6ConfigInstance);\r
 \r
   if (!IpSb->LinkLocalDadFail) {\r
@@ -160,7 +176,7 @@ Ip6CleanService (
     Status = Ip6LeaveGroup (IpSb, &AllNodes);\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
-    }  \r
+    }\r
   }\r
 \r
   if (IpSb->DefaultInterface != NULL) {\r
@@ -214,19 +230,6 @@ Ip6CleanService (
     gBS->CloseEvent (IpSb->RecvRequest.MnpToken.Event);\r
   }\r
 \r
-  if (IpSb->Timer != NULL) {\r
-    gBS->SetTimer (IpSb->Timer, TimerCancel, 0);\r
-    gBS->CloseEvent (IpSb->Timer);\r
-\r
-    IpSb->Timer = NULL;\r
-  }\r
-\r
-  if (IpSb->FasterTimer != NULL) {\r
-    gBS->SetTimer (IpSb->FasterTimer, TimerCancel, 0);\r
-    gBS->CloseEvent (IpSb->FasterTimer);\r
-\r
-    IpSb->FasterTimer = NULL;\r
-  }\r
   //\r
   // Free the Neighbor Discovery resources\r
   //\r
@@ -555,18 +558,18 @@ Ip6DriverBindingStart (
                   NULL\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    goto ON_ERROR;\r
+    goto FREE_SERVICE;\r
   }\r
 \r
   //\r
-  // Read the config data from NV variable again. \r
+  // Read the config data from NV variable again.\r
   // The default data can be changed by other drivers.\r
   //\r
   Status = Ip6ConfigReadConfigData (IpSb->MacString, &IpSb->Ip6ConfigInstance);\r
   if (EFI_ERROR (Status)) {\r
-    goto ON_ERROR;\r
+    goto UNINSTALL_PROTOCOL;\r
   }\r
-  \r
+\r
   //\r
   // If there is any default manual address, set it.\r
   //\r
@@ -578,8 +581,17 @@ Ip6DriverBindingStart (
                        DataItem->DataSize,\r
                        DataItem->Data.Ptr\r
                        );\r
-    if (EFI_ERROR(Status) && Status != EFI_NOT_READY) {\r
-      goto ON_ERROR;\r
+    if (Status == EFI_INVALID_PARAMETER || Status == EFI_BAD_BUFFER_SIZE) {\r
+      //\r
+      // Clean the invalid ManualAddress configuration.\r
+      //\r
+      Status = Ip6Cfg->SetData (\r
+                         Ip6Cfg,\r
+                         Ip6ConfigDataTypeManualAddress,\r
+                         0,\r
+                         NULL\r
+                         );\r
+      DEBUG ((EFI_D_WARN, "Ip6DriverBindingStart: Clean the invalid ManualAddress configuration.\n"));\r
     }\r
   }\r
 \r
@@ -594,8 +606,17 @@ Ip6DriverBindingStart (
                        DataItem->DataSize,\r
                        DataItem->Data.Ptr\r
                        );\r
-    if (EFI_ERROR(Status)) {\r
-      goto ON_ERROR;\r
+    if (Status == EFI_INVALID_PARAMETER || Status == EFI_BAD_BUFFER_SIZE) {\r
+      //\r
+      // Clean the invalid Gateway configuration.\r
+      //\r
+      Status = Ip6Cfg->SetData (\r
+                         Ip6Cfg,\r
+                         Ip6ConfigDataTypeGateway,\r
+                         0,\r
+                         NULL\r
+                         );\r
+      DEBUG ((EFI_D_WARN, "Ip6DriverBindingStart: Clean the invalid Gateway configuration.\n"));\r
     }\r
   }\r
 \r
@@ -604,7 +625,7 @@ Ip6DriverBindingStart (
   //\r
   Status = Ip6ReceiveFrame (Ip6AcceptFrame, IpSb);\r
   if (EFI_ERROR (Status)) {\r
-    goto ON_ERROR;\r
+    goto UNINSTALL_PROTOCOL;\r
   }\r
 \r
   //\r
@@ -616,7 +637,7 @@ Ip6DriverBindingStart (
                   TICKS_PER_MS * IP6_TIMER_INTERVAL_IN_MS\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    goto ON_ERROR;\r
+    goto UNINSTALL_PROTOCOL;\r
   }\r
 \r
   //\r
@@ -628,8 +649,8 @@ Ip6DriverBindingStart (
                   TICKS_PER_MS * IP6_ONE_SECOND_IN_MS\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    goto ON_ERROR;\r
-  }    \r
+    goto UNINSTALL_PROTOCOL;\r
+  }\r
 \r
   //\r
   // Initialize the IP6 ID\r
@@ -638,7 +659,17 @@ Ip6DriverBindingStart (
 \r
   return EFI_SUCCESS;\r
 \r
-ON_ERROR:\r
+UNINSTALL_PROTOCOL:\r
+  gBS->UninstallMultipleProtocolInterfaces (\r
+         ControllerHandle,\r
+         &gEfiIp6ServiceBindingProtocolGuid,\r
+         &IpSb->ServiceBinding,\r
+         &gEfiIp6ConfigProtocolGuid,\r
+         Ip6Cfg,\r
+         NULL\r
+         );\r
+\r
+FREE_SERVICE:\r
   Ip6CleanService (IpSb);\r
   FreePool (IpSb);\r
   return Status;\r
@@ -646,7 +677,7 @@ ON_ERROR:
 \r
 /**\r
   Callback function which provided by user to remove one node in NetDestroyLinkList process.\r
-  \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
@@ -759,8 +790,6 @@ Ip6DriverBindingStop (
                );\r
   } else if (IsListEmpty (&IpSb->Children)) {\r
     State           = IpSb->State;\r
-    IpSb->State     = IP6_SERVICE_DESTROY;\r
-\r
     Status = Ip6CleanService (IpSb);\r
     if (EFI_ERROR (Status)) {\r
       IpSb->State = State;\r
@@ -779,7 +808,7 @@ Ip6DriverBindingStop (
     FreePool (IpSb);\r
     Status = EFI_SUCCESS;\r
   }\r
-  \r
+\r
 Exit:\r
   return Status;\r
 }\r
@@ -795,7 +824,7 @@ Exit:
                                  the existing child handle.\r
 \r
   @retval EFI_SUCCES             The child handle was created with the I/O services.\r
-  @retval EFI_OUT_OF_RESOURCES   There are not enough resources availabe to create\r
+  @retval EFI_OUT_OF_RESOURCES   There are not enough resources available to create\r
                                  the child.\r
   @retval other                  The child handle was not created.\r
 \r