]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/IScsiDxe/IScsiDhcp.c
NetworkPkg/IScsiDxe: Switch IP4 configuration policy to Static before DHCP
[mirror_edk2.git] / NetworkPkg / IScsiDxe / IScsiDhcp.c
index 43ae50bbffacaf23f1d41f0d42034a7fda0255cc..6587a05993535ba6391d82ca91919db6d2aba019 100644 (file)
@@ -371,6 +371,50 @@ IScsiParseDhcpAck (
   return Status;\r
 }\r
 \r
+/**\r
+  This function will switch the IP4 configuration policy to Static.\r
+\r
+  @param[in]  Ip4Config2          Pointer to the IP4 configuration protocol.\r
+\r
+  @retval     EFI_SUCCESS         The policy is already configured to static.\r
+  @retval     Others              Other error as indicated.\r
+\r
+**/\r
+EFI_STATUS\r
+IScsiSetIp4Policy (\r
+  IN EFI_IP4_CONFIG2_PROTOCOL        *Ip4Config2\r
+  )\r
+{\r
+  EFI_IP4_CONFIG2_POLICY          Policy;\r
+  EFI_STATUS                      Status;\r
+  UINTN                           DataSize;\r
+\r
+  DataSize = sizeof (EFI_IP4_CONFIG2_POLICY);\r
+  Status = Ip4Config2->GetData (\r
+                         Ip4Config2,\r
+                         Ip4Config2DataTypePolicy,\r
+                         &DataSize,\r
+                         &Policy\r
+                         );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if (Policy != Ip4Config2PolicyStatic) {\r
+    Policy = Ip4Config2PolicyStatic;\r
+    Status= Ip4Config2->SetData (\r
+                          Ip4Config2,\r
+                          Ip4Config2DataTypePolicy,\r
+                          sizeof (EFI_IP4_CONFIG2_POLICY),\r
+                          &Policy\r
+                          );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    } \r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
 \r
 /**\r
   Parse the DHCP ACK to get the address configuration and DNS information.\r
@@ -393,6 +437,7 @@ IScsiDoDhcp (
   )\r
 {\r
   EFI_HANDLE                    Dhcp4Handle;\r
+  EFI_IP4_CONFIG2_PROTOCOL      *Ip4Config2;\r
   EFI_DHCP4_PROTOCOL            *Dhcp4;\r
   EFI_STATUS                    Status;\r
   EFI_DHCP4_PACKET_OPTION       *ParaList;\r
@@ -401,6 +446,7 @@ IScsiDoDhcp (
   BOOLEAN                       MediaPresent;\r
 \r
   Dhcp4Handle = NULL;\r
+  Ip4Config2  = NULL;\r
   Dhcp4       = NULL;\r
   ParaList    = NULL;\r
 \r
@@ -413,6 +459,21 @@ IScsiDoDhcp (
     return EFI_NO_MEDIA;\r
   }\r
 \r
+  //\r
+  // DHCP4 service allows only one of its children to be configured in  \r
+  // the active state, If the DHCP4 D.O.R.A started by IP4 auto  \r
+  // configuration and has not been completed, the Dhcp4 state machine \r
+  // will not be in the right state for the iSCSI to start a new round D.O.R.A. \r
+  // So, we need to switch it's policy to static.\r
+  //\r
+  Status = gBS->HandleProtocol (Controller, &gEfiIp4Config2ProtocolGuid, (VOID **) &Ip4Config2);\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = IScsiSetIp4Policy (Ip4Config2);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
   //\r
   // Create a DHCP4 child instance and get the protocol.\r
   //\r