]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c
MdeModulePkg/Ip4Dxe: Add an independent timer for reconfig checking
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Driver.c
index fcd3ccb9fd2c218201dd032dff1a32822e9e6edb..552c4e190b40cde75a6b74e1e4ca9bcb5ecb572c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The driver binding and service binding protocol for IP4 driver.\r
 \r
-Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2018, 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
@@ -41,12 +41,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
+  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
-  mIpSec2Installed = TRUE;\r
+    mIpSec2Installed = TRUE;\r
+  }\r
 }\r
 \r
 /**\r
@@ -245,6 +253,7 @@ Ip4CreateService (
   ZeroMem (&IpSb->SnpMode, sizeof (EFI_SIMPLE_NETWORK_MODE));\r
 \r
   IpSb->Timer = NULL;\r
+  IpSb->ReconfigCheckTimer = NULL;\r
 \r
   IpSb->ReconfigEvent = NULL;\r
 \r
@@ -276,6 +285,18 @@ Ip4CreateService (
     goto ON_ERROR;\r
   }\r
 \r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_SIGNAL | EVT_TIMER,\r
+                  TPL_CALLBACK,\r
+                  Ip4TimerReconfigChecking,\r
+                  IpSb,\r
+                  &IpSb->ReconfigCheckTimer\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_ERROR;\r
+  }\r
+\r
   Status = gBS->CreateEvent (\r
                   EVT_NOTIFY_SIGNAL,\r
                   TPL_NOTIFY,\r
@@ -402,6 +423,13 @@ Ip4CleanService (
     IpSb->Timer = NULL;\r
   }\r
 \r
+  if (IpSb->ReconfigCheckTimer != NULL) {\r
+    gBS->SetTimer (IpSb->ReconfigCheckTimer, TimerCancel, 0);\r
+    gBS->CloseEvent (IpSb->ReconfigCheckTimer);\r
+\r
+    IpSb->ReconfigCheckTimer = NULL;\r
+  }\r
+\r
   if (IpSb->DefaultInterface != NULL) {\r
     Status = Ip4FreeInterface (IpSb->DefaultInterface, NULL);\r
 \r
@@ -598,6 +626,10 @@ Ip4DriverBindingStart (
       if (EFI_ERROR(Status)) {\r
         goto UNINSTALL_PROTOCOL;\r
       }\r
+      \r
+      if (Index == Ip4Config2DataTypePolicy && (*(DataItem->Data.Policy) == Ip4Config2PolicyDhcp)) {\r
+        break;\r
+      } \r
     }\r
   }\r
  \r
@@ -618,6 +650,12 @@ Ip4DriverBindingStart (
     goto UNINSTALL_PROTOCOL;\r
   }\r
 \r
+  Status = gBS->SetTimer (IpSb->ReconfigCheckTimer, TimerPeriodic, 500 * TICKS_PER_MS);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    goto UNINSTALL_PROTOCOL;\r
+  }\r
+\r
   //\r
   // Initialize the IP4 ID\r
   //\r
@@ -796,7 +834,7 @@ ON_ERROR:
 \r
   @retval EFI_SUCCES            The protocol was added to ChildHandle.\r
   @retval EFI_INVALID_PARAMETER ChildHandle is NULL.\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
@@ -918,7 +956,6 @@ Ip4ServiceBindingDestroyChild (
   IP4_PROTOCOL              *IpInstance;\r
   EFI_IP4_PROTOCOL          *Ip4;\r
   EFI_TPL                   OldTpl;\r
-  INTN                      State;\r
 \r
   if ((This == NULL) || (ChildHandle == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -956,13 +993,12 @@ Ip4ServiceBindingDestroyChild (
   // when UDP driver is being stopped, it will destroy all\r
   // the IP child it opens.\r
   //\r
-  if (IpInstance->State == IP4_STATE_DESTROY) {\r
+  if (IpInstance->InDestroy) {\r
     gBS->RestoreTPL (OldTpl);\r
     return EFI_SUCCESS;\r
   }\r
 \r
-  State             = IpInstance->State;\r
-  IpInstance->State = IP4_STATE_DESTROY;\r
+  IpInstance->InDestroy = TRUE;\r
 \r
   //\r
   // Close the Managed Network protocol.\r
@@ -1005,6 +1041,7 @@ Ip4ServiceBindingDestroyChild (
                   );\r
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
   if (EFI_ERROR (Status)) {\r
+    IpInstance->InDestroy = FALSE;\r
     goto ON_ERROR;\r
   }\r
 \r
@@ -1029,7 +1066,6 @@ Ip4ServiceBindingDestroyChild (
   return EFI_SUCCESS;\r
 \r
 ON_ERROR:\r
-  IpInstance->State = State;\r
   gBS->RestoreTPL (OldTpl);\r
 \r
   return Status;\r