]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c
MdeModulePkg: INF/DEC file updates to EDK II packages
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4ConfigDxe / Ip4Config.c
index 2c74a80308827bb246652ec1e9ff5653177275c9..3eff1882e779dfccbda8e0c06c3acaed4dbfc897 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   This code implements the IP4Config and NicIp4Config protocols.\r
 \r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 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 of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at<BR>\r
@@ -125,10 +125,33 @@ EfiNicIp4ConfigSetInfo (
   // Signal the IP4 to run the auto configuration again\r
   //\r
   if (Reconfig && (Instance->ReconfigEvent != NULL)) {\r
+    //\r
+    // When NicConfig is NULL, NIC IP4 configuration parameter is removed,\r
+    // the auto configuration process should stop running the configuration\r
+    // policy for the EFI IPv4 Protocol driver.\r
+    //\r
+    if (NicConfig == NULL) {\r
+      Instance->DoNotStart = TRUE;\r
+    }\r
+\r
     Status = gBS->SignalEvent (Instance->ReconfigEvent);\r
     DispatchDpc ();\r
   }\r
 \r
+  if (NicConfig == NULL) {\r
+    return Status;\r
+  }\r
+  //\r
+  // A dedicated timer is used to poll underlying media status.In case of\r
+  // cable swap, a new round auto configuration will be initiated. The timer\r
+  // starts in DHCP policy only. STATIC policy stops the timer.\r
+  // \r
+  if (NicConfig->Source == IP4_CONFIG_SOURCE_DHCP) {\r
+    gBS->SetTimer (Instance->Timer, TimerPeriodic, TICKS_PER_SECOND);\r
+  } else if (NicConfig->Source == IP4_CONFIG_SOURCE_STATIC) {\r
+    gBS->SetTimer (Instance->Timer, TimerCancel, 0);\r
+  }\r
+  \r
   return Status;\r
 }\r
 \r
@@ -153,7 +176,7 @@ Ip4ConfigOnDhcp4Complete (
   EFI_DHCP4_MODE_DATA       Dhcp4Mode;\r
   EFI_IP4_IPCONFIG_DATA     *Ip4Config;\r
   EFI_STATUS                Status;\r
-  BOOLEAN                   Perment;\r
+  BOOLEAN                   Permanent;\r
   IP4_ADDR                  Subnet;\r
   IP4_ADDR                  Ip1;\r
   IP4_ADDR                  Ip2;\r
@@ -179,11 +202,11 @@ Ip4ConfigOnDhcp4Complete (
     // the instance and to NVRam. So, both the IP4 driver and\r
     // other user can get that address.\r
     //\r
-    Perment = FALSE;\r
+    Permanent = FALSE;\r
 \r
     if (Instance->NicConfig != NULL) {\r
       ASSERT (Instance->NicConfig->Source == IP4_CONFIG_SOURCE_DHCP);\r
-      Perment = Instance->NicConfig->Perment;\r
+      Permanent = Instance->NicConfig->Permanent;\r
       FreePool (Instance->NicConfig);\r
     }\r
 \r
@@ -198,7 +221,7 @@ Ip4ConfigOnDhcp4Complete (
 \r
     CopyMem (&Instance->NicConfig->NicAddr, &Instance->NicAddr, sizeof (Instance->NicConfig->NicAddr));\r
     Instance->NicConfig->Source  = IP4_CONFIG_SOURCE_DHCP;\r
-    Instance->NicConfig->Perment = Perment;\r
+    Instance->NicConfig->Permanent = Permanent;\r
 \r
     Ip4Config                    = &Instance->NicConfig->Ip4Info;\r
     Ip4Config->StationAddress    = Dhcp4Mode.ClientAddress;\r
@@ -330,6 +353,12 @@ EfiIp4ConfigStart (
   Instance->NicConfig     = EfiNicIp4ConfigGetInfo (Instance);\r
 \r
   if (Instance->NicConfig == NULL) {\r
+    if (Instance->DoNotStart) {\r
+      Instance->DoNotStart = FALSE;\r
+      Status = EFI_SUCCESS;\r
+      goto ON_EXIT;\r
+    }\r
+\r
     Source = IP4_CONFIG_SOURCE_DHCP;\r
   } else {\r
     Source = Instance->NicConfig->Source;\r
@@ -659,3 +688,57 @@ Ip4ConfigCleanConfig (
   Ip4ConfigCleanDhcp4 (Instance);\r
 }\r
 \r
+\r
+/**\r
+  A dedicated timer is used to poll underlying media status. In case of\r
+  cable swap, a new round auto configuration will be initiated. The timer \r
+  will signal the IP4 to run the auto configuration again. IP4 driver will free\r
+  old IP address related resource, such as route table and Interface, then\r
+  initiate a DHCP process by IP4Config->Start to acquire new IP, eventually\r
+  create route table for new IP address.\r
+\r
+  @param[in]  Event                  The IP4 service instance's heart beat timer.\r
+  @param[in]  Context                The IP4 service instance.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+MediaChangeDetect (\r
+  IN EFI_EVENT              Event,\r
+  IN VOID                   *Context\r
+  )\r
+{\r
+  BOOLEAN                      OldMediaPresent;\r
+  EFI_STATUS                   Status;\r
+  EFI_SIMPLE_NETWORK_MODE      SnpModeData;\r
+  IP4_CONFIG_INSTANCE         *Instance;  \r
+\r
+  Instance = (IP4_CONFIG_INSTANCE *) Context;\r
+\r
+  OldMediaPresent = Instance->MediaPresent;\r
+  \r
+  //\r
+  // Get fresh mode data from MNP, since underlying media status may change\r
+  //\r
+  Status = Instance->Mnp->GetModeData (Instance->Mnp, NULL, &SnpModeData);\r
+  if (EFI_ERROR (Status) && (Status != EFI_NOT_STARTED)) {\r
+    return;\r
+  }\r
+\r
+  Instance->MediaPresent = SnpModeData.MediaPresent;\r
+  //\r
+  // Media transimit Unpresent to Present means new link movement is detected.\r
+  //\r
+  if (!OldMediaPresent && Instance->MediaPresent) {\r
+    //\r
+    // Signal the IP4 to run the auto configuration again. IP4 driver will free\r
+    // old IP address related resource, such as route table and Interface, then \r
+    // initiate a DHCP round by IP4Config->Start to acquire new IP, eventually \r
+    // create route table for new IP address.\r
+    //\r
+    if (Instance->ReconfigEvent != NULL) {\r
+      Status = gBS->SignalEvent (Instance->ReconfigEvent);\r
+      DispatchDpc ();\r
+    }\r
+  }\r
+}\r