]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Fix a bug about the iSCSI DHCP dependency issue.
authorWu Jiaxin <jiaxin.wu@intel.com>
Fri, 25 Oct 2013 08:07:26 +0000 (08:07 +0000)
committerjiaxinwu <jiaxinwu@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 25 Oct 2013 08:07:26 +0000 (08:07 +0000)
Create rules to determine whether iSCSI need DHCP protocol in current configuration by examining user’s configuration data in DriverBindingSupported().

Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com >
Reviewed-by: Ye Ting <ting.ye@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14803 6f19259b-4bc3-4df7-8a09-765794883524

NetworkPkg/IScsiDxe/IScsiDriver.c
NetworkPkg/IScsiDxe/IScsiMisc.c
NetworkPkg/IScsiDxe/IScsiMisc.h

index cc452e711048314fed534522312928d223930013..6d6f9a13ed8b8f33059872bc1f1dd3b7b27682ca 100644 (file)
@@ -112,13 +112,16 @@ IScsiSupported (
   EFI_STATUS                Status;\r
   EFI_GUID                  *IScsiServiceBindingGuid;\r
   EFI_GUID                  *TcpServiceBindingGuid;\r
   EFI_STATUS                Status;\r
   EFI_GUID                  *IScsiServiceBindingGuid;\r
   EFI_GUID                  *TcpServiceBindingGuid;\r
+  EFI_GUID                  *DhcpServiceBindingGuid;\r
 \r
   if (IpVersion == IP_VERSION_4) {\r
     IScsiServiceBindingGuid  = &gIScsiV4PrivateGuid;\r
     TcpServiceBindingGuid    = &gEfiTcp4ServiceBindingProtocolGuid;\r
 \r
   if (IpVersion == IP_VERSION_4) {\r
     IScsiServiceBindingGuid  = &gIScsiV4PrivateGuid;\r
     TcpServiceBindingGuid    = &gEfiTcp4ServiceBindingProtocolGuid;\r
+    DhcpServiceBindingGuid   = &gEfiDhcp4ServiceBindingProtocolGuid;\r
   } else {\r
     IScsiServiceBindingGuid  = &gIScsiV6PrivateGuid;\r
     TcpServiceBindingGuid    = &gEfiTcp6ServiceBindingProtocolGuid;\r
   } else {\r
     IScsiServiceBindingGuid  = &gIScsiV6PrivateGuid;\r
     TcpServiceBindingGuid    = &gEfiTcp6ServiceBindingProtocolGuid;\r
+    DhcpServiceBindingGuid   = &gEfiDhcp6ServiceBindingProtocolGuid;\r
   }\r
 \r
   Status = gBS->OpenProtocol (\r
   }\r
 \r
   Status = gBS->OpenProtocol (\r
@@ -131,24 +134,40 @@ IScsiSupported (
                   );\r
   if (!EFI_ERROR (Status)) {\r
     return EFI_ALREADY_STARTED;\r
                   );\r
   if (!EFI_ERROR (Status)) {\r
     return EFI_ALREADY_STARTED;\r
-  } else {\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  TcpServiceBindingGuid,\r
+                  NULL,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Status = IScsiIsDevicePathSupported (RemainingDevicePath);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (IScsiDhcpIsConfigured (ControllerHandle, IpVersion)) {\r
     Status = gBS->OpenProtocol (\r
                     ControllerHandle,\r
     Status = gBS->OpenProtocol (\r
                     ControllerHandle,\r
-                    TcpServiceBindingGuid,\r
+                    DhcpServiceBindingGuid,\r
                     NULL,\r
                     This->DriverBindingHandle,\r
                     ControllerHandle,\r
                     EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
                     );\r
                     NULL,\r
                     This->DriverBindingHandle,\r
                     ControllerHandle,\r
                     EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
                     );\r
-    if (!EFI_ERROR (Status)) {\r
-      Status = IScsiIsDevicePathSupported (RemainingDevicePath);\r
-      if (!EFI_ERROR (Status)) {\r
-        return EFI_SUCCESS;\r
-      }\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_UNSUPPORTED;\r
     }\r
   }\r
     }\r
   }\r
-\r
-  return EFI_UNSUPPORTED;\r
+  \r
+  return EFI_SUCCESS;\r
 }\r
 \r
 \r
 }\r
 \r
 \r
index 971011eac52884a636eb7cf167dd2501da5c6148..1079c187fa22810d978200250a1a107d1f3593e9 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Miscellaneous routines for iSCSI driver.\r
 \r
 /** @file\r
   Miscellaneous routines for iSCSI driver.\r
 \r
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2013, 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
 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
@@ -890,6 +890,99 @@ IScsiCleanDriverData (
   FreePool (Private);\r
 }\r
 \r
   FreePool (Private);\r
 }\r
 \r
+/**\r
+  Check wheather the Controller handle is configured to use DHCP protocol.\r
+\r
+  @param[in]  Controller           The handle of the controller.\r
+  @param[in]  IpVersion            IP_VERSION_4 or IP_VERSION_6.\r
+  \r
+  @retval TRUE                     The handle of the controller need the Dhcp protocol.\r
+  @retval FALSE                    The handle of the controller does not need the Dhcp protocol.\r
+  \r
+**/\r
+BOOLEAN\r
+IScsiDhcpIsConfigured (\r
+  IN EFI_HANDLE  Controller,\r
+  IN UINT8       IpVersion\r
+  )\r
+{\r
+  ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptTmp;\r
+  UINT8                       *AttemptConfigOrder;\r
+  UINTN                       AttemptConfigOrderSize;\r
+  UINTN                       Index;\r
+  EFI_STATUS                  Status;\r
+  EFI_MAC_ADDRESS             MacAddr;\r
+  UINTN                       HwAddressSize;\r
+  UINT16                      VlanId;\r
+  CHAR16                      MacString[ISCSI_MAX_MAC_STRING_LEN];\r
+  CHAR16                      AttemptName[ISCSI_NAME_IFR_MAX_SIZE];\r
+  \r
+  AttemptConfigOrder = IScsiGetVariableAndSize (\r
+                         L"AttemptOrder",\r
+                         &gIScsiConfigGuid,\r
+                         &AttemptConfigOrderSize\r
+                         );\r
+  if (AttemptConfigOrder == NULL || AttemptConfigOrderSize == 0) {\r
+    return FALSE;\r
+  }\r
+  \r
+  //\r
+  // Get MAC address of this network device.\r
+  //\r
+  Status = NetLibGetMacAddress (Controller, &MacAddr, &HwAddressSize);\r
+  if(EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  }\r
+  //\r
+  // Get VLAN ID of this network device.\r
+  //\r
+  VlanId = NetLibGetVlanId (Controller);\r
+  IScsiMacAddrToStr (&MacAddr, (UINT32) HwAddressSize, VlanId, MacString);\r
+  \r
+  for (Index = 0; Index < AttemptConfigOrderSize / sizeof (UINT8); Index++) {\r
+    UnicodeSPrint (\r
+      AttemptName,\r
+      (UINTN) 128,\r
+      L"%s%d",\r
+      MacString,\r
+      (UINTN) AttemptConfigOrder[Index]\r
+      );\r
+    Status = GetVariable2 (\r
+               AttemptName,\r
+               &gEfiIScsiInitiatorNameProtocolGuid,\r
+               (VOID**)&AttemptTmp,\r
+               NULL\r
+               );\r
+    if(EFI_ERROR (Status)) {\r
+      continue;\r
+    }\r
+    ASSERT (AttemptConfigOrder[Index] == AttemptTmp->AttemptConfigIndex);\r
+\r
+    if (AttemptTmp->SessionConfigData.Enabled == ISCSI_DISABLED) {\r
+      FreePool (AttemptTmp);\r
+      continue;\r
+    }\r
+\r
+    if (AttemptTmp->SessionConfigData.IpMode != IP_MODE_AUTOCONFIG && \r
+        AttemptTmp->SessionConfigData.IpMode != ((IpVersion == IP_VERSION_4) ? IP_MODE_IP4 : IP_MODE_IP6)) {\r
+      FreePool (AttemptTmp);\r
+      continue;\r
+    }\r
+    \r
+    if(AttemptTmp->SessionConfigData.IpMode == IP_MODE_AUTOCONFIG ||\r
+       AttemptTmp->SessionConfigData.InitiatorInfoFromDhcp == TRUE ||\r
+       AttemptTmp->SessionConfigData.TargetInfoFromDhcp == TRUE) { \r
+      FreePool (AttemptTmp);\r
+      FreePool (AttemptConfigOrder);\r
+      return TRUE;\r
+    }\r
+\r
+    FreePool (AttemptTmp);\r
+  }\r
+  \r
+  FreePool (AttemptConfigOrder);\r
+  return FALSE;\r
+}\r
 \r
 /**\r
   Get the various configuration data.\r
 \r
 /**\r
   Get the various configuration data.\r
index c9ff96da6cc37991198bab49f1752817a6a9ad4f..e2a27806ac8eccefcd362a696a98ba2d53f5c28f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Miscellaneous definitions for iSCSI driver.\r
 \r
 /** @file\r
   Miscellaneous definitions for iSCSI driver.\r
 \r
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2013, 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
 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
@@ -298,6 +298,22 @@ IScsiCleanDriverData (
   IN ISCSI_DRIVER_DATA  *Private\r
   );\r
 \r
   IN ISCSI_DRIVER_DATA  *Private\r
   );\r
 \r
+/**\r
+  Check wheather the Controller handle is configured to use DHCP protocol.\r
+\r
+  @param[in]  Controller           The handle of the controller.\r
+  @param[in]  IpVersion            IP_VERSION_4 or IP_VERSION_6.\r
+  \r
+  @retval TRUE                     The handle of the controller need the Dhcp protocol.\r
+  @retval FALSE                    The handle of the controller does not need the Dhcp protocol.\r
+  \r
+**/\r
+BOOLEAN\r
+IScsiDhcpIsConfigured (\r
+  IN EFI_HANDLE  Controller,\r
+  IN UINT8       IpVersion\r
+  );\r
+\r
 /**\r
   Get the various configuration data of this iSCSI instance.\r
 \r
 /**\r
   Get the various configuration data of this iSCSI instance.\r
 \r