]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4Config.c
code scrub fix
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4ConfigDxe / Ip4Config.c
index 4c72a540451adbf2e32d5bde0e3da0b4bc45707a..291ea1a933b62f57cea58f30e754115cda826afd 100644 (file)
@@ -16,24 +16,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 IP4_CONFIG_INSTANCE *mIp4ConfigNicList[MAX_IP4_CONFIG_IN_VARIABLE];\r
 \r
-/**\r
-  Callback function when DHCP process finished. It will save the\r
-  retrieved IP configure parameter from DHCP to the NVRam.\r
-\r
-  @param  Event                  The callback event\r
-  @param  Context                Opaque context to the callback\r
-\r
-  @return None\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-Ip4ConfigOnDhcp4Complete (\r
-  IN EFI_EVENT                  Event,\r
-  IN VOID                       *Context\r
-  );\r
-\r
-\r
 /**\r
   Return the name and MAC address for the NIC. The Name, if not NULL,\r
   has at least IP4_NIC_NAME_LENGTH bytes.\r
@@ -49,9 +31,9 @@ Ip4ConfigOnDhcp4Complete (
 EFI_STATUS\r
 EFIAPI\r
 EfiNicIp4ConfigGetName (\r
-  IN  EFI_NIC_IP4_CONFIG_PROTOCOL *This,\r
-  IN  UINT16                      *Name,          OPTIONAL\r
-  IN  NIC_ADDR                    *NicAddr       OPTIONAL\r
+  IN  EFI_NIC_IP4_CONFIG_PROTOCOL  *This,\r
+  OUT  UINT16                      *Name          OPTIONAL,\r
+  OUT  NIC_ADDR                    *NicAddr       OPTIONAL\r
   )\r
 {\r
   IP4_CONFIG_INSTANCE       *Instance;\r
@@ -75,13 +57,13 @@ EfiNicIp4ConfigGetName (
 \r
 \r
 /**\r
-  Get the NIC's configure information from the IP4 configure  variable.\r
+  Get the NIC's configure information from the IP4 configure variable.\r
   It will remove the invalid variable.\r
 \r
   @param  NicAddr                The NIC to check\r
 \r
   @return NULL if no configure for the NIC in the variable, or it is invalid.\r
-  @return Otherwise the NIC's IP configure parameter.\r
+          Otherwise the pointer to the NIC's IP configure parameter will be returned.\r
 \r
 **/\r
 NIC_IP4_CONFIG_INFO *\r
@@ -134,14 +116,18 @@ Ip4ConfigGetNicInfo (
 /**\r
   Get the configure parameter for this NIC.\r
 \r
-  @param  This                   The NIC IP4 CONFIG protocol\r
+  @param  This                   The NIC IP4 CONFIG protocol.\r
   @param  ConfigLen              The length of the NicConfig buffer.\r
   @param  NicConfig              The buffer to receive the NIC's configure\r
                                  parameter.\r
 \r
-  @retval EFI_INVALID_PARAMETER  This or ConfigLen is NULL\r
+  @retval EFI_SUCCESS            The configure parameter for this NIC was \r
+                                 obtained successfully .\r
+  @retval EFI_INVALID_PARAMETER  This or ConfigLen is NULL.\r
   @retval EFI_NOT_FOUND          There is no configure parameter for the NIC in\r
                                  NVRam.\r
+  @retval EFI_BUFFER_TOO_SMALL   The ConfigLen is too small or the NicConfig is \r
+                                 NULL.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -192,10 +178,11 @@ EfiNicIp4ConfigGetInfo (
 \r
 \r
 /**\r
-  Set the IP configure parameters for this NIC. If Reconfig is TRUE,\r
-  the IP driver will be informed to discard current auto configure\r
-  parameter and restart the auto configuration process. If current\r
-  there is a pending auto configuration, EFI_ALREADY_STARTED is\r
+  Set the IP configure parameters for this NIC. \r
+\r
+  If Reconfig is TRUE, the IP driver will be informed to discard current \r
+  auto configure parameter and restart the auto configuration process. \r
+  If current there is a pending auto configuration, EFI_ALREADY_STARTED is\r
   returned. You can only change the configure setting when either\r
   the configure has finished or not started yet. If NicConfig, the\r
   NIC's configure parameter is removed from the variable.\r
@@ -204,7 +191,9 @@ EfiNicIp4ConfigGetInfo (
   @param  NicConfig              The new NIC IP4 configure parameter\r
   @param  Reconfig               Inform the IP4 driver to restart the auto\r
                                  configuration\r
-\r
+                                 \r
+  @retval EFI_SUCCESS            The configure parameter for this NIC was \r
+                                 set successfully .\r
   @retval EFI_INVALID_PARAMETER  This is NULL or the configure parameter is\r
                                  invalid.\r
   @retval EFI_ALREADY_STARTED    There is a pending auto configuration.\r
@@ -215,7 +204,7 @@ EFI_STATUS
 EFIAPI\r
 EfiNicIp4ConfigSetInfo (\r
   IN EFI_NIC_IP4_CONFIG_PROTOCOL  *This,\r
-  IN NIC_IP4_CONFIG_INFO          *NicConfig,     OPTIONAL\r
+  IN NIC_IP4_CONFIG_INFO          *NicConfig     OPTIONAL,\r
   IN BOOLEAN                      Reconfig\r
   )\r
 {\r
@@ -280,6 +269,120 @@ EfiNicIp4ConfigSetInfo (
   return Status;\r
 }\r
 \r
+/**\r
+  Callback function when DHCP process finished. It will save the\r
+  retrieved IP configure parameter from DHCP to the NVRam.\r
+\r
+  @param  Event                  The callback event\r
+  @param  Context                Opaque context to the callback\r
+\r
+  @return None\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+Ip4ConfigOnDhcp4Complete (\r
+  IN EFI_EVENT              Event,\r
+  IN VOID                   *Context\r
+  )\r
+{\r
+  IP4_CONFIG_INSTANCE       *Instance;\r
+  EFI_DHCP4_MODE_DATA       Dhcp4Mode;\r
+  EFI_IP4_IPCONFIG_DATA     *Ip4Config;\r
+  EFI_STATUS                Status;\r
+  BOOLEAN                   Perment;\r
+  IP4_ADDR                  Subnet;\r
+  IP4_ADDR                  Ip1;\r
+  IP4_ADDR                  Ip2;\r
+\r
+  Instance = (IP4_CONFIG_INSTANCE *) Context;\r
+  ASSERT (Instance->Dhcp4 != NULL);\r
+\r
+  Instance->State   = IP4_CONFIG_STATE_CONFIGURED;\r
+  Instance->Result  = EFI_TIMEOUT;\r
+\r
+  //\r
+  // Get the DHCP retrieved parameters\r
+  //\r
+  Status = Instance->Dhcp4->GetModeData (Instance->Dhcp4, &Dhcp4Mode);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  if (Dhcp4Mode.State == Dhcp4Bound) {\r
+    //\r
+    // Save the new configuration retrieved by DHCP both in\r
+    // the instance and to NVRam. So, both the IP4 driver and\r
+    // other user can get that address.\r
+    //\r
+    Perment = FALSE;\r
+\r
+    if (Instance->NicConfig != NULL) {\r
+      ASSERT (Instance->NicConfig->Source == IP4_CONFIG_SOURCE_DHCP);\r
+      Perment = Instance->NicConfig->Perment;\r
+      gBS->FreePool (Instance->NicConfig);\r
+    }\r
+\r
+    Instance->NicConfig = AllocatePool (sizeof (NIC_IP4_CONFIG_INFO) + 2* sizeof (EFI_IP4_ROUTE_TABLE));\r
+\r
+    if (Instance->NicConfig == NULL) {\r
+      Instance->Result = EFI_OUT_OF_RESOURCES;\r
+      goto ON_EXIT;\r
+    }\r
+\r
+    Instance->NicConfig->Ip4Info.RouteTable = (EFI_IP4_ROUTE_TABLE *) (Instance->NicConfig + 1);\r
+\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
+\r
+    Ip4Config                    = &Instance->NicConfig->Ip4Info;\r
+    Ip4Config->StationAddress    = Dhcp4Mode.ClientAddress;\r
+    Ip4Config->SubnetMask        = Dhcp4Mode.SubnetMask;\r
+\r
+    //\r
+    // Create a route for the connected network\r
+    //\r
+    Ip4Config->RouteTableSize    = 1;\r
+\r
+    CopyMem (&Ip1, &Dhcp4Mode.ClientAddress, sizeof (IP4_ADDR));\r
+    CopyMem (&Ip2, &Dhcp4Mode.SubnetMask, sizeof (IP4_ADDR));\r
+\r
+    Subnet = Ip1 & Ip2;\r
+\r
+    CopyMem (&Ip4Config->RouteTable[0].SubnetAddress, &Subnet, sizeof (EFI_IPv4_ADDRESS));\r
+    CopyMem (&Ip4Config->RouteTable[0].SubnetMask, &Dhcp4Mode.SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
+    ZeroMem (&Ip4Config->RouteTable[0].GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r
+\r
+    //\r
+    // Create a route if there is a default router.\r
+    //\r
+    if (!EFI_IP4_EQUAL (&Dhcp4Mode.RouterAddress, &mZeroIp4Addr)) {\r
+      Ip4Config->RouteTableSize = 2;\r
+\r
+      ZeroMem (&Ip4Config->RouteTable[1].SubnetAddress, sizeof (EFI_IPv4_ADDRESS));\r
+      ZeroMem (&Ip4Config->RouteTable[1].SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
+      CopyMem (&Ip4Config->RouteTable[1].GatewayAddress, &Dhcp4Mode.RouterAddress, sizeof (EFI_IPv4_ADDRESS));\r
+    }\r
+\r
+    Instance->Result = EFI_SUCCESS;\r
+\r
+    //\r
+    // ignore the return status of EfiNicIp4ConfigSetInfo. Network\r
+    // stack can operate even that failed.\r
+    //\r
+    EfiNicIp4ConfigSetInfo (&Instance->NicIp4Protocol, Instance->NicConfig, FALSE);\r
+  }\r
+\r
+ON_EXIT:\r
+  gBS->SignalEvent (Instance->DoneEvent);\r
+  Ip4ConfigCleanDhcp4 (Instance);\r
+\r
+  NetLibDispatchDpc ();\r
+\r
+  return ;\r
+}\r
 \r
 /**\r
   Starts running the configuration policy for the EFI IPv4 Protocol driver.\r
@@ -557,8 +660,9 @@ ON_EXIT:
   @retval EFI_INVALID_PARAMETER  This is NULL.\r
   @retval EFI_NOT_STARTED        The configuration policy for the EFI IPv4 Protocol \r
                                  driver is not running.\r
-  @retval EFI_NOT_READY EFI      IPv4 Protocol driver configuration is still running.\r
-  @retval EFI_ABORTED EFI        IPv4 Protocol driver configuration could not complete.\r
+  @retval EFI_NOT_READY          EFI IPv4 Protocol driver configuration is still running.\r
+  @retval EFI_ABORTED            EFI IPv4 Protocol driver configuration could not complete.\r
+                                 Currently not implemented.\r
   @retval EFI_BUFFER_TOO_SMALL   *ConfigDataSize is smaller than the configuration \r
                                  data buffer or ConfigData is NULL.\r
 \r
@@ -623,123 +727,6 @@ ON_EXIT:
   return Status;\r
 }\r
 \r
-\r
-/**\r
-  Callback function when DHCP process finished. It will save the\r
-  retrieved IP configure parameter from DHCP to the NVRam.\r
-\r
-  @param  Event                  The callback event\r
-  @param  Context                Opaque context to the callback\r
-\r
-  @return None\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-Ip4ConfigOnDhcp4Complete (\r
-  IN EFI_EVENT              Event,\r
-  IN VOID                   *Context\r
-  )\r
-{\r
-  IP4_CONFIG_INSTANCE       *Instance;\r
-  EFI_DHCP4_MODE_DATA       Dhcp4Mode;\r
-  EFI_IP4_IPCONFIG_DATA     *Ip4Config;\r
-  EFI_STATUS                Status;\r
-  BOOLEAN                   Perment;\r
-  IP4_ADDR                  Subnet;\r
-  IP4_ADDR                  Ip1;\r
-  IP4_ADDR                  Ip2;\r
-\r
-  Instance = (IP4_CONFIG_INSTANCE *) Context;\r
-  ASSERT (Instance->Dhcp4 != NULL);\r
-\r
-  Instance->State   = IP4_CONFIG_STATE_CONFIGURED;\r
-  Instance->Result  = EFI_TIMEOUT;\r
-\r
-  //\r
-  // Get the DHCP retrieved parameters\r
-  //\r
-  Status = Instance->Dhcp4->GetModeData (Instance->Dhcp4, &Dhcp4Mode);\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    goto ON_EXIT;\r
-  }\r
-\r
-  if (Dhcp4Mode.State == Dhcp4Bound) {\r
-    //\r
-    // Save the new configuration retrieved by DHCP both in\r
-    // the instance and to NVRam. So, both the IP4 driver and\r
-    // other user can get that address.\r
-    //\r
-    Perment = FALSE;\r
-\r
-    if (Instance->NicConfig != NULL) {\r
-      ASSERT (Instance->NicConfig->Source == IP4_CONFIG_SOURCE_DHCP);\r
-      Perment = Instance->NicConfig->Perment;\r
-      gBS->FreePool (Instance->NicConfig);\r
-    }\r
-\r
-    Instance->NicConfig = AllocatePool (sizeof (NIC_IP4_CONFIG_INFO) + 2* sizeof (EFI_IP4_ROUTE_TABLE));\r
-\r
-    if (Instance->NicConfig == NULL) {\r
-      Instance->Result = EFI_OUT_OF_RESOURCES;\r
-      goto ON_EXIT;\r
-    }\r
-\r
-    Instance->NicConfig->Ip4Info.RouteTable = (EFI_IP4_ROUTE_TABLE *) (Instance->NicConfig + 1);\r
-\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
-\r
-    Ip4Config                    = &Instance->NicConfig->Ip4Info;\r
-    Ip4Config->StationAddress    = Dhcp4Mode.ClientAddress;\r
-    Ip4Config->SubnetMask        = Dhcp4Mode.SubnetMask;\r
-\r
-    //\r
-    // Create a route for the connected network\r
-    //\r
-    Ip4Config->RouteTableSize    = 1;\r
-\r
-    CopyMem (&Ip1, &Dhcp4Mode.ClientAddress, sizeof (IP4_ADDR));\r
-    CopyMem (&Ip2, &Dhcp4Mode.SubnetMask, sizeof (IP4_ADDR));\r
-\r
-    Subnet = Ip1 & Ip2;\r
-\r
-    CopyMem (&Ip4Config->RouteTable[0].SubnetAddress, &Subnet, sizeof (EFI_IPv4_ADDRESS));\r
-    CopyMem (&Ip4Config->RouteTable[0].SubnetMask, &Dhcp4Mode.SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
-    ZeroMem (&Ip4Config->RouteTable[0].GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r
-\r
-    //\r
-    // Create a route if there is a default router.\r
-    //\r
-    if (!EFI_IP4_EQUAL (&Dhcp4Mode.RouterAddress, &mZeroIp4Addr)) {\r
-      Ip4Config->RouteTableSize = 2;\r
-\r
-      ZeroMem (&Ip4Config->RouteTable[1].SubnetAddress, sizeof (EFI_IPv4_ADDRESS));\r
-      ZeroMem (&Ip4Config->RouteTable[1].SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
-      CopyMem (&Ip4Config->RouteTable[1].GatewayAddress, &Dhcp4Mode.RouterAddress, sizeof (EFI_IPv4_ADDRESS));\r
-    }\r
-\r
-    Instance->Result = EFI_SUCCESS;\r
-\r
-    //\r
-    // ignore the return status of EfiNicIp4ConfigSetInfo. Network\r
-    // stack can operate even that failed.\r
-    //\r
-    EfiNicIp4ConfigSetInfo (&Instance->NicIp4Protocol, Instance->NicConfig, FALSE);\r
-  }\r
-\r
-ON_EXIT:\r
-  gBS->SignalEvent (Instance->DoneEvent);\r
-  Ip4ConfigCleanDhcp4 (Instance);\r
-\r
-  NetLibDispatchDpc ();\r
-\r
-  return ;\r
-}\r
-\r
-\r
 /**\r
   Release all the DHCP related resources.\r
 \r