]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c
MdeModulePkg/Ip4Dxe: return error on memory allocate failure instead of ASSERT.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Driver.c
index 3dc4d88f13b7d2bed0933b4a9be21f12f50a63ef..49b7dc55d5da3feed2b40ee57bc963542ae549c8 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The driver binding and service binding protocol for IP4 driver.\r
 \r
-Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2017, 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
@@ -254,7 +262,7 @@ Ip4CreateService (
 \r
   //\r
   // Create various resources. First create the route table, timer\r
-  // event and MNP child. IGMP, interface's initialization depend\r
+  // event, ReconfigEvent and MNP child. IGMP, interface's initialization depend\r
   // on the MNP child.\r
   //\r
   IpSb->DefaultRouteTable = Ip4CreateRouteTable ();\r
@@ -276,6 +284,17 @@ Ip4CreateService (
     goto ON_ERROR;\r
   }\r
 \r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  Ip4AutoReconfigCallBack,\r
+                  IpSb,\r
+                  &IpSb->ReconfigEvent\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_ERROR;\r
+  }\r
+\r
   Status = NetLibCreateServiceChild (\r
              Controller,\r
              ImageHandle,\r
@@ -382,6 +401,15 @@ Ip4CleanService (
 {\r
   EFI_STATUS                Status;\r
 \r
+  IpSb->State     = IP4_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->DefaultInterface != NULL) {\r
     Status = Ip4FreeInterface (IpSb->DefaultInterface, NULL);\r
 \r
@@ -421,13 +449,6 @@ Ip4CleanService (
     IpSb->MnpChildHandle = NULL;\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->ReconfigEvent != NULL) {\r
     gBS->CloseEvent (IpSb->ReconfigEvent);\r
 \r
@@ -511,6 +532,13 @@ Ip4DriverBindingStart (
 { \r
   EFI_STATUS                    Status;\r
   IP4_SERVICE                   *IpSb;\r
+  EFI_IP4_CONFIG2_PROTOCOL      *Ip4Cfg2;\r
+  UINTN                         Index;\r
+  IP4_CONFIG2_DATA_ITEM         *DataItem;\r
+\r
+  IpSb     = NULL;\r
+  Ip4Cfg2  = NULL;\r
+  DataItem = NULL;\r
 \r
   //\r
   // Test for the Ip4 service binding protocol\r
@@ -536,6 +564,8 @@ Ip4DriverBindingStart (
   \r
   ASSERT (IpSb != NULL);\r
 \r
+  Ip4Cfg2  = &IpSb->Ip4Config2Instance.Ip4Config2;\r
+\r
   //\r
   // Install the Ip4ServiceBinding Protocol onto ControlerHandle\r
   //\r
@@ -544,13 +574,44 @@ Ip4DriverBindingStart (
                   &gEfiIp4ServiceBindingProtocolGuid,\r
                   &IpSb->ServiceBinding,\r
                   &gEfiIp4Config2ProtocolGuid,\r
-                  &IpSb->Ip4Config2Instance.Ip4Config2,\r
+                  Ip4Cfg2,\r
                   NULL\r
                   );\r
 \r
   if (EFI_ERROR (Status)) {\r
     goto FREE_SERVICE;\r
   }\r
+\r
+  //\r
+  // Read the config data from NV variable again. \r
+  // The default data can be changed by other drivers.\r
+  //\r
+  Status = Ip4Config2ReadConfigData (IpSb->MacString, &IpSb->Ip4Config2Instance);\r
+  if (EFI_ERROR (Status)) {\r
+    goto UNINSTALL_PROTOCOL;\r
+  }\r
+  \r
+  //\r
+  // Consume the installed EFI_IP4_CONFIG2_PROTOCOL to set the default data items. \r
+  //\r
+  for (Index = Ip4Config2DataTypePolicy; Index < Ip4Config2DataTypeMaximum; Index++) {\r
+    DataItem = &IpSb->Ip4Config2Instance.DataItem[Index];\r
+    if (DataItem->Data.Ptr != NULL) {\r
+      Status = Ip4Cfg2->SetData (\r
+                          Ip4Cfg2,\r
+                          Index,\r
+                          DataItem->DataSize,\r
+                          DataItem->Data.Ptr\r
+                          );\r
+      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
   //\r
   // Ready to go: start the receiving and timer.\r
@@ -703,8 +764,6 @@ Ip4DriverBindingStop (
 \r
   } else if (IsListEmpty (&IpSb->Children)) {\r
     State           = IpSb->State;\r
-    IpSb->State     = IP4_SERVICE_DESTROY;\r
-\r
     //\r
     // OK, clean other resources then uninstall the service binding protocol.\r
     //\r
@@ -749,7 +808,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
@@ -871,7 +930,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
@@ -909,13 +967,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
@@ -958,6 +1015,7 @@ Ip4ServiceBindingDestroyChild (
                   );\r
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
   if (EFI_ERROR (Status)) {\r
+    IpInstance->InDestroy = FALSE;\r
     goto ON_ERROR;\r
   }\r
 \r
@@ -982,7 +1040,6 @@ Ip4ServiceBindingDestroyChild (
   return EFI_SUCCESS;\r
 \r
 ON_ERROR:\r
-  IpInstance->State = State;\r
   gBS->RestoreTPL (OldTpl);\r
 \r
   return Status;\r