]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/IScsiDxe/IScsiMisc.c
NetworkPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / NetworkPkg / IScsiDxe / IScsiMisc.c
index 6ed4974545fba7b35dfa17fab3ba4b5eef74c355..38ad67917c300d0369c4df0466b421210a07917c 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   Miscellaneous routines for iSCSI driver.\r
 \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
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -20,7 +14,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8  IScsiHexString[] = "0123456789ABCDEFa
   Removes (trims) specified leading and trailing characters from a string.\r
 \r
   @param[in, out] Str   Pointer to the null-terminated string to be trimmed.\r
-                        On return, Str will hold the trimmed string. \r
+                        On return, Str will hold the trimmed string.\r
 \r
   @param[in]      CharC Character will be trimmed from str.\r
 \r
@@ -33,18 +27,18 @@ IScsiStrTrim (
 {\r
   CHAR16  *Pointer1;\r
   CHAR16  *Pointer2;\r
-  \r
+\r
   if (*Str == 0) {\r
     return ;\r
   }\r
-  \r
+\r
   //\r
   // Trim off the leading and trailing characters c\r
   //\r
   for (Pointer1 = Str; (*Pointer1 != 0) && (*Pointer1 == CharC); Pointer1++) {\r
     ;\r
   }\r
-  \r
+\r
   Pointer2 = Str;\r
   if (Pointer2 == Pointer1) {\r
     while (*Pointer1 != 0) {\r
@@ -52,19 +46,19 @@ IScsiStrTrim (
       Pointer1++;\r
     }\r
   } else {\r
-    while (*Pointer1 != 0) {    \r
-    *Pointer2 = *Pointer1;    \r
+    while (*Pointer1 != 0) {\r
+    *Pointer2 = *Pointer1;\r
     Pointer1++;\r
     Pointer2++;\r
     }\r
     *Pointer2 = 0;\r
   }\r
-  \r
-  \r
+\r
+\r
   for (Pointer1 = Str + StrLen(Str) - 1; Pointer1 >= Str && *Pointer1 == CharC; Pointer1--) {\r
     ;\r
   }\r
-  if  (Pointer1 !=  Str + StrLen(Str) - 1) { \r
+  if  (Pointer1 !=  Str + StrLen(Str) - 1) {\r
     *(Pointer1 + 1) = 0;\r
   }\r
 }\r
@@ -131,11 +125,11 @@ IScsiAsciiStrToLun (
   CHAR8   TemStr[2];\r
   UINT8   TemValue;\r
   UINT16  Value[4];\r
-  \r
+\r
   ZeroMem (Lun, 8);\r
   ZeroMem (TemStr, 2);\r
   ZeroMem ((UINT8 *) Value, sizeof (Value));\r
-  SizeStr    = AsciiStrLen (Str);  \r
+  SizeStr    = AsciiStrLen (Str);\r
   IndexValue = 0;\r
   IndexNum   = 0;\r
 \r
@@ -150,7 +144,7 @@ IScsiAsciiStrToLun (
         return EFI_INVALID_PARAMETER;\r
       }\r
     }\r
-    \r
+\r
     if ((TemValue == 0) && (TemStr[0] == '-')) {\r
       //\r
       // Next Lun value.\r
@@ -167,24 +161,24 @@ IScsiAsciiStrToLun (
       IndexNum = 0;\r
       continue;\r
     }\r
-    \r
+\r
     if (++IndexNum > 4) {\r
-      //     \r
+      //\r
       // Each Lun Str can't exceed size 4, because it will be as UINT16 value.\r
       //\r
       return EFI_INVALID_PARAMETER;\r
     }\r
-    \r
+\r
     //\r
     // Combine UINT16 value.\r
     //\r
     Value[IndexValue] = (UINT16) ((Value[IndexValue] << 4) + TemValue);\r
   }\r
\r
+\r
   for (Index = 0; Index <= IndexValue; Index ++) {\r
     *((UINT16 *) &Lun[Index * 2]) =  HTONS (Value[Index]);\r
   }\r
-  \r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -209,7 +203,7 @@ IScsiLunToUnicodeStr (
   for (Index = 0; Index < 4; Index++) {\r
 \r
     if ((Lun[2 * Index] | Lun[2 * Index + 1]) == 0) {\r
-      StrCpy (TempStr, L"0-");\r
+      CopyMem (TempStr, L"0-", sizeof (L"0-"));\r
     } else {\r
       TempStr[0]  = (CHAR16) IScsiHexString[Lun[2 * Index] >> 4];\r
       TempStr[1]  = (CHAR16) IScsiHexString[Lun[2 * Index] & 0x0F];\r
@@ -223,7 +217,10 @@ IScsiLunToUnicodeStr (
 \r
     TempStr += StrLen (TempStr);\r
   }\r
-\r
+  //\r
+  // Remove the last '-'\r
+  //\r
+  ASSERT (StrLen(Str) >= 1);\r
   Str[StrLen (Str) - 1] = 0;\r
 \r
   for (Index = StrLen (Str) - 1; Index > 1; Index = Index - 2) {\r
@@ -316,7 +313,7 @@ IScsiMacAddrToStr (
   @param[in, out]  HexStr      Pointer to the string.\r
   @param[in, out]  HexLength   The length of the string.\r
 \r
-  @retval EFI_SUCCESS          The binary data is converted to the hexadecimal string \r
+  @retval EFI_SUCCESS          The binary data is converted to the hexadecimal string\r
                                and the length of the string is updated.\r
   @retval EFI_BUFFER_TOO_SMALL The string is too small.\r
   @retval EFI_INVALID_PARAMETER The IP string is malformatted.\r
@@ -382,7 +379,7 @@ IScsiHexToBin (
   UINTN   Length;\r
   UINT8   Digit;\r
   CHAR8   TemStr[2];\r
-  \r
+\r
   ZeroMem (TemStr, sizeof (TemStr));\r
 \r
   //\r
@@ -391,7 +388,7 @@ IScsiHexToBin (
   if ((HexStr[0] == '0') && ((HexStr[1] == 'x') || (HexStr[1] == 'X'))) {\r
     HexStr += 2;\r
   }\r
-  \r
+\r
   Length = AsciiStrLen (HexStr);\r
 \r
   for (Index = 0; Index < Length; Index ++) {\r
@@ -409,7 +406,7 @@ IScsiHexToBin (
       BinBuffer [Index/2] = (UINT8) ((BinBuffer [Index/2] << 4) + Digit);\r
     }\r
   }\r
-  \r
+\r
   *BinLength = (UINT32) ((Index + 1)/2);\r
 \r
   return EFI_SUCCESS;\r
@@ -462,10 +459,115 @@ IScsiGenRandom (
 }\r
 \r
 \r
+/**\r
+  Check whether UNDI protocol supports IPv6.\r
+\r
+  @param[in]   ControllerHandle    Controller handle.\r
+  @param[in]   Image               Handle of the image.\r
+  @param[out]  Ipv6Support         TRUE if UNDI supports IPv6.\r
+\r
+  @retval EFI_SUCCESS            Get the result whether UNDI supports IPv6 by NII or AIP protocol successfully.\r
+  @retval EFI_NOT_FOUND          Don't know whether UNDI supports IPv6 since NII or AIP is not available.\r
+\r
+**/\r
+EFI_STATUS\r
+IScsiCheckIpv6Support (\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  EFI_HANDLE                   Image,\r
+  OUT BOOLEAN                      *Ipv6Support\r
+  )\r
+{\r
+  EFI_HANDLE                       Handle;\r
+  EFI_ADAPTER_INFORMATION_PROTOCOL *Aip;\r
+  EFI_STATUS                       Status;\r
+  EFI_GUID                         *InfoTypesBuffer;\r
+  UINTN                            InfoTypeBufferCount;\r
+  UINTN                            TypeIndex;\r
+  BOOLEAN                          Supported;\r
+  VOID                             *InfoBlock;\r
+  UINTN                            InfoBlockSize;\r
+\r
+  EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *Nii;\r
+\r
+  ASSERT (Ipv6Support != NULL);\r
+\r
+  //\r
+  // Check whether the UNDI supports IPv6 by NII protocol.\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiNetworkInterfaceIdentifierProtocolGuid_31,\r
+                  (VOID **) &Nii,\r
+                  Image,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (Status == EFI_SUCCESS) {\r
+    *Ipv6Support = Nii->Ipv6Supported;\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // Get the NIC handle by SNP protocol.\r
+  //\r
+  Handle = NetLibGetSnpHandle (ControllerHandle, NULL);\r
+  if (Handle == NULL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  Aip    = NULL;\r
+  Status = gBS->HandleProtocol (\r
+                  Handle,\r
+                  &gEfiAdapterInformationProtocolGuid,\r
+                  (VOID *) &Aip\r
+                  );\r
+  if (EFI_ERROR (Status) || Aip == NULL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  InfoTypesBuffer     = NULL;\r
+  InfoTypeBufferCount = 0;\r
+  Status = Aip->GetSupportedTypes (Aip, &InfoTypesBuffer, &InfoTypeBufferCount);\r
+  if (EFI_ERROR (Status) || InfoTypesBuffer == NULL) {\r
+    FreePool (InfoTypesBuffer);\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  Supported = FALSE;\r
+  for (TypeIndex = 0; TypeIndex < InfoTypeBufferCount; TypeIndex++) {\r
+    if (CompareGuid (&InfoTypesBuffer[TypeIndex], &gEfiAdapterInfoUndiIpv6SupportGuid)) {\r
+      Supported = TRUE;\r
+      break;\r
+    }\r
+  }\r
+\r
+  FreePool (InfoTypesBuffer);\r
+  if (!Supported) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  //\r
+  // We now have adapter information block.\r
+  //\r
+  InfoBlock     = NULL;\r
+  InfoBlockSize = 0;\r
+  Status = Aip->GetInformation (Aip, &gEfiAdapterInfoUndiIpv6SupportGuid, &InfoBlock, &InfoBlockSize);\r
+  if (EFI_ERROR (Status) || InfoBlock == NULL) {\r
+    FreePool (InfoBlock);\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  *Ipv6Support = ((EFI_ADAPTER_INFO_UNDI_IPV6_SUPPORT *) InfoBlock)->Ipv6Support;\r
+  FreePool (InfoBlock);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
 /**\r
   Record the NIC info in global structure.\r
 \r
   @param[in]  Controller         The handle of the controller.\r
+  @param[in]  Image              Handle of the image.\r
 \r
   @retval EFI_SUCCESS            The operation is completed.\r
   @retval EFI_OUT_OF_RESOURCES   Do not have sufficient resources to finish this\r
@@ -474,7 +576,8 @@ IScsiGenRandom (
 **/\r
 EFI_STATUS\r
 IScsiAddNic (\r
-  IN EFI_HANDLE  Controller\r
+  IN EFI_HANDLE  Controller,\r
+  IN EFI_HANDLE  Image\r
   )\r
 {\r
   EFI_STATUS                  Status;\r
@@ -506,6 +609,19 @@ IScsiAddNic (
         CompareMem (&NicInfo->PermanentAddress, MacAddr.Addr, HwAddressSize) == 0 &&\r
         NicInfo->VlanId == VlanId) {\r
       mPrivate->CurrentNic = NicInfo->NicIndex;\r
+\r
+      //\r
+      // Set IPv6 available flag.\r
+      //\r
+      Status = IScsiCheckIpv6Support (Controller, Image, &NicInfo->Ipv6Available);\r
+      if (EFI_ERROR (Status)) {\r
+        //\r
+        // Fail to get the data whether UNDI supports IPv6.\r
+        // Set default value to TRUE.\r
+        //\r
+        NicInfo->Ipv6Available = TRUE;\r
+      }\r
+\r
       return EFI_SUCCESS;\r
     }\r
 \r
@@ -528,6 +644,18 @@ IScsiAddNic (
   NicInfo->NicIndex       = (UINT8) (mPrivate->MaxNic + 1);\r
   mPrivate->MaxNic        = NicInfo->NicIndex;\r
 \r
+  //\r
+  // Set IPv6 available flag.\r
+  //\r
+  Status = IScsiCheckIpv6Support (Controller, Image, &NicInfo->Ipv6Available);\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Fail to get the data whether UNDI supports IPv6.\r
+    // Set default value to TRUE.\r
+    //\r
+    NicInfo->Ipv6Available = TRUE;\r
+  }\r
+\r
   //\r
   // Get the PCI location.\r
   //\r
@@ -640,17 +768,795 @@ IScsiRemoveNic (
     }\r
   }\r
 \r
-  //\r
-  // Free attempt is created but not saved to system.\r
-  //\r
-  if (mPrivate->NewAttempt != NULL) {\r
-    FreePool (mPrivate->NewAttempt);\r
-    mPrivate->NewAttempt = NULL;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Create and initialize the Attempts.\r
+\r
+  @param[in]  AttemptNum          The number of Attempts will be created.\r
+\r
+  @retval EFI_SUCCESS             The Attempts have been created successfully.\r
+  @retval Others                  Failed to create the Attempt.\r
+\r
+**/\r
+EFI_STATUS\r
+IScsiCreateAttempts (\r
+  IN UINTN            AttemptNum\r
+)\r
+{\r
+  ISCSI_ATTEMPT_CONFIG_NVDATA   *AttemptConfigData;\r
+  ISCSI_SESSION_CONFIG_NVDATA   *ConfigData;\r
+  UINT8                         *AttemptConfigOrder;\r
+  UINTN                         AttemptConfigOrderSize;\r
+  UINT8                         *AttemptOrderTmp;\r
+  UINTN                         TotalNumber;\r
+  UINT8                         Index;\r
+  EFI_STATUS                    Status;\r
+\r
+  for (Index = 1; Index <= AttemptNum; Index ++) {\r
+    //\r
+    // Get the initialized attempt order. This is used to essure creating attempts by order.\r
+    //\r
+    AttemptConfigOrder = IScsiGetVariableAndSize (\r
+                           L"InitialAttemptOrder",\r
+                           &gIScsiConfigGuid,\r
+                           &AttemptConfigOrderSize\r
+                           );\r
+    TotalNumber = AttemptConfigOrderSize / sizeof (UINT8);\r
+    if (TotalNumber == AttemptNum) {\r
+      Status = EFI_SUCCESS;\r
+      break;\r
+    }\r
+    TotalNumber++;\r
+\r
+    //\r
+    // Append the new created attempt to the end.\r
+    //\r
+    AttemptOrderTmp = AllocateZeroPool (TotalNumber * sizeof (UINT8));\r
+    if (AttemptOrderTmp == NULL) {\r
+      if (AttemptConfigOrder != NULL) {\r
+        FreePool (AttemptConfigOrder);\r
+      }\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+\r
+    if (AttemptConfigOrder != NULL) {\r
+      CopyMem (AttemptOrderTmp, AttemptConfigOrder, AttemptConfigOrderSize);\r
+      FreePool (AttemptConfigOrder);\r
+    }\r
+\r
+    AttemptOrderTmp[TotalNumber - 1] = Index;\r
+    AttemptConfigOrder               = AttemptOrderTmp;\r
+    AttemptConfigOrderSize           = TotalNumber * sizeof (UINT8);\r
+\r
+    Status = gRT->SetVariable (\r
+                    L"InitialAttemptOrder",\r
+                    &gIScsiConfigGuid,\r
+                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
+                    AttemptConfigOrderSize,\r
+                    AttemptConfigOrder\r
+                    );\r
+    FreePool (AttemptConfigOrder);\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((DEBUG_ERROR,\r
+        "%a: Failed to set 'InitialAttemptOrder' with Guid (%g): "\r
+        "%r\n",\r
+        __FUNCTION__, &gIScsiConfigGuid, Status));\r
+      return Status;\r
+    }\r
+\r
+    //\r
+    // Create new Attempt\r
+    //\r
+    AttemptConfigData = AllocateZeroPool (sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA));\r
+    if (AttemptConfigData == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    ConfigData                    = &AttemptConfigData->SessionConfigData;\r
+    ConfigData->TargetPort        = ISCSI_WELL_KNOWN_PORT;\r
+    ConfigData->ConnectTimeout    = CONNECT_DEFAULT_TIMEOUT;\r
+    ConfigData->ConnectRetryCount = CONNECT_MIN_RETRY;\r
+\r
+    AttemptConfigData->AuthenticationType           = ISCSI_AUTH_TYPE_CHAP;\r
+    AttemptConfigData->AuthConfigData.CHAP.CHAPType = ISCSI_CHAP_UNI;\r
+    //\r
+    // Configure the Attempt index and set variable.\r
+    //\r
+    AttemptConfigData->AttemptConfigIndex = Index;\r
+\r
+    //\r
+    // Set the attempt name according to the order.\r
+    //\r
+    UnicodeSPrint (\r
+      mPrivate->PortString,\r
+      (UINTN) ISCSI_NAME_IFR_MAX_SIZE,\r
+      L"Attempt %d",\r
+      (UINTN) AttemptConfigData->AttemptConfigIndex\r
+      );\r
+    UnicodeStrToAsciiStrS (mPrivate->PortString, AttemptConfigData->AttemptName, ATTEMPT_NAME_SIZE);\r
+\r
+    Status = gRT->SetVariable (\r
+                    mPrivate->PortString,\r
+                    &gEfiIScsiInitiatorNameProtocolGuid,\r
+                    ISCSI_CONFIG_VAR_ATTR,\r
+                    sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA),\r
+                    AttemptConfigData\r
+                    );\r
+    FreePool (AttemptConfigData);\r
+    if (EFI_ERROR (Status)) {\r
+        DEBUG ((DEBUG_ERROR,\r
+          "%a: Failed to set variable (mPrivate->PortString) with Guid (%g): "\r
+          "%r\n",\r
+          __FUNCTION__, &gEfiIScsiInitiatorNameProtocolGuid, Status));\r
+      return Status;\r
+    }\r
   }\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Create the iSCSI configuration Keywords for each attempt. You can find the keywords\r
+  defined in the "x-UEFI-ns" namespace (http://www.uefi.org/confignamespace).\r
+\r
+  @param[in]  KeywordNum          The number Sets of Keywords will be created.\r
+\r
+  @retval EFI_SUCCESS             The operation is completed.\r
+  @retval Others                  Failed to create the Keywords.\r
+\r
+**/\r
+EFI_STATUS\r
+IScsiCreateKeywords (\r
+  IN UINTN            KeywordNum\r
+)\r
+{\r
+  VOID                          *StartOpCodeHandle;\r
+  EFI_IFR_GUID_LABEL            *StartLabel;\r
+  VOID                          *EndOpCodeHandle;\r
+  EFI_IFR_GUID_LABEL            *EndLabel;\r
+  UINTN                         Index;\r
+  EFI_STRING_ID                 StringToken;\r
+  CHAR16                        StringId[64];\r
+  CHAR16                        KeywordId[32];\r
+  EFI_STATUS                    Status;\r
+\r
+  Status = IScsiCreateOpCode (\r
+             KEYWORD_ENTRY_LABEL,\r
+             &StartOpCodeHandle,\r
+             &StartLabel,\r
+             &EndOpCodeHandle,\r
+             &EndLabel\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  for (Index = 1; Index <= KeywordNum; Index ++) {\r
+    //\r
+    // Create iSCSIAttemptName Keyword.\r
+    //\r
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_ATTEMPTT_NAME_PROMPT%d", Index);\r
+    StringToken =  HiiSetString (\r
+                     mCallbackInfo->RegisteredHandle,\r
+                     0,\r
+                     StringId,\r
+                     NULL\r
+                     );\r
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIAttemptName:%d", Index);\r
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");\r
+    HiiCreateStringOpCode (\r
+      StartOpCodeHandle,\r
+      (EFI_QUESTION_ID) (ATTEMPT_ATTEMPT_NAME_QUESTION_ID + (Index - 1)),\r
+      CONFIGURATION_VARSTORE_ID,\r
+      (UINT16) (ATTEMPT_ATTEMPT_NAME_VAR_OFFSET + ATTEMPT_NAME_SIZE * (Index - 1) * sizeof (CHAR16)),\r
+      StringToken,\r
+      StringToken,\r
+      EFI_IFR_FLAG_READ_ONLY,\r
+      0,\r
+      0,\r
+      ATTEMPT_NAME_SIZE,\r
+      NULL\r
+      );\r
+\r
+    //\r
+    // Create iSCSIBootEnable Keyword.\r
+    //\r
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_MODE_PROMPT%d", Index);\r
+    StringToken =  HiiSetString (\r
+                     mCallbackInfo->RegisteredHandle,\r
+                     0,\r
+                     StringId,\r
+                     NULL\r
+                     );\r
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIBootEnable:%d", Index);\r
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");\r
+    HiiCreateNumericOpCode (\r
+      StartOpCodeHandle,\r
+      (EFI_QUESTION_ID) (ATTEMPT_BOOTENABLE_QUESTION_ID + (Index - 1)),\r
+      CONFIGURATION_VARSTORE_ID,\r
+      (UINT16) (ATTEMPT_BOOTENABLE_VAR_OFFSET + (Index - 1)),\r
+      StringToken,\r
+      StringToken,\r
+      0,\r
+      EFI_IFR_NUMERIC_SIZE_1,\r
+      0,\r
+      2,\r
+      0,\r
+      NULL\r
+      );\r
+\r
+    //\r
+    // Create iSCSIIpAddressType Keyword.\r
+    //\r
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_IP_MODE_PROMPT%d", Index);\r
+    StringToken =  HiiSetString (\r
+                     mCallbackInfo->RegisteredHandle,\r
+                     0,\r
+                     StringId,\r
+                     NULL\r
+                     );\r
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIIpAddressType:%d", Index);\r
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");\r
+    HiiCreateNumericOpCode (\r
+      StartOpCodeHandle,\r
+      (EFI_QUESTION_ID) (ATTEMPT_ADDRESS_TYPE_QUESTION_ID + (Index - 1)),\r
+      CONFIGURATION_VARSTORE_ID,\r
+      (UINT16) (ATTEMPT_ADDRESS_TYPE_VAR_OFFSET + (Index - 1)),\r
+      StringToken,\r
+      StringToken,\r
+      0,\r
+      EFI_IFR_NUMERIC_SIZE_1,\r
+      0,\r
+      2,\r
+      0,\r
+      NULL\r
+      );\r
+\r
+    //\r
+    // Create iSCSIConnectRetry Keyword.\r
+    //\r
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_CONNECT_RETRY_PROMPT%d", Index);\r
+    StringToken =  HiiSetString (\r
+                     mCallbackInfo->RegisteredHandle,\r
+                     0,\r
+                     StringId,\r
+                     NULL\r
+                     );\r
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIConnectRetry:%d", Index);\r
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");\r
+    HiiCreateNumericOpCode (\r
+      StartOpCodeHandle,\r
+      (EFI_QUESTION_ID) (ATTEMPT_CONNECT_RETRY_QUESTION_ID + (Index - 1)),\r
+      CONFIGURATION_VARSTORE_ID,\r
+      (UINT16) (ATTEMPT_CONNECT_RETRY_VAR_OFFSET + (Index - 1)),\r
+      StringToken,\r
+      StringToken,\r
+      0,\r
+      EFI_IFR_NUMERIC_SIZE_1,\r
+      0,\r
+      16,\r
+      0,\r
+      NULL\r
+      );\r
+\r
+    //\r
+    // Create iSCSIConnectTimeout Keyword.\r
+    //\r
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_CONNECT_TIMEOUT_PROMPT%d", Index);\r
+    StringToken =  HiiSetString (\r
+                     mCallbackInfo->RegisteredHandle,\r
+                     0,\r
+                     StringId,\r
+                     NULL\r
+                     );\r
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIConnectTimeout:%d", Index);\r
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");\r
+    HiiCreateNumericOpCode (\r
+      StartOpCodeHandle,\r
+      (EFI_QUESTION_ID) (ATTEMPT_CONNECT_TIMEOUT_QUESTION_ID + (Index - 1)),\r
+      CONFIGURATION_VARSTORE_ID,\r
+      (UINT16) (ATTEMPT_CONNECT_TIMEOUT_VAR_OFFSET + 2 * (Index - 1)),\r
+      StringToken,\r
+      StringToken,\r
+      0,\r
+      EFI_IFR_NUMERIC_SIZE_2,\r
+      CONNECT_MIN_TIMEOUT,\r
+      CONNECT_MAX_TIMEOUT,\r
+      0,\r
+      NULL\r
+      );\r
+\r
+    //\r
+    // Create ISID Keyword.\r
+    //\r
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_ISID_PROMPT%d", Index);\r
+    StringToken =  HiiSetString (\r
+                     mCallbackInfo->RegisteredHandle,\r
+                     0,\r
+                     StringId,\r
+                     NULL\r
+                     );\r
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIISID:%d", Index);\r
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");\r
+    HiiCreateStringOpCode (\r
+      StartOpCodeHandle,\r
+      (EFI_QUESTION_ID) (ATTEMPT_ISID_QUESTION_ID + (Index - 1)),\r
+      CONFIGURATION_VARSTORE_ID,\r
+      (UINT16) (ATTEMPT_ISID_VAR_OFFSET + sizeof (KEYWORD_STR) * (Index - 1)),\r
+      StringToken,\r
+      STRING_TOKEN (STR_ISCSI_ISID_HELP),\r
+      0,\r
+      0,\r
+      ISID_CONFIGURABLE_MIN_LEN,\r
+      ISID_CONFIGURABLE_STORAGE,\r
+      NULL\r
+      );\r
+\r
+    //\r
+    // Create iSCSIInitiatorInfoViaDHCP Keyword.\r
+    //\r
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_INITIATOR_VIA_DHCP_PROMPT%d", Index);\r
+    StringToken =  HiiSetString (\r
+                     mCallbackInfo->RegisteredHandle,\r
+                     0,\r
+                     StringId,\r
+                     NULL\r
+                     );\r
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIInitiatorInfoViaDHCP:%d", Index);\r
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");\r
+    HiiCreateNumericOpCode (\r
+    StartOpCodeHandle,\r
+    (EFI_QUESTION_ID) (ATTEMPT_INITIATOR_VIA_DHCP_QUESTION_ID + (Index - 1)),\r
+    CONFIGURATION_VARSTORE_ID,\r
+    (UINT16) (ATTEMPT_INITIATOR_VIA_DHCP_VAR_OFFSET + (Index - 1)),\r
+    StringToken,\r
+    StringToken,\r
+    0,\r
+    0,\r
+    0,\r
+    1,\r
+    0,\r
+    NULL\r
+    );\r
+\r
+    //\r
+    // Create iSCSIInitiatorIpAddress Keyword.\r
+    //\r
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_INITIATOR_IP_ADDRESS_PROMPT%d", Index);\r
+    StringToken =  HiiSetString (\r
+                     mCallbackInfo->RegisteredHandle,\r
+                     0,\r
+                     StringId,\r
+                     NULL\r
+                     );\r
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIInitiatorIpAddress:%d", Index);\r
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");\r
+    HiiCreateStringOpCode (\r
+      StartOpCodeHandle,\r
+      (EFI_QUESTION_ID) (ATTEMPT_INITIATOR_IP_ADDRESS_QUESTION_ID + (Index - 1)),\r
+      CONFIGURATION_VARSTORE_ID,\r
+      (UINT16) (ATTEMPT_INITIATOR_IP_ADDRESS_VAR_OFFSET + sizeof (KEYWORD_STR) * (Index - 1)),\r
+      StringToken,\r
+      StringToken,\r
+      0,\r
+      0,\r
+      IP4_MIN_SIZE,\r
+      IP4_STR_MAX_SIZE,\r
+      NULL\r
+      );\r
+\r
+    //\r
+    // Create iSCSIInitiatorNetmask Keyword.\r
+    //\r
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_INITIATOR_NET_MASK_PROMPT%d", Index);\r
+    StringToken =  HiiSetString (\r
+                     mCallbackInfo->RegisteredHandle,\r
+                     0,\r
+                     StringId,\r
+                     NULL\r
+                     );\r
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIInitiatorNetmask:%d", Index);\r
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");\r
+    HiiCreateStringOpCode (\r
+      StartOpCodeHandle,\r
+      (EFI_QUESTION_ID) (ATTEMPT_INITIATOR_NET_MASK_QUESTION_ID + (Index - 1)),\r
+      CONFIGURATION_VARSTORE_ID,\r
+      (UINT16) (ATTEMPT_INITIATOR_NET_MASK_VAR_OFFSET + sizeof (KEYWORD_STR) * (Index - 1)),\r
+      StringToken,\r
+      StringToken,\r
+      0,\r
+      0,\r
+      IP4_MIN_SIZE,\r
+      IP4_STR_MAX_SIZE,\r
+      NULL\r
+      );\r
+\r
+    //\r
+    // Create iSCSIInitiatorGateway Keyword.\r
+    //\r
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_INITIATOR_GATE_PROMPT%d", Index);\r
+    StringToken =  HiiSetString (\r
+                     mCallbackInfo->RegisteredHandle,\r
+                     0,\r
+                     StringId,\r
+                     NULL\r
+                     );\r
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIInitiatorGateway:%d", Index);\r
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");\r
+    HiiCreateStringOpCode (\r
+      StartOpCodeHandle,\r
+      (EFI_QUESTION_ID) (ATTEMPT_INITIATOR_GATE_WAY_QUESTION_ID + (Index - 1)),\r
+      CONFIGURATION_VARSTORE_ID,\r
+      (UINT16) (ATTEMPT_INITIATOR_GATE_WAY_VAR_OFFSET + sizeof (KEYWORD_STR) * (Index - 1)),\r
+      StringToken,\r
+      StringToken,\r
+      0,\r
+      0,\r
+      IP4_MIN_SIZE,\r
+      IP4_STR_MAX_SIZE,\r
+      NULL\r
+      );\r
+\r
+    //\r
+    // Create iSCSITargetInfoViaDHCP Keyword.\r
+    //\r
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_TARGET_VIA_DHCP_PROMPT%d", Index);\r
+    StringToken =  HiiSetString (\r
+                     mCallbackInfo->RegisteredHandle,\r
+                     0,\r
+                     StringId,\r
+                     NULL\r
+                     );\r
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSITargetInfoViaDHCP:%d", Index);\r
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");\r
+    HiiCreateNumericOpCode (\r
+    StartOpCodeHandle,\r
+    (EFI_QUESTION_ID) (ATTEMPT_TARGET_VIA_DHCP_QUESTION_ID + (Index - 1)),\r
+    CONFIGURATION_VARSTORE_ID,\r
+    (UINT16) (ATTEMPT_TARGET_VIA_DHCP_VAR_OFFSET + (Index - 1)),\r
+    StringToken,\r
+    StringToken,\r
+    0,\r
+    0,\r
+    0,\r
+    1,\r
+    0,\r
+    NULL\r
+    );\r
+\r
+    //\r
+    // Create iSCSITargetTcpPort Keyword.\r
+    //\r
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_TARGET_TCP_PORT_PROMPT%d", Index);\r
+    StringToken =  HiiSetString (\r
+                     mCallbackInfo->RegisteredHandle,\r
+                     0,\r
+                     StringId,\r
+                     NULL\r
+                     );\r
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSITargetTcpPort:%d", Index);\r
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");\r
+    HiiCreateNumericOpCode (\r
+      StartOpCodeHandle,\r
+      (EFI_QUESTION_ID) (ATTEMPT_TARGET_TCP_PORT_QUESTION_ID + (Index - 1)),\r
+      CONFIGURATION_VARSTORE_ID,\r
+      (UINT16) (ATTEMPT_TARGET_TCP_PORT_VAR_OFFSET + 2 * (Index - 1)),\r
+      StringToken,\r
+      StringToken,\r
+      0,\r
+      EFI_IFR_NUMERIC_SIZE_2,\r
+      TARGET_PORT_MIN_NUM,\r
+      TARGET_PORT_MAX_NUM,\r
+      0,\r
+      NULL\r
+      );\r
+\r
+    //\r
+    // Create iSCSITargetName Keyword.\r
+    //\r
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_TARGET_NAME_PROMPT%d", Index);\r
+    StringToken =  HiiSetString (\r
+                     mCallbackInfo->RegisteredHandle,\r
+                     0,\r
+                     StringId,\r
+                     NULL\r
+                     );\r
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSITargetName:%d", Index);\r
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");\r
+    HiiCreateStringOpCode (\r
+      StartOpCodeHandle,\r
+      (EFI_QUESTION_ID) (ATTEMPT_TARGET_NAME_QUESTION_ID + (Index - 1)),\r
+      CONFIGURATION_VARSTORE_ID,\r
+      (UINT16) (ATTEMPT_TARGET_NAME_VAR_OFFSET + sizeof (KEYWORD_STR) * (Index - 1)),\r
+      StringToken,\r
+      StringToken,\r
+      0,\r
+      0,\r
+      ISCSI_NAME_IFR_MIN_SIZE,\r
+      ISCSI_NAME_IFR_MAX_SIZE,\r
+      NULL\r
+      );\r
+\r
+    //\r
+    // Create iSCSITargetIpAddress Keyword.\r
+    //\r
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_TARGET_IP_ADDRESS_PROMPT%d", Index);\r
+    StringToken =  HiiSetString (\r
+                     mCallbackInfo->RegisteredHandle,\r
+                     0,\r
+                     StringId,\r
+                     NULL\r
+                     );\r
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSITargetIpAddress:%d", Index);\r
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");\r
+    HiiCreateStringOpCode (\r
+      StartOpCodeHandle,\r
+      (EFI_QUESTION_ID) (ATTEMPT_TARGET_IP_ADDRESS_QUESTION_ID + (Index - 1)),\r
+      CONFIGURATION_VARSTORE_ID,\r
+      (UINT16) (ATTEMPT_TARGET_IP_ADDRESS_VAR_OFFSET + sizeof (KEYWORD_STR) * (Index - 1)),\r
+      StringToken,\r
+      StringToken,\r
+      0,\r
+      0,\r
+      IP_MIN_SIZE,\r
+      IP_STR_MAX_SIZE,\r
+      NULL\r
+      );\r
+\r
+    //\r
+    // Create iSCSILUN Keyword.\r
+    //\r
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_LUN_PROMPT%d", Index);\r
+    StringToken =  HiiSetString (\r
+                     mCallbackInfo->RegisteredHandle,\r
+                     0,\r
+                     StringId,\r
+                     NULL\r
+                     );\r
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSILUN:%d", Index);\r
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");\r
+    HiiCreateStringOpCode (\r
+      StartOpCodeHandle,\r
+      (EFI_QUESTION_ID) (ATTEMPT_LUN_QUESTION_ID + (Index - 1)),\r
+      CONFIGURATION_VARSTORE_ID,\r
+      (UINT16) (ATTEMPT_LUN_VAR_OFFSET + sizeof (KEYWORD_STR) * (Index - 1)),\r
+      StringToken,\r
+      StringToken,\r
+      0,\r
+      0,\r
+      LUN_MIN_SIZE,\r
+      LUN_MAX_SIZE,\r
+      NULL\r
+      );\r
+\r
+    //\r
+    // Create iSCSIAuthenticationMethod Keyword.\r
+    //\r
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_AUTHENTICATION_METHOD_PROMPT%d", Index);\r
+    StringToken =  HiiSetString (\r
+                     mCallbackInfo->RegisteredHandle,\r
+                     0,\r
+                     StringId,\r
+                     NULL\r
+                     );\r
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIAuthenticationMethod:%d", Index);\r
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");\r
+    HiiCreateNumericOpCode (\r
+    StartOpCodeHandle,\r
+    (EFI_QUESTION_ID) (ATTEMPT_AUTHENTICATION_METHOD_QUESTION_ID + (Index - 1)),\r
+    CONFIGURATION_VARSTORE_ID,\r
+    (UINT16) (ATTEMPT_AUTHENTICATION_METHOD_VAR_OFFSET + (Index - 1)),\r
+    StringToken,\r
+    StringToken,\r
+    0,\r
+    0,\r
+    0,\r
+    1,\r
+    0,\r
+    NULL\r
+    );\r
+\r
+    //\r
+    // Create iSCSIChapType Keyword.\r
+    //\r
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_CHARTYPE_PROMPT%d", Index);\r
+    StringToken =  HiiSetString (\r
+                     mCallbackInfo->RegisteredHandle,\r
+                     0,\r
+                     StringId,\r
+                     NULL\r
+                     );\r
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIChapType:%d", Index);\r
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");\r
+    HiiCreateNumericOpCode (\r
+    StartOpCodeHandle,\r
+    (EFI_QUESTION_ID) (ATTEMPT_CHARTYPE_QUESTION_ID + (Index - 1)),\r
+    CONFIGURATION_VARSTORE_ID,\r
+    (UINT16) (ATTEMPT_CHARTYPE_VAR_OFFSET + (Index - 1)),\r
+    StringToken,\r
+    StringToken,\r
+    0,\r
+    0,\r
+    0,\r
+    1,\r
+    0,\r
+    NULL\r
+    );\r
+\r
+    //\r
+    // Create iSCSIChapUsername Keyword.\r
+    //\r
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_CHAR_USER_NAME_PROMPT%d", Index);\r
+    StringToken =  HiiSetString (\r
+                     mCallbackInfo->RegisteredHandle,\r
+                     0,\r
+                     StringId,\r
+                     NULL\r
+                     );\r
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIChapUsername:%d", Index);\r
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");\r
+    HiiCreateStringOpCode (\r
+      StartOpCodeHandle,\r
+      (EFI_QUESTION_ID) (ATTEMPT_CHAR_USER_NAME_QUESTION_ID + (Index - 1)),\r
+      CONFIGURATION_VARSTORE_ID,\r
+      (UINT16) (ATTEMPT_CHAR_USER_NAME_VAR_OFFSET + sizeof (KEYWORD_STR) * (Index - 1)),\r
+      StringToken,\r
+      StringToken,\r
+      0,\r
+      0,\r
+      0,\r
+      ISCSI_CHAP_NAME_MAX_LEN,\r
+      NULL\r
+      );\r
+\r
+    //\r
+    // Create iSCSIChapSecret Keyword.\r
+    //\r
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_CHAR_SECRET_PROMPT%d", Index);\r
+    StringToken =  HiiSetString (\r
+                     mCallbackInfo->RegisteredHandle,\r
+                     0,\r
+                     StringId,\r
+                     NULL\r
+                     );\r
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIChapSecret:%d", Index);\r
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");\r
+    HiiCreateStringOpCode (\r
+      StartOpCodeHandle,\r
+      (EFI_QUESTION_ID) (ATTEMPT_CHAR_SECRET_QUESTION_ID + (Index - 1)),\r
+      CONFIGURATION_VARSTORE_ID,\r
+      (UINT16) (ATTEMPT_CHAR_SECRET_VAR_OFFSET + sizeof (KEYWORD_STR) * (Index - 1)),\r
+      StringToken,\r
+      StringToken,\r
+      0,\r
+      0,\r
+      ISCSI_CHAP_SECRET_MIN_LEN,\r
+      ISCSI_CHAP_SECRET_MAX_LEN,\r
+      NULL\r
+      );\r
+\r
+    //\r
+    // Create iSCSIReverseChapUsername Keyword.\r
+    //\r
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_CHAR_REVERSE_USER_NAME_PROMPT%d", Index);\r
+    StringToken =  HiiSetString (\r
+                     mCallbackInfo->RegisteredHandle,\r
+                     0,\r
+                     StringId,\r
+                     NULL\r
+                     );\r
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIReverseChapUsername:%d", Index);\r
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");\r
+    HiiCreateStringOpCode (\r
+      StartOpCodeHandle,\r
+      (EFI_QUESTION_ID) (ATTEMPT_CHAR_REVERSE_USER_NAME_QUESTION_ID + (Index - 1)),\r
+      CONFIGURATION_VARSTORE_ID,\r
+      (UINT16) (ATTEMPT_CHAR_REVERSE_USER_NAME_VAR_OFFSET + sizeof (KEYWORD_STR) * (Index - 1)),\r
+      StringToken,\r
+      StringToken,\r
+      0,\r
+      0,\r
+      0,\r
+      ISCSI_CHAP_NAME_MAX_LEN,\r
+      NULL\r
+      );\r
+\r
+    //\r
+    // Create iSCSIReverseChapSecret Keyword.\r
+    //\r
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_CHAR_REVERSE_SECRET_PROMPT%d", Index);\r
+    StringToken =  HiiSetString (\r
+                     mCallbackInfo->RegisteredHandle,\r
+                     0,\r
+                     StringId,\r
+                     NULL\r
+                     );\r
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIReverseChapSecret:%d", Index);\r
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");\r
+    HiiCreateStringOpCode (\r
+      StartOpCodeHandle,\r
+      (EFI_QUESTION_ID) (ATTEMPT_CHAR_REVERSE_SECRET_QUESTION_ID + (Index - 1)),\r
+      CONFIGURATION_VARSTORE_ID,\r
+      (UINT16) (ATTEMPT_CHAR_REVERSE_SECRET_VAR_OFFSET + sizeof (KEYWORD_STR) * (Index - 1)),\r
+      StringToken,\r
+      StringToken,\r
+      0,\r
+      0,\r
+      ISCSI_CHAP_SECRET_MIN_LEN,\r
+      ISCSI_CHAP_SECRET_MAX_LEN,\r
+      NULL\r
+      );\r
+  }\r
+\r
+  Status = HiiUpdateForm (\r
+             mCallbackInfo->RegisteredHandle, // HII handle\r
+             &gIScsiConfigGuid,               // Formset GUID\r
+             FORMID_ATTEMPT_FORM,             // Form ID\r
+             StartOpCodeHandle,               // Label for where to insert opcodes\r
+             EndOpCodeHandle                  // Replace data\r
+             );\r
+\r
+  HiiFreeOpCodeHandle (StartOpCodeHandle);\r
+  HiiFreeOpCodeHandle (EndOpCodeHandle);\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+\r
+  Free the attempt configure data variable.\r
+\r
+**/\r
+VOID\r
+IScsiCleanAttemptVariable (\r
+  IN   VOID\r
+)\r
+{\r
+  ISCSI_ATTEMPT_CONFIG_NVDATA   *AttemptConfigData;\r
+  UINT8                         *AttemptConfigOrder;\r
+  UINTN                         AttemptConfigOrderSize;\r
+  UINTN                         Index;\r
+\r
+  //\r
+  // Get the initialized attempt order.\r
+  //\r
+  AttemptConfigOrder = IScsiGetVariableAndSize (\r
+                         L"InitialAttemptOrder",\r
+                         &gIScsiConfigGuid,\r
+                         &AttemptConfigOrderSize\r
+                         );\r
+  if (AttemptConfigOrder == NULL || AttemptConfigOrderSize == 0) {\r
+    return;\r
+  }\r
+\r
+  for (Index = 1; Index < AttemptConfigOrderSize / sizeof (UINT8); Index++) {\r
+    UnicodeSPrint (\r
+      mPrivate->PortString,\r
+      (UINTN) ISCSI_NAME_IFR_MAX_SIZE,\r
+      L"Attempt %d",\r
+      Index\r
+      );\r
+\r
+    GetVariable2 (\r
+      mPrivate->PortString,\r
+      &gEfiIScsiInitiatorNameProtocolGuid,\r
+      (VOID**)&AttemptConfigData,\r
+      NULL\r
+      );\r
+\r
+    if (AttemptConfigData != NULL) {\r
+      gRT->SetVariable (\r
+             mPrivate->PortString,\r
+             &gEfiIScsiInitiatorNameProtocolGuid,\r
+             0,\r
+             0,\r
+             NULL\r
+             );\r
+    }\r
+  }\r
+  return;\r
+}\r
 \r
 /**\r
   Get the recorded NIC info from global structure by the Index.\r
@@ -680,7 +1586,7 @@ IScsiGetNicInfoByIndex (
 \r
 \r
 /**\r
-  Get the NIC's PCI location and return it accroding to the composited\r
+  Get the NIC's PCI location and return it according to the composited\r
   format defined in iSCSI Boot Firmware Table.\r
 \r
   @param[in]   Controller        The handle of the controller.\r
@@ -854,22 +1760,30 @@ IScsiCreateDriverData (
 /**\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
@@ -885,9 +1799,15 @@ IScsiCleanDriverData (
     }\r
   }\r
 \r
-  gBS->CloseEvent (Private->ExitBootServiceEvent);\r
+EXIT:\r
+  if (Private->ExitBootServiceEvent != NULL) {\r
+    gBS->CloseEvent (Private->ExitBootServiceEvent);\r
+  }\r
+\r
+  mCallbackInfo->Current = NULL;\r
 \r
   FreePool (Private);\r
+  return Status;\r
 }\r
 \r
 /**\r
@@ -895,10 +1815,10 @@ IScsiCleanDriverData (
 \r
   @param[in]  Controller           The handle of the controller.\r
   @param[in]  IpVersion            IP_VERSION_4 or IP_VERSION_6.\r
-  \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
 **/\r
 BOOLEAN\r
 IScsiDhcpIsConfigured (\r
@@ -915,8 +1835,9 @@ IScsiDhcpIsConfigured (
   UINTN                       HwAddressSize;\r
   UINT16                      VlanId;\r
   CHAR16                      MacString[ISCSI_MAX_MAC_STRING_LEN];\r
+  CHAR16                      AttemptMacString[ISCSI_MAX_MAC_STRING_LEN];\r
   CHAR16                      AttemptName[ISCSI_NAME_IFR_MAX_SIZE];\r
-  \r
+\r
   AttemptConfigOrder = IScsiGetVariableAndSize (\r
                          L"AttemptOrder",\r
                          &gIScsiConfigGuid,\r
@@ -925,7 +1846,7 @@ IScsiDhcpIsConfigured (
   if (AttemptConfigOrder == NULL || AttemptConfigOrderSize == 0) {\r
     return FALSE;\r
   }\r
-  \r
+\r
   //\r
   // Get MAC address of this network device.\r
   //\r
@@ -938,13 +1859,12 @@ IScsiDhcpIsConfigured (
   //\r
   VlanId = NetLibGetVlanId (Controller);\r
   IScsiMacAddrToStr (&MacAddr, (UINT32) HwAddressSize, VlanId, MacString);\r
-  \r
+\r
   for (Index = 0; Index < AttemptConfigOrderSize / sizeof (UINT8); Index++) {\r
     UnicodeSPrint (\r
       AttemptName,\r
       (UINTN) 128,\r
-      L"%s%d",\r
-      MacString,\r
+      L"Attempt %d",\r
       (UINTN) AttemptConfigOrder[Index]\r
       );\r
     Status = GetVariable2 (\r
@@ -956,7 +1876,7 @@ IScsiDhcpIsConfigured (
     if(AttemptTmp == NULL || EFI_ERROR (Status)) {\r
       continue;\r
     }\r
-    \r
+\r
     ASSERT (AttemptConfigOrder[Index] == AttemptTmp->AttemptConfigIndex);\r
 \r
     if (AttemptTmp->SessionConfigData.Enabled == ISCSI_DISABLED) {\r
@@ -964,15 +1884,21 @@ IScsiDhcpIsConfigured (
       continue;\r
     }\r
 \r
-    if (AttemptTmp->SessionConfigData.IpMode != IP_MODE_AUTOCONFIG && \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
+\r
+    AsciiStrToUnicodeStrS (AttemptTmp->MacString, AttemptMacString, sizeof (AttemptMacString) / sizeof (AttemptMacString[0]));\r
+\r
+    if (AttemptTmp->Actived == ISCSI_ACTIVE_DISABLED || StrCmp (MacString, AttemptMacString)) {\r
+      continue;\r
+    }\r
+\r
     if(AttemptTmp->SessionConfigData.IpMode == IP_MODE_AUTOCONFIG ||\r
        AttemptTmp->SessionConfigData.InitiatorInfoFromDhcp == TRUE ||\r
-       AttemptTmp->SessionConfigData.TargetInfoFromDhcp == TRUE) { \r
+       AttemptTmp->SessionConfigData.TargetInfoFromDhcp == TRUE) {\r
       FreePool (AttemptTmp);\r
       FreePool (AttemptConfigOrder);\r
       return TRUE;\r
@@ -980,9 +1906,100 @@ IScsiDhcpIsConfigured (
 \r
     FreePool (AttemptTmp);\r
   }\r
-  \r
+\r
+  FreePool (AttemptConfigOrder);\r
+  return FALSE;\r
+}\r
+\r
+/**\r
+  Check whether 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                      AttemptMacString[ISCSI_MAX_MAC_STRING_LEN];\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"Attempt %d",\r
+      (UINTN) AttemptConfigOrder[Index]\r
+      );\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
+    AsciiStrToUnicodeStrS (AttemptTmp->MacString, AttemptMacString, sizeof (AttemptMacString) / sizeof (AttemptMacString[0]));\r
+\r
+    if (AttemptTmp->SessionConfigData.Enabled == ISCSI_DISABLED || StrCmp (MacString, AttemptMacString)) {\r
+      FreePool (AttemptTmp);\r
+      continue;\r
+    }\r
+\r
+    if (AttemptTmp->SessionConfigData.DnsMode || AttemptTmp->SessionConfigData.TargetInfoFromDhcp) {\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
@@ -992,6 +2009,7 @@ IScsiDhcpIsConfigured (
 \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
@@ -1001,6 +2019,7 @@ IScsiGetConfigData (
 {\r
   EFI_STATUS                  Status;\r
   CHAR16                      MacString[ISCSI_MAX_MAC_STRING_LEN];\r
+  CHAR16                      AttemptMacString[ISCSI_MAX_MAC_STRING_LEN];\r
   UINTN                       Index;\r
   ISCSI_NIC_INFO              *NicInfo;\r
   ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;\r
@@ -1043,7 +2062,7 @@ IScsiGetConfigData (
     //\r
     // Check whether the attempt exists in AttemptConfig.\r
     //\r
-    AttemptTmp = IScsiConfigGetAttemptByConfigIndex (AttemptConfigOrder[Index]);    \r
+    AttemptTmp = IScsiConfigGetAttemptByConfigIndex (AttemptConfigOrder[Index]);\r
     if (AttemptTmp != NULL && AttemptTmp->SessionConfigData.Enabled == ISCSI_DISABLED) {\r
       continue;\r
     } else if (AttemptTmp != NULL && AttemptTmp->SessionConfigData.Enabled != ISCSI_DISABLED) {\r
@@ -1051,7 +2070,7 @@ IScsiGetConfigData (
       // Check the autoconfig path to see whether it should be retried.\r
       //\r
       if (AttemptTmp->SessionConfigData.IpMode == IP_MODE_AUTOCONFIG &&\r
-          AttemptTmp->AutoConfigureMode != IP_MODE_AUTOCONFIG_SUCCESS) {\r
+          !AttemptTmp->AutoConfigureSuccess) {\r
         if (mPrivate->Ipv6Flag &&\r
             AttemptTmp->AutoConfigureMode == IP_MODE_AUTOCONFIG_IP6) {\r
           //\r
@@ -1092,12 +2111,10 @@ IScsiGetConfigData (
           //\r
           // Refresh the state of this attempt to NVR.\r
           //\r
-          AsciiStrToUnicodeStr (AttemptTmp->MacString, MacString);\r
           UnicodeSPrint (\r
             mPrivate->PortString,\r
             (UINTN) ISCSI_NAME_IFR_MAX_SIZE,\r
-            L"%s%d",\r
-            MacString,\r
+            L"Attempt %d",\r
             (UINTN) AttemptTmp->AttemptConfigIndex\r
             );\r
 \r
@@ -1111,9 +2128,12 @@ IScsiGetConfigData (
 \r
           continue;\r
         }\r
-      } else if (AttemptTmp->SessionConfigData.InitiatorInfoFromDhcp && !AttemptTmp->ValidPath) {\r
+      } else if (AttemptTmp->SessionConfigData.InitiatorInfoFromDhcp &&\r
+                 !AttemptTmp->ValidPath &&\r
+                 AttemptTmp->NicIndex == mPrivate->CurrentNic) {\r
         //\r
-        // Get DHCP information for already added, but failed, attempt.\r
+        // If the attempt associates with the current NIC, we can\r
+        // get DHCP information for already added, but failed, attempt.\r
         //\r
         AttemptTmp->DhcpSuccess = FALSE;\r
         if (!mPrivate->Ipv6Flag && (AttemptTmp->SessionConfigData.IpMode == IP_MODE_IP4)) {\r
@@ -1131,12 +2151,10 @@ IScsiGetConfigData (
         //\r
         // Refresh the state of this attempt to NVR.\r
         //\r
-        AsciiStrToUnicodeStr (AttemptTmp->MacString, MacString);\r
         UnicodeSPrint (\r
           mPrivate->PortString,\r
           (UINTN) ISCSI_NAME_IFR_MAX_SIZE,\r
-          L"%s%d",\r
-          MacString,\r
+          L"Attempt %d",\r
           (UINTN) AttemptTmp->AttemptConfigIndex\r
           );\r
 \r
@@ -1164,20 +2182,21 @@ IScsiGetConfigData (
     IScsiMacAddrToStr (&NicInfo->PermanentAddress, NicInfo->HwAddressSize, NicInfo->VlanId, MacString);\r
     UnicodeSPrint (\r
       mPrivate->PortString,\r
-      (UINTN) 128,\r
-      L"%s%d",\r
-      MacString,\r
+      (UINTN) ISCSI_NAME_IFR_MAX_SIZE,\r
+      L"Attempt %d",\r
       (UINTN) AttemptConfigOrder[Index]\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
+    AsciiStrToUnicodeStrS (AttemptConfigData->MacString, AttemptMacString, sizeof (AttemptMacString) / sizeof (AttemptMacString[0]));\r
 \r
-    if (AttemptConfigData == NULL) {\r
+    if (AttemptConfigData == NULL || AttemptConfigData->Actived == ISCSI_ACTIVE_DISABLED ||\r
+        StrCmp (MacString, AttemptMacString)) {\r
       continue;\r
     }\r
 \r
@@ -1194,8 +2213,9 @@ IScsiGetConfigData (
 \r
       AttemptConfigData->AutoConfigureMode =\r
         (UINT8) (mPrivate->Ipv6Flag ? IP_MODE_AUTOCONFIG_IP6 : IP_MODE_AUTOCONFIG_IP4);\r
+      AttemptConfigData->AutoConfigureSuccess = FALSE;\r
     }\r
-    \r
+\r
     //\r
     // Get some information from dhcp server.\r
     //\r
@@ -1221,12 +2241,10 @@ IScsiGetConfigData (
       //\r
       // Refresh the state of this attempt to NVR.\r
       //\r
-      AsciiStrToUnicodeStr (AttemptConfigData->MacString, MacString);\r
       UnicodeSPrint (\r
         mPrivate->PortString,\r
         (UINTN) ISCSI_NAME_IFR_MAX_SIZE,\r
-        L"%s%d",\r
-        MacString,\r
+        L"Attempt %d",\r
         (UINTN) AttemptConfigData->AttemptConfigIndex\r
         );\r
 \r
@@ -1277,7 +2295,9 @@ IScsiGetConfigData (
                                                  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
@@ -1349,6 +2369,7 @@ IScsiGetTcpConnDevicePath (
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
   EFI_STATUS                Status;\r
   EFI_DEV_PATH              *DPathNode;\r
+  UINTN                     PathLen;\r
 \r
   if (Session->State != SESSION_STATE_LOGGED_IN) {\r
     return NULL;\r
@@ -1365,7 +2386,7 @@ IScsiGetTcpConnDevicePath (
                   Conn->TcpIo.Handle,\r
                   &gEfiDevicePathProtocolGuid,\r
                   (VOID **) &DevicePath\r
-                  );  \r
+                  );\r
   if (EFI_ERROR (Status)) {\r
     return NULL;\r
   }\r
@@ -1384,24 +2405,61 @@ IScsiGetTcpConnDevicePath (
       if (!Conn->Ipv6Flag && DevicePathSubType (&DPathNode->DevPath) == MSG_IPv4_DP) {\r
         DPathNode->Ipv4.LocalPort       = 0;\r
 \r
-        DPathNode->Ipv4.StaticIpAddress = \r
+        DPathNode->Ipv4.StaticIpAddress =\r
           (BOOLEAN) (!Session->ConfigData->SessionConfigData.InitiatorInfoFromDhcp);\r
 \r
-        IP4_COPY_ADDRESS (\r
-          &DPathNode->Ipv4.GatewayIpAddress,\r
-          &Session->ConfigData->SessionConfigData.Gateway\r
-          );\r
+        //\r
+        //  Add a judgement here to support previous versions of IPv4_DEVICE_PATH.\r
+        //  In previous versions of IPv4_DEVICE_PATH, GatewayIpAddress and SubnetMask\r
+        //  do not exist.\r
+        //  In new version of IPv4_DEVICE_PATH, structcure length is 27.\r
+        //\r
+\r
+        PathLen = DevicePathNodeLength (&DPathNode->Ipv4);\r
+\r
+        if (PathLen == IP4_NODE_LEN_NEW_VERSIONS) {\r
+\r
+          IP4_COPY_ADDRESS (\r
+            &DPathNode->Ipv4.GatewayIpAddress,\r
+            &Session->ConfigData->SessionConfigData.Gateway\r
+            );\r
+\r
+          IP4_COPY_ADDRESS (\r
+            &DPathNode->Ipv4.SubnetMask,\r
+            &Session->ConfigData->SessionConfigData.SubnetMask\r
+            );\r
+        }\r
 \r
-        IP4_COPY_ADDRESS (\r
-          &DPathNode->Ipv4.SubnetMask,\r
-          &Session->ConfigData->SessionConfigData.SubnetMask\r
-          );\r
         break;\r
       } else if (Conn->Ipv6Flag && DevicePathSubType (&DPathNode->DevPath) == MSG_IPv6_DP) {\r
         DPathNode->Ipv6.LocalPort       = 0;\r
-        DPathNode->Ipv6.IpAddressOrigin = 0;\r
-        DPathNode->Ipv6.PrefixLength    = IP6_PREFIX_LENGTH;\r
-        ZeroMem (&DPathNode->Ipv6.GatewayIpAddress, sizeof (EFI_IPv6_ADDRESS));\r
+\r
+        //\r
+        //  Add a judgement here to support previous versions of IPv6_DEVICE_PATH.\r
+        //  In previous versions of IPv6_DEVICE_PATH, IpAddressOrigin, PrefixLength\r
+        //  and GatewayIpAddress do not exist.\r
+        //  In new version of IPv6_DEVICE_PATH, structure length is 60, while in\r
+        //  old versions, the length is 43.\r
+        //\r
+\r
+        PathLen = DevicePathNodeLength (&DPathNode->Ipv6);\r
+\r
+        if (PathLen == IP6_NODE_LEN_NEW_VERSIONS ) {\r
+\r
+          DPathNode->Ipv6.IpAddressOrigin = 0;\r
+          DPathNode->Ipv6.PrefixLength    = IP6_PREFIX_LENGTH;\r
+          ZeroMem (&DPathNode->Ipv6.GatewayIpAddress, sizeof (EFI_IPv6_ADDRESS));\r
+        }\r
+        else if (PathLen == IP6_NODE_LEN_OLD_VERSIONS) {\r
+\r
+          //\r
+          //  StaticIPAddress is a field in old versions of IPv6_DEVICE_PATH, while ignored in new\r
+          //  version. Set StaticIPAddress through its' offset in old IPv6_DEVICE_PATH.\r
+          //\r
+          *((UINT8 *)(&DPathNode->Ipv6) + IP6_OLD_IPADDRESS_OFFSET) =\r
+            (BOOLEAN) (!Session->ConfigData->SessionConfigData.InitiatorInfoFromDhcp);\r
+        }\r
+\r
         break;\r
       }\r
     }\r
@@ -1430,9 +2488,78 @@ IScsiOnExitBootService (
   ISCSI_DRIVER_DATA *Private;\r
 \r
   Private = (ISCSI_DRIVER_DATA *) Context;\r
+\r
   gBS->CloseEvent (Private->ExitBootServiceEvent);\r
+  Private->ExitBootServiceEvent = NULL;\r
 \r
   if (Private->Session != NULL) {\r
     IScsiSessionAbort (Private->Session);\r
   }\r
 }\r
+\r
+/**\r
+  Tests whether a controller handle is being managed by IScsi driver.\r
+\r
+  This function tests whether the driver specified by DriverBindingHandle is\r
+  currently managing the controller specified by ControllerHandle.  This test\r
+  is performed by evaluating if the the protocol specified by ProtocolGuid is\r
+  present on ControllerHandle and is was opened by DriverBindingHandle and Nic\r
+  Device handle with an attribute of EFI_OPEN_PROTOCOL_BY_DRIVER.\r
+  If ProtocolGuid is NULL, then ASSERT().\r
+\r
+  @param  ControllerHandle     A handle for a controller to test.\r
+  @param  DriverBindingHandle  Specifies the driver binding handle for the\r
+                               driver.\r
+  @param  ProtocolGuid         Specifies the protocol that the driver specified\r
+                               by DriverBindingHandle opens in its Start()\r
+                               function.\r
+\r
+  @retval EFI_SUCCESS          ControllerHandle is managed by the driver\r
+                               specified by DriverBindingHandle.\r
+  @retval EFI_UNSUPPORTED      ControllerHandle is not managed by the driver\r
+                               specified by DriverBindingHandle.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+IScsiTestManagedDevice (\r
+  IN  EFI_HANDLE       ControllerHandle,\r
+  IN  EFI_HANDLE       DriverBindingHandle,\r
+  IN  EFI_GUID         *ProtocolGuid\r
+  )\r
+{\r
+  EFI_STATUS     Status;\r
+  VOID           *ManagedInterface;\r
+  EFI_HANDLE     NicControllerHandle;\r
+\r
+  ASSERT (ProtocolGuid != NULL);\r
+\r
+  NicControllerHandle = NetLibGetNicHandle (ControllerHandle, ProtocolGuid);\r
+  if (NicControllerHandle == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  (EFI_GUID *) ProtocolGuid,\r
+                  &ManagedInterface,\r
+                  DriverBindingHandle,\r
+                  NicControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+           ControllerHandle,\r
+           (EFI_GUID *) ProtocolGuid,\r
+           DriverBindingHandle,\r
+           NicControllerHandle\r
+           );\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r