]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/IScsiDxe/IScsiDhcp.c
NetworkPkg/HttpDxe: Fix build warning error if CHAR8 is unsigned.
[mirror_edk2.git] / NetworkPkg / IScsiDxe / IScsiDhcp.c
index 3706256db5f76e676035117383ad19be93a4bc05..e34352370c6ed0b5a73e1c7b2bd2bd112ad789ba 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   iSCSI DHCP4 related configuration routines.\r
 \r
-Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2017, 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\r
@@ -123,11 +123,25 @@ IScsiDhcpExtractRootPath (
     IpMode = ConfigData->AutoConfigureMode;\r
   }\r
 \r
-  Status = IScsiAsciiStrToIp (Field->Str, IpMode, &Ip);\r
-  CopyMem (&ConfigNvData->TargetIp, &Ip, sizeof (EFI_IP_ADDRESS));\r
+  //\r
+  // Server name is expressed as domain name, just save it.\r
+  //\r
+  if ((!NET_IS_DIGIT (*(Field->Str))) && (*(Field->Str) != '[')) {\r
+    ConfigNvData->DnsMode = TRUE;\r
+    if (Field->Len > sizeof (ConfigNvData->TargetUrl)) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    CopyMem (&ConfigNvData->TargetUrl, Field->Str, Field->Len);\r
+    ConfigNvData->TargetUrl[Field->Len + 1] = '\0';\r
+  } else {\r
+    ConfigNvData->DnsMode = FALSE;\r
+    ZeroMem(ConfigNvData->TargetUrl, sizeof (ConfigNvData->TargetUrl));\r
+    Status = IScsiAsciiStrToIp (Field->Str, IpMode, &Ip);\r
+    CopyMem (&ConfigNvData->TargetIp, &Ip, sizeof (EFI_IP_ADDRESS));\r
 \r
-  if (EFI_ERROR (Status)) {\r
-    goto ON_EXIT;\r
+    if (EFI_ERROR (Status)) {\r
+      goto ON_EXIT;\r
+    }\r
   }\r
   //\r
   // Check the protocol type.\r
@@ -175,7 +189,7 @@ IScsiDhcpExtractRootPath (
     goto ON_EXIT;\r
   }\r
 \r
-  AsciiStrCpy (ConfigNvData->TargetName, Field->Str);\r
+  AsciiStrCpyS (ConfigNvData->TargetName, ISCSI_NAME_MAX_SIZE, Field->Str);\r
 \r
 ON_EXIT:\r
 \r
@@ -240,7 +254,7 @@ IScsiDhcpSelectOffer (
   }\r
 \r
   for (Index = 0; Index < OptionCount; Index++) {\r
-    if (OptionList[Index]->OpCode != DHCP4_TAG_ROOT_PATH) {\r
+    if (OptionList[Index]->OpCode != DHCP4_TAG_ROOTPATH) {\r
       continue;\r
     }\r
 \r
@@ -253,7 +267,7 @@ IScsiDhcpSelectOffer (
     break;\r
   }\r
 \r
-  if ((Index == OptionCount)) {\r
+  if (Index == OptionCount) {\r
     Status = EFI_NOT_READY;\r
   }\r
 \r
@@ -326,7 +340,7 @@ IScsiParseDhcpAck (
     //\r
     // Get DNS server addresses and DHCP server address from this offer.\r
     //\r
-    if (OptionList[Index]->OpCode == DHCP4_TAG_DNS) {\r
+    if (OptionList[Index]->OpCode == DHCP4_TAG_DNS_SERVER) {\r
 \r
       if (((OptionList[Index]->Length & 0x3) != 0) || (OptionList[Index]->Length == 0)) {\r
         Status = EFI_INVALID_PARAMETER;\r
@@ -358,6 +372,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
@@ -380,26 +438,44 @@ 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
   EFI_DHCP4_CONFIG_DATA         Dhcp4ConfigData;\r
   ISCSI_SESSION_CONFIG_NVDATA   *NvData;\r
-  BOOLEAN                       MediaPresent;\r
+  EFI_STATUS                    MediaStatus;\r
 \r
   Dhcp4Handle = NULL;\r
+  Ip4Config2  = NULL;\r
   Dhcp4       = NULL;\r
   ParaList    = NULL;\r
 \r
   //\r
   // Check media status before doing DHCP.\r
   //\r
-  MediaPresent = TRUE;\r
-  NetLibDetectMedia (Controller, &MediaPresent);\r
-  if (!MediaPresent) {\r
+  MediaStatus = EFI_SUCCESS;\r
+  NetLibDetectMediaWaitTimeout (Controller, ISCSI_CHECK_MEDIA_GET_DHCP_WAITING_TIME, &MediaStatus);\r
+  if (MediaStatus!= EFI_SUCCESS) {\r
+    AsciiPrint ("\n  Error: Could not detect network connection.\n");\r
     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
@@ -440,8 +516,8 @@ IScsiDoDhcp (
   ParaList->Length  = (UINT8) (NvData->TargetInfoFromDhcp ? 4 : 3);\r
   ParaList->Data[0] = DHCP4_TAG_NETMASK;\r
   ParaList->Data[1] = DHCP4_TAG_ROUTER;\r
-  ParaList->Data[2] = DHCP4_TAG_DNS;\r
-  ParaList->Data[3] = DHCP4_TAG_ROOT_PATH;\r
+  ParaList->Data[2] = DHCP4_TAG_DNS_SERVER;\r
+  ParaList->Data[3] = DHCP4_TAG_ROOTPATH;\r
 \r
   ZeroMem (&Dhcp4ConfigData, sizeof (EFI_DHCP4_CONFIG_DATA));\r
   Dhcp4ConfigData.OptionCount = 1;\r