]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1. Enabled IP4 layer auto configuration in case cable swap is detected.
authorhhuan13 <hhuan13@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 25 Apr 2011 01:25:11 +0000 (01:25 +0000)
committerhhuan13 <hhuan13@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 25 Apr 2011 01:25:11 +0000 (01:25 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11582 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c
MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.h
MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDriver.c

index 2c74a80308827bb246652ec1e9ff5653177275c9..937da41f2c7a6c5976ead45d84f2d21996f18727 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   This code implements the IP4Config and NicIp4Config protocols.\r
 \r
 /** @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 - 2011, 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
 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
@@ -129,6 +129,17 @@ EfiNicIp4ConfigSetInfo (
     DispatchDpc ();\r
   }\r
 \r
     DispatchDpc ();\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
+  // 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
   return Status;\r
 }\r
 \r
@@ -659,3 +670,57 @@ Ip4ConfigCleanConfig (
   Ip4ConfigCleanDhcp4 (Instance);\r
 }\r
 \r
   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
index eacd89389065a932d21722adeef23a49f2400935..622b87ee032f237f9e615ee164ae3daf2acf3c4b 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Header file for IP4Config driver.\r
 \r
 /** @file\r
   Header file for IP4Config driver.\r
 \r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2011, 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
 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
@@ -128,6 +128,16 @@ typedef struct _IP4_CONFIG_INSTANCE {
   EFI_DHCP4_PROTOCOL              *Dhcp4;\r
   EFI_HANDLE                      Dhcp4Handle;\r
   EFI_EVENT                       Dhcp4Event;\r
   EFI_DHCP4_PROTOCOL              *Dhcp4;\r
   EFI_HANDLE                      Dhcp4Handle;\r
   EFI_EVENT                       Dhcp4Event;\r
+\r
+  //\r
+  // A dedicated timer is used to poll underlying media status\r
+  //\r
+  EFI_EVENT                       Timer;\r
+\r
+  //\r
+  // Underlying media present status. \r
+  //\r
+  BOOLEAN                         MediaPresent; \r
 } IP4_CONFIG_INSTANCE;\r
 \r
 #define IP4_CONFIG_INSTANCE_FROM_IP4CONFIG(this) \\r
 } IP4_CONFIG_INSTANCE;\r
 \r
 #define IP4_CONFIG_INSTANCE_FROM_IP4CONFIG(this) \\r
@@ -496,4 +506,23 @@ EfiIp4ConfigGetData (
   OUT EFI_IP4_IPCONFIG_DATA   *ConfigData           OPTIONAL\r
   );\r
 \r
   OUT EFI_IP4_IPCONFIG_DATA   *ConfigData           OPTIONAL\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 round 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
 #endif\r
 #endif\r
index fdbb26cd78a69f04e47efc33f36f3bf374ce8f1f..9ed9ae82a89bba43aa4cfe8c4ef46e576eca0c2b 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The driver binding for IP4 CONFIG protocol.\r
 \r
 /** @file\r
   The driver binding for IP4 CONFIG protocol.\r
 \r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2011, 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
 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
@@ -77,7 +77,9 @@ IP4_CONFIG_INSTANCE        mIp4ConfigTemplate = {
   (NIC_IP4_CONFIG_INFO *) NULL,\r
   (EFI_DHCP4_PROTOCOL *) NULL,\r
   NULL,\r
   (NIC_IP4_CONFIG_INFO *) NULL,\r
   (EFI_DHCP4_PROTOCOL *) NULL,\r
   NULL,\r
-  NULL\r
+  NULL,\r
+  NULL,\r
+  TRUE\r
 };\r
 \r
 /**\r
 };\r
 \r
 /**\r
@@ -285,6 +287,21 @@ Ip4ConfigDriverBindingStart (
     goto ON_ERROR;\r
   }\r
 \r
     goto ON_ERROR;\r
   }\r
 \r
+  //\r
+  // A dedicated timer is used to poll underlying media status.\r
+  //\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_SIGNAL | EVT_TIMER,\r
+                  TPL_CALLBACK,\r
+                  MediaChangeDetect,\r
+                  Instance,\r
+                  &Instance->Timer\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_ERROR;\r
+  }\r
+\r
   //\r
   // Get the previous configure parameters. If an error happend here,\r
   // just ignore it because the driver should be able to operate.\r
   //\r
   // Get the previous configure parameters. If an error happend here,\r
   // just ignore it because the driver should be able to operate.\r
@@ -476,6 +493,12 @@ Ip4ConfigDriverBindingStop (
     FreePool (Instance->MacString);\r
   }\r
 \r
     FreePool (Instance->MacString);\r
   }\r
 \r
+  if (Instance->Timer != NULL) {\r
+    gBS->SetTimer (Instance->Timer, TimerCancel, 0);\r
+    gBS->CloseEvent (Instance->Timer);\r
+    Instance->Timer = NULL;\r
+  }\r
+  \r
   Ip4ConfigCleanConfig (Instance);\r
   FreePool (Instance);\r
 \r
   Ip4ConfigCleanConfig (Instance);\r
   FreePool (Instance);\r
 \r