/** @file\r
Miscellaneous routines for iSCSI driver.\r
\r
-Copyright (c) 2004 - 2015, 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
/**\r
Clean the iSCSI driver data.\r
\r
- @param[in] Private The iSCSI driver data.\r
+ @param[in] Private The iSCSI driver data.\r
+\r
+ @retval EFI_SUCCESS The clean operation is successful.\r
+ @retval Others Other errors as indicated.\r
\r
**/\r
-VOID\r
+EFI_STATUS\r
IScsiCleanDriverData (\r
IN ISCSI_DRIVER_DATA *Private\r
)\r
{\r
EFI_STATUS Status;\r
\r
+ Status = EFI_SUCCESS;\r
+\r
if (Private->DevicePath != NULL) {\r
- gBS->UninstallProtocolInterface (\r
- Private->ExtScsiPassThruHandle,\r
- &gEfiDevicePathProtocolGuid,\r
- Private->DevicePath\r
- );\r
+ Status = gBS->UninstallProtocolInterface (\r
+ Private->ExtScsiPassThruHandle,\r
+ &gEfiDevicePathProtocolGuid,\r
+ Private->DevicePath\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ goto EXIT;\r
+ }\r
\r
FreePool (Private->DevicePath);\r
}\r
}\r
}\r
\r
+EXIT:\r
+\r
gBS->CloseEvent (Private->ExitBootServiceEvent);\r
\r
+ mCallbackInfo->Current = NULL;\r
+\r
FreePool (Private);\r
+ return Status;\r
}\r
\r
/**\r
return FALSE;\r
}\r
\r
+/**\r
+ Check wheather the Controller handle is configured to use DNS protocol.\r
+\r
+ @param[in] Controller The handle of the controller.\r
+ \r
+ @retval TRUE The handle of the controller need the Dns protocol.\r
+ @retval FALSE The handle of the controller does not need the Dns protocol.\r
+ \r
+**/\r
+BOOLEAN\r
+IScsiDnsIsConfigured (\r
+ IN EFI_HANDLE Controller\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(AttemptTmp == NULL || EFI_ERROR (Status)) {\r
+ continue;\r
+ }\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.DnsMode) {\r
+ FreePool (AttemptTmp);\r
+ FreePool (AttemptConfigOrder);\r
+ return TRUE;\r
+ } else {\r
+ FreePool (AttemptTmp);\r
+ continue;\r
+ }\r
+\r
+ }\r
+\r
+ FreePool (AttemptConfigOrder);\r
+ return FALSE;\r
+\r
+}\r
+\r
/**\r
Get the various configuration data.\r
\r
\r
@retval EFI_SUCCESS The configuration data is retrieved.\r
@retval EFI_NOT_FOUND This iSCSI driver is not configured yet.\r
+ @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
\r
**/\r
EFI_STATUS\r
//\r
// Refresh the state of this attempt to NVR.\r
//\r
- AsciiStrToUnicodeStr (AttemptTmp->MacString, MacString);\r
+ AsciiStrToUnicodeStrS (AttemptTmp->MacString, MacString, ARRAY_SIZE (MacString));\r
UnicodeSPrint (\r
mPrivate->PortString,\r
(UINTN) ISCSI_NAME_IFR_MAX_SIZE,\r
//\r
// Refresh the state of this attempt to NVR.\r
//\r
- AsciiStrToUnicodeStr (AttemptTmp->MacString, MacString);\r
+ AsciiStrToUnicodeStrS (AttemptTmp->MacString, MacString, ARRAY_SIZE (MacString));\r
UnicodeSPrint (\r
mPrivate->PortString,\r
(UINTN) ISCSI_NAME_IFR_MAX_SIZE,\r
);\r
\r
GetVariable2 (\r
- mPrivate->PortString,\r
- &gEfiIScsiInitiatorNameProtocolGuid,\r
- (VOID**)&AttemptConfigData,\r
- NULL\r
- );\r
+ mPrivate->PortString,\r
+ &gEfiIScsiInitiatorNameProtocolGuid,\r
+ (VOID**)&AttemptConfigData,\r
+ NULL\r
+ );\r
\r
if (AttemptConfigData == NULL) {\r
continue;\r
//\r
// Refresh the state of this attempt to NVR.\r
//\r
- AsciiStrToUnicodeStr (AttemptConfigData->MacString, MacString);\r
+ AsciiStrToUnicodeStrS (AttemptConfigData->MacString, MacString, ARRAY_SIZE (MacString));\r
UnicodeSPrint (\r
mPrivate->PortString,\r
(UINTN) ISCSI_NAME_IFR_MAX_SIZE,\r
mPrivate->PortString,\r
NULL\r
);\r
- ASSERT (AttemptConfigData->AttemptTitleHelpToken != 0);\r
+ if (AttemptConfigData->AttemptTitleHelpToken == 0) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
\r
//\r
// Record the attempt in global link list.\r