public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ye, Ting" <ting.ye@intel.com>
To: "Zhang, Lubo" <lubo.zhang@intel.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Fu, Siyuan" <siyuan.fu@intel.com>, "Wu, Jiaxin" <jiaxin.wu@intel.com>
Subject: Re: [PATCH v2] NetworkPkg:Add scriptable configuration to iSCSI driver by
Date: Mon, 20 Feb 2017 08:50:19 +0000	[thread overview]
Message-ID: <BC0C045B0E2A584CA4575E779FA2C12A1A8B054E@SHSMSX103.ccr.corp.intel.com> (raw)
In-Reply-To: <1487314532-50492-1-git-send-email-lubo.zhang@intel.com>

Some minor comments for this patch:

1. IScsiConvertAttemptConfigDataToIfrNvDataByKeyword
 	Suggest to describe more details about this function, especially the difference with existing IScsiConvertAttemptConfigDataToIfrNvData.
	Also suggest to add more description for other new added functions, for example, IScsiConfigAddAttemptsByKeywords. We might add the link to x-UEFI keywords to some functions.

2. typos in IScsiDriver.c: Maxmum->Maximum; Creat-> Create 
3. Suggest to update the name " InitiatorAttemptOrder", as "initiator" has special meaning to iSCSI. It might be confusing. 

Others are good to me.
Reviewed-by: Ye Ting <ting.ye@intel.com> 

Thanks,
Ting



-----Original Message-----
From: Zhang, Lubo 
Sent: Friday, February 17, 2017 2:56 PM
To: edk2-devel@lists.01.org
Cc: Ye, Ting <ting.ye@intel.com>; Fu, Siyuan <siyuan.fu@intel.com>; Wu, Jiaxin <jiaxin.wu@intel.com>
Subject: [PATCH v2] NetworkPkg:Add scriptable configuration to iSCSI driver by

v2:
Add error handling if can not create Attempts in driver entry point.
Since we support to define a macro be a PCD value, we enhance our code
by modifying the structure in IFR_NVDATA. This effect code logic mainly
in Creating Keywords,Convert IFR NvData To AttemptConfigData ByKeyword and
reverse function.
Fix typo errors and sync based on the latest code.

Enable iSCSI keywords configuration based on x-UEFI
name space. we introduce new PCD to control the attempt
numbers which will be created in non activated state, besides
the Attempt name is changed to READ_ONLY attribute in UI.
We can invoke KEYWORD HANDLER Protocol to configure
the related keywords.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Zhang Lubo <lubo.zhang@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
---
 NetworkPkg/IScsiDxe/IScsiConfig.c            | 1744 +++++++++++++++++++++-----
 NetworkPkg/IScsiDxe/IScsiConfig.h            |   78 +-
 NetworkPkg/IScsiDxe/IScsiConfigNVDataStruc.h |   67 +-
 NetworkPkg/IScsiDxe/IScsiConfigStrings.uni   |   28 +-
 NetworkPkg/IScsiDxe/IScsiConfigVfr.vfr       |   46 +-
 NetworkPkg/IScsiDxe/IScsiDriver.c            |   28 +-
 NetworkPkg/IScsiDxe/IScsiDriver.h            |    3 +-
 NetworkPkg/IScsiDxe/IScsiDxe.inf             |    5 +-
 NetworkPkg/IScsiDxe/IScsiMisc.c              |  815 +++++++++++-
 NetworkPkg/IScsiDxe/IScsiMisc.h              |   38 +
 NetworkPkg/NetworkPkg.dec                    |    6 +-
 11 files changed, 2506 insertions(+), 352 deletions(-)

diff --git a/NetworkPkg/IScsiDxe/IScsiConfig.c b/NetworkPkg/IScsiDxe/IScsiConfig.c
index 40ea75a..d07bdcb 100644
--- a/NetworkPkg/IScsiDxe/IScsiConfig.c
+++ b/NetworkPkg/IScsiDxe/IScsiConfig.c
@@ -288,10 +288,102 @@ IScsiConvertIsIdToString (
 
   return EFI_SUCCESS;
 }
 
 /**
+  Get the Offset value specified by the input String.
+
+  @param[in]  Configuration      A null-terminated Unicode string in
+                                 <ConfigString> format.
+  @param[in]  String             The string is "&OFFSET=".
+  @param[out]  Value              The Offset value.
+
+  @retval EFI_OUT_OF_RESOURCES   Insufficient resources to store neccessary
+                                 structures.
+  @retval EFI_SUCCESS            Value of <Number> is outputted in Number
+                                 successfully.
+
+**/
+EFI_STATUS
+IScsiGetValue (
+  IN  CONST EFI_STRING             Configuration,
+  IN  CHAR16                       *String,
+  OUT UINTN                        *Value
+  )
+{
+  CHAR16                           *StringPtr;
+  CHAR16                           *TmpPtr;
+  CHAR16                           *Str;
+  CHAR16                           TmpStr[2];
+  UINTN                            Length;
+  UINTN                            Len;
+  UINTN                            Index;
+  UINT8                            *Buf;
+  UINT8                            DigitUint8;
+  EFI_STATUS                       Status;
+
+  //
+  // Get Value.
+  //
+  Buf = NULL;
+  StringPtr = StrStr (Configuration, String);
+  ASSERT(StringPtr != NULL);
+  StringPtr += StrLen (String);
+  TmpPtr = StringPtr;
+
+  while (*StringPtr != L'\0' && *StringPtr != L'&') {
+    StringPtr ++;
+  }
+  Length = StringPtr - TmpPtr;
+  Len = Length + 1;
+
+  Str = AllocateZeroPool (Len * sizeof (CHAR16));
+  if (Str == NULL) {
+    Status = EFI_OUT_OF_RESOURCES;
+    goto Exit;
+  }
+
+  CopyMem (Str, TmpPtr, Len * sizeof (CHAR16));
+  *(Str + Length) = L'\0';
+
+  Len = (Len + 1) / 2;
+  Buf = (UINT8 *) AllocateZeroPool (Len);
+  if (Buf == NULL) {
+    Status = EFI_OUT_OF_RESOURCES;
+    goto Exit;
+  }
+
+  ZeroMem (TmpStr, sizeof (TmpStr));
+  for (Index = 0; Index < Length; Index ++) {
+    TmpStr[0] = Str[Length - Index - 1];
+    DigitUint8 = (UINT8) StrHexToUint64 (TmpStr);
+    if ((Index & 1) == 0) {
+      Buf [Index/2] = DigitUint8;
+    } else {
+      Buf [Index/2] = (UINT8) ((DigitUint8 << 4) + Buf [Index/2]);
+    }
+  }
+
+  *Value = 0;
+  CopyMem (
+    Value,
+    Buf,
+    (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)
+    );
+
+  FreePool (Buf);
+  Status = EFI_SUCCESS;
+
+Exit:
+  if (Str != NULL) {
+    FreePool (Str);
+  }
+
+  return Status;
+}
+
+/**
   Get the attempt config data from global structure by the ConfigIndex.
 
   @param[in]  AttemptConfigIndex     The unique index indicates the attempt.
 
   @return       Pointer to the attempt config data.
@@ -347,10 +439,68 @@ IScsiConfigGetAttemptByNic (
   }
 
   return NULL;
 }
 
+/**
+  Extract the Index of the attempt list.
+
+  @param[in]   AttemptNameList     The Name list of the Attempts.
+  @param[out]  AttemptIndexList    The Index list of the Attempts.
+  @param[in]   IsAddAttempts       If TRUE, Indicates add one or more attempts.
+                                   If FALSE, Indicates delete attempts or change attempt order.
+
+  @retval EFI_SUCCESS              The Attempt list is valid.
+  @retval EFI_INVALID_PARAMETERS   The Attempt List is invalid.
+
+**/
+EFI_STATUS
+IScsiGetAttemptIndexList (
+  IN      CHAR16                    *AttemptNameList,
+     OUT  UINT8                     *AttemptIndexList,
+  IN      BOOLEAN                   IsAddAttempts
+)
+{
+  ISCSI_ATTEMPT_CONFIG_NVDATA   *AttemptConfigData;
+  CHAR16                        *AttemptStr;
+  UINT8                         AttemptIndex;
+  UINTN                         Len;
+  UINTN                         Index;
+
+  Index = 0;
+
+  if ((AttemptNameList == NULL) || (*AttemptNameList == L'\0')) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  AttemptStr = AttemptNameList;
+  Len = StrLen (L"attempt:");
+
+  while (*AttemptStr != L'\0') {
+    AttemptStr = StrStr (AttemptStr, L"attempt:");
+    if (AttemptStr == NULL) {
+      return EFI_INVALID_PARAMETER;
+    }
+    AttemptStr += Len;
+    AttemptIndex = (UINT8)(*AttemptStr - L'0');
+    AttemptConfigData  = IScsiConfigGetAttemptByConfigIndex (AttemptIndex);
+    if (IsAddAttempts) {
+      if ((AttemptConfigData != NULL) || ((AttemptIndex) > PcdGet8 (PcdMaxIScsiAttemptNumber))) {
+        return EFI_INVALID_PARAMETER;
+      }
+    } else {
+      if (AttemptConfigData == NULL) {
+        return EFI_INVALID_PARAMETER;
+      }
+    }
+
+    AttemptIndexList[Index] = AttemptIndex;
+    Index ++;
+    AttemptStr += 2;
+  }
+  return EFI_SUCCESS;
+}
 
 /**
   Convert the iSCSI configuration data into the IFR data.
 
   @param[in]       Attempt                The iSCSI attempt config data.
@@ -459,10 +609,125 @@ IScsiConvertAttemptConfigDataToIfrNvData (
     sizeof (IfrNvData->AttemptName) / sizeof (IfrNvData->AttemptName[0])
     );
 }
 
 /**
+  Convert the iSCSI configuration data into the IFR data.
+
+  @param[in, out]  IfrNvData              The IFR nv data.
+
+**/
+VOID
+EFIAPI
+IScsiConvertAttemptConfigDataToIfrNvDataByKeyword (
+  IN OUT ISCSI_CONFIG_IFR_NVDATA  *IfrNvData
+  )
+{
+  LIST_ENTRY                    *Entry;
+  ISCSI_ATTEMPT_CONFIG_NVDATA   *Attempt;
+  ISCSI_SESSION_CONFIG_NVDATA   *SessionConfigData;
+  ISCSI_CHAP_AUTH_CONFIG_NVDATA *AuthConfigData;
+  CHAR16                        AttemptNameList[ATTEMPT_NAME_LIST_SIZE];
+  EFI_IP_ADDRESS                Ip;
+  UINTN                         Index;
+
+  ZeroMem (AttemptNameList, sizeof (AttemptNameList));
+
+  NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) {
+    Attempt = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);
+    //
+    // Normal session configuration parameters.
+    //
+    SessionConfigData                 = &Attempt->SessionConfigData;
+
+    Index   = Attempt->AttemptConfigIndex - 1;
+
+    //
+    // Save the attempt to AttemptNameList as Attempt:1 Attempt:2
+    //
+    AsciiStrToUnicodeStrS (
+      Attempt->AttemptName,
+      AttemptNameList + StrLen (AttemptNameList),
+      ATTEMPT_NAME_LIST_SIZE
+    );
+    *(AttemptNameList + StrLen (AttemptNameList) - 2) = L':';
+    *(AttemptNameList + StrLen (AttemptNameList))     = L' ';
+
+    AsciiStrToUnicodeStrS (
+      Attempt->AttemptName,
+      IfrNvData->ISCSIAttemptName  + ATTEMPT_NAME_SIZE * Index,
+      ATTEMPT_NAME_SIZE
+    );
+
+    IfrNvData->ISCSIBootEnableList[Index]          = SessionConfigData->Enabled;
+    IfrNvData->ISCSIIpAddressTypeList[Index]       = SessionConfigData->IpMode;
+
+    IfrNvData->ISCSIInitiatorInfoViaDHCP[Index]    = SessionConfigData->InitiatorInfoFromDhcp;
+    IfrNvData->ISCSITargetInfoViaDHCP[Index]       = SessionConfigData->TargetInfoFromDhcp;
+    IfrNvData->ISCSIConnectRetry[Index]            = SessionConfigData->ConnectRetryCount;
+    IfrNvData->ISCSIConnectTimeout[Index]          = SessionConfigData->ConnectTimeout;
+    IfrNvData->ISCSITargetTcpPort[Index]           = SessionConfigData->TargetPort;
+
+    if (SessionConfigData->IpMode == IP_MODE_IP4) {
+      CopyMem (&Ip.v4, &SessionConfigData->LocalIp, sizeof (EFI_IPv4_ADDRESS));
+      IScsiIpToStr (&Ip, FALSE, IfrNvData->Keyword[Index].ISCSIInitiatorIpAddress);
+      CopyMem (&Ip.v4, &SessionConfigData->SubnetMask, sizeof (EFI_IPv4_ADDRESS));
+      IScsiIpToStr (&Ip, FALSE, IfrNvData->Keyword[Index].ISCSIInitiatorNetmask);
+      CopyMem (&Ip.v4, &SessionConfigData->Gateway, sizeof (EFI_IPv4_ADDRESS));
+      IScsiIpToStr (&Ip, FALSE, IfrNvData->Keyword[Index].ISCSIInitiatorGateway);
+      CopyMem (&Ip.v4, &SessionConfigData->TargetIp, sizeof (EFI_IPv4_ADDRESS));
+      IScsiIpToStr (&Ip, FALSE, IfrNvData->Keyword[Index].ISCSITargetIpAddress);
+    } else if (SessionConfigData->IpMode == IP_MODE_IP6) {
+      ZeroMem (IfrNvData->Keyword[Index].ISCSITargetIpAddress, sizeof (IfrNvData->TargetIp));
+      IP6_COPY_ADDRESS (&Ip.v6, &SessionConfigData->TargetIp);
+      IScsiIpToStr (&Ip, TRUE, IfrNvData->Keyword[Index].ISCSITargetIpAddress);
+    }
+
+    AsciiStrToUnicodeStrS (
+      SessionConfigData->TargetName,
+      IfrNvData->Keyword[Index].ISCSITargetName,
+      ISCSI_NAME_MAX_SIZE
+      );
+
+    IScsiLunToUnicodeStr (SessionConfigData->BootLun, IfrNvData->Keyword[Index].ISCSILUN);
+    IScsiConvertIsIdToString (IfrNvData->Keyword[Index].ISCSIISID, SessionConfigData->IsId);
+
+    IfrNvData->ISCSIAuthenticationMethod[Index]    = Attempt->AuthenticationType;
+
+    if (Attempt->AuthenticationType == ISCSI_AUTH_TYPE_CHAP) {
+      AuthConfigData      = &Attempt->AuthConfigData.CHAP;
+      IfrNvData->ISCSIChapType[Index] = AuthConfigData->CHAPType;
+      AsciiStrToUnicodeStrS (
+        AuthConfigData->CHAPName,
+        IfrNvData->Keyword[Index].ISCSIChapUsername,
+        ISCSI_CHAP_NAME_STORAGE
+        );
+
+      AsciiStrToUnicodeStrS (
+        AuthConfigData->CHAPSecret,
+        IfrNvData->Keyword[Index].ISCSIChapSecret,
+        ISCSI_CHAP_SECRET_STORAGE
+        );
+
+      AsciiStrToUnicodeStrS (
+        AuthConfigData->ReverseCHAPName,
+        IfrNvData->Keyword[Index].ISCSIReverseChapUsername,
+        ISCSI_CHAP_NAME_STORAGE
+        );
+
+      AsciiStrToUnicodeStrS (
+        AuthConfigData->ReverseCHAPSecret,
+        IfrNvData->Keyword[Index].ISCSIReverseChapSecret,
+        ISCSI_CHAP_SECRET_STORAGE
+        );
+    }
+  }
+
+  CopyMem(IfrNvData->ISCSIDisplayAttemptList, AttemptNameList, ATTEMPT_NAME_LIST_SIZE);
+}
+
+/**
   Convert the IFR data to iSCSI configuration data.
 
   @param[in]       IfrNvData              Point to ISCSI_CONFIG_IFR_NVDATA.
   @param[in, out]  Attempt                The iSCSI attempt config data.
 
@@ -534,11 +799,11 @@ IScsiConvertIfrNvDataToAttemptConfigData (
         EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
         &Key,
         L"Connection Establishing Timeout is less than minimum value 100ms.",
         NULL
         );
-      
+
       return EFI_INVALID_PARAMETER;
     }
 
     //
     // Validate the address configuration of the Initiator if DHCP isn't
@@ -555,20 +820,20 @@ IScsiConvertIfrNvDataToAttemptConfigData (
             EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
             &Key,
             L"Gateway address is set but subnet mask is zero.",
             NULL
             );
-          
+
           return EFI_INVALID_PARAMETER;
         } else if (!IP4_NET_EQUAL (HostIp.Addr[0], Gateway.Addr[0], SubnetMask.Addr[0])) {
           CreatePopUp (
             EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
             &Key,
             L"Local IP and Gateway are not in the same subnet.",
             NULL
             );
-          
+
           return EFI_INVALID_PARAMETER;
         }
       }
     }
     //
@@ -611,11 +876,10 @@ IScsiConvertIfrNvDataToAttemptConfigData (
           );
         return EFI_INVALID_PARAMETER;
       }
     }
 
-
     //
     // Validate the authentication info.
     //
     if (IfrNvData->AuthenticationType == ISCSI_AUTH_TYPE_CHAP) {
       if ((IfrNvData->CHAPName[0] == '\0') || (IfrNvData->CHAPSecret[0] == '\0')) {
@@ -645,30 +909,23 @@ IScsiConvertIfrNvDataToAttemptConfigData (
     //
     // Check whether this attempt uses NIC which is already used by existing attempt.
     //
     SameNicAttempt = IScsiConfigGetAttemptByNic (Attempt, IfrNvData->Enabled);
     if (SameNicAttempt != NULL) {
-      AttemptName1 = (CHAR16 *) AllocateZeroPool (ATTEMPT_NAME_MAX_SIZE * sizeof (CHAR16));
+      AttemptName1 = (CHAR16 *) AllocateZeroPool (ATTEMPT_NAME_SIZE * sizeof (CHAR16));
       if (AttemptName1 == NULL) {
         return EFI_OUT_OF_RESOURCES;
       }
 
-      AttemptName2 = (CHAR16 *) AllocateZeroPool (ATTEMPT_NAME_MAX_SIZE * sizeof (CHAR16));
+      AttemptName2 = (CHAR16 *) AllocateZeroPool (ATTEMPT_NAME_SIZE * sizeof (CHAR16));
       if (AttemptName2 == NULL) {
         FreePool (AttemptName1);
         return EFI_OUT_OF_RESOURCES;
       }      
-      
-      AsciiStrToUnicodeStrS (Attempt->AttemptName, AttemptName1, ATTEMPT_NAME_MAX_SIZE);
-      if (StrLen (AttemptName1) > ATTEMPT_NAME_SIZE) {
-        CopyMem (&AttemptName1[ATTEMPT_NAME_SIZE], L"...", 4 * sizeof (CHAR16));
-      }
 
-      AsciiStrToUnicodeStrS (SameNicAttempt->AttemptName, AttemptName2, ATTEMPT_NAME_MAX_SIZE);
-      if (StrLen (AttemptName2) > ATTEMPT_NAME_SIZE) {
-        CopyMem (&AttemptName2[ATTEMPT_NAME_SIZE], L"...", 4 * sizeof (CHAR16));
-      }
+      AsciiStrToUnicodeStrS (Attempt->AttemptName, AttemptName1, ATTEMPT_NAME_SIZE);
+      AsciiStrToUnicodeStrS (SameNicAttempt->AttemptName, AttemptName2, ATTEMPT_NAME_SIZE);
 
       UnicodeSPrint (
         mPrivate->PortString,
         (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
         L"Warning! Attempt \"%s\" uses same NIC as Attempt \"%s\".",
@@ -689,11 +946,10 @@ IScsiConvertIfrNvDataToAttemptConfigData (
   }
 
   //
   // Update the iSCSI Mode data and record it in attempt help info.
   //
-  Attempt->SessionConfigData.Enabled = IfrNvData->Enabled;
   if (IfrNvData->Enabled == ISCSI_DISABLED) {
     UnicodeSPrint (IScsiMode, 64, L"Disabled");
   } else if (IfrNvData->Enabled == ISCSI_ENABLED) {
     UnicodeSPrint (IScsiMode, 64, L"Enabled");
   } else if (IfrNvData->Enabled == ISCSI_ENABLED_FOR_MPIO) {
@@ -813,15 +1069,14 @@ IScsiConvertIfrNvDataToAttemptConfigData (
     }
 
   } else if (ExistAttempt == NULL) {
     //
     // When a new attempt is created, pointer of the attempt is saved to
-    // mPrivate->NewAttempt, and also saved to mCallbackInfo->Current in
-    // IScsiConfigProcessDefault. If input Attempt does not match any existing
-    // attempt, it should be a new created attempt. Save it to system now.
-    //    
-    ASSERT (Attempt == mPrivate->NewAttempt);
+    // mCallbackInfo->Current in IScsiConfigProcessDefault. If input Attempt
+    // does not match any existing attempt, it should be a new created attempt.
+    // Save it to system now.
+    //
 
     //
     // Save current order number for this attempt.
     //
     AttemptConfigOrder = IScsiGetVariableAndSize (
@@ -868,15 +1123,10 @@ IScsiConvertIfrNvDataToAttemptConfigData (
     //
     // Insert new created attempt to array.
     //
     InsertTailList (&mPrivate->AttemptConfigs, &Attempt->Link);
     mPrivate->AttemptCount++;
-    //
-    // Reset mPrivate->NewAttempt to NULL, which indicates none attempt is created
-    // but not saved now.
-    //
-    mPrivate->NewAttempt = NULL;
 
     if (IfrNvData->Enabled == ISCSI_ENABLED_FOR_MPIO) {
       //
       // This new Attempt is enabled for MPIO; enable the multipath mode.
       //
@@ -886,21 +1136,16 @@ IScsiConvertIfrNvDataToAttemptConfigData (
       mPrivate->SinglePathCount++;
     }
 
     IScsiConfigUpdateAttempt ();
   }
+  Attempt->SessionConfigData.Enabled = IfrNvData->Enabled;
 
   //
   // Record the user configuration information in NVR.
   //
-  UnicodeSPrint (
-    mPrivate->PortString,
-    (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
-    L"%s%d",
-    MacString,
-    (UINTN) Attempt->AttemptConfigIndex
-    );
+  UnicodeSPrint (mPrivate->PortString, (UINTN) ISCSI_NAME_IFR_MAX_SIZE, L"Attempt %d", Attempt->AttemptConfigIndex);
 
   FreePool (MacString);
 
   return gRT->SetVariable (
                 mPrivate->PortString,
@@ -910,114 +1155,755 @@ IScsiConvertIfrNvDataToAttemptConfigData (
                 Attempt
                 );
 }
 
 /**
-  Create Hii Extend Label OpCode as the start opcode and end opcode. It is 
-  a help function.
+  Convert the IFR data to iSCSI configuration data by keyword.
 
-  @param[in]  StartLabelNumber   The number of start label.
-  @param[out] StartOpCodeHandle  Points to the start opcode handle.
-  @param[out] StartLabel         Points to the created start opcode.
-  @param[out] EndOpCodeHandle    Points to the end opcode handle.
-  @param[out] EndLabel           Points to the created end opcode.
+  @param[in]  IfrNvData      Point to ISCSI_CONFIG_IFR_NVDATA.
+  @param[in]  OffSet         The offset of the variable to the configuration structure.
 
-  @retval EFI_OUT_OF_RESOURCES   Do not have sufficient resource to finish this
-                                 operation.
-  @retval EFI_INVALID_PARAMETER  Any input parameter is invalid.                                 
+  @retval EFI_INVALID_PARAMETER  Any input or configured parameter is invalid.
   @retval EFI_SUCCESS            The operation is completed successfully.
 
 **/
 EFI_STATUS
-IScsiCreateOpCode (
-  IN  UINT16                        StartLabelNumber,
-  OUT VOID                          **StartOpCodeHandle,
-  OUT EFI_IFR_GUID_LABEL            **StartLabel,
-  OUT VOID                          **EndOpCodeHandle,
-  OUT EFI_IFR_GUID_LABEL            **EndLabel
+IScsiConvertlfrNvDataToAttemptConfigDataByKeyword (
+  IN ISCSI_CONFIG_IFR_NVDATA          *IfrNvData,
+  IN UINTN                             OffSet
   )
 {
-  EFI_STATUS                        Status;
-  EFI_IFR_GUID_LABEL                *InternalStartLabel;
-  EFI_IFR_GUID_LABEL                *InternalEndLabel;
-
-  if (StartOpCodeHandle == NULL || StartLabel == NULL || EndOpCodeHandle == NULL || EndLabel == NULL) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  *StartOpCodeHandle = NULL;
-  *EndOpCodeHandle   = NULL;
-  Status             = EFI_OUT_OF_RESOURCES;
+  ISCSI_ATTEMPT_CONFIG_NVDATA      *Attempt;
+  UINT8                            AttemptIndex;
+  UINT8                            Index;
+  CHAR16                           *AttemptName1;
+  CHAR16                           *AttemptName2;
+  ISCSI_ATTEMPT_CONFIG_NVDATA      *SameNicAttempt;
+  CHAR8                            LunString[ISCSI_LUN_STR_MAX_LEN];
+  CHAR8                            IScsiName[ISCSI_NAME_MAX_SIZE];
+  CHAR8                            IpString[IP_STR_MAX_SIZE];
+  EFI_IP_ADDRESS                   HostIp;
+  EFI_IP_ADDRESS                   SubnetMask;
+  EFI_IP_ADDRESS                   Gateway;
+  EFI_INPUT_KEY                    Key;
+  UINT64                           Lun;
+  EFI_STATUS                       Status;
 
-  //
-  // Initialize the container for dynamic opcodes.
-  //
-  *StartOpCodeHandle = HiiAllocateOpCodeHandle ();
-  if (*StartOpCodeHandle == NULL) {
-    return Status;
-  }
+  ZeroMem (IScsiName, sizeof (IScsiName));
 
-  *EndOpCodeHandle = HiiAllocateOpCodeHandle ();
-  if (*EndOpCodeHandle == NULL) {
-    goto Exit;
-  }
+  if (OffSet < ATTEMPT_BOOTENABLE_VAR_OFFSET) {
+    return EFI_SUCCESS;
 
-  //
-  // Create Hii Extend Label OpCode as the start opcode.
-  //
-  InternalStartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (
-                                                *StartOpCodeHandle,
-                                                &gEfiIfrTianoGuid,
-                                                NULL,
-                                                sizeof (EFI_IFR_GUID_LABEL)
-                                                );
-  if (InternalStartLabel == NULL) {
-    goto Exit;
-  }
-  
-  InternalStartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
-  InternalStartLabel->Number       = StartLabelNumber;
+  } else if ((OffSet >= ATTEMPT_BOOTENABLE_VAR_OFFSET) && (OffSet < ATTEMPT_ADDRESS_TYPE_VAR_OFFSET)) {
+    AttemptIndex = (UINT8) ((OffSet - ATTEMPT_BOOTENABLE_VAR_OFFSET) + 1);
+    Attempt = IScsiConfigGetAttemptByConfigIndex (AttemptIndex);
+    if (Attempt == NULL) {
+      return EFI_INVALID_PARAMETER;
+    }
+    IfrNvData->Enabled = IfrNvData->ISCSIBootEnableList[AttemptIndex - 1];
+    //
+    // Validate the configuration of attempt.
+    //
+    if (IfrNvData->Enabled != ISCSI_DISABLED) {
+      //
+      // Check whether this attempt uses NIC which is already used by existing attempt.
+      //
+      SameNicAttempt = IScsiConfigGetAttemptByNic (Attempt, IfrNvData->Enabled);
+      if (SameNicAttempt != NULL) {
+        AttemptName1 = (CHAR16 *) AllocateZeroPool (ATTEMPT_NAME_SIZE * sizeof (CHAR16));
+        if (AttemptName1 == NULL) {
+          return EFI_OUT_OF_RESOURCES;
+        }
 
-  //
-  // Create Hii Extend Label OpCode as the end opcode.
-  //
-  InternalEndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (
-                                              *EndOpCodeHandle,
-                                              &gEfiIfrTianoGuid,
-                                              NULL,
-                                              sizeof (EFI_IFR_GUID_LABEL)
-                                              );
-  if (InternalEndLabel == NULL) {
-    goto Exit;
-  }
+        AttemptName2 = (CHAR16 *) AllocateZeroPool (ATTEMPT_NAME_SIZE * sizeof (CHAR16));
+        if (AttemptName2 == NULL) {
+          FreePool (AttemptName1);
+          return EFI_OUT_OF_RESOURCES;
+        }
 
-  InternalEndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
-  InternalEndLabel->Number       = LABEL_END;
+        AsciiStrToUnicodeStrS (Attempt->AttemptName, AttemptName1, ATTEMPT_NAME_SIZE);
+        AsciiStrToUnicodeStrS (SameNicAttempt->AttemptName, AttemptName2, ATTEMPT_NAME_SIZE);
 
-  *StartLabel = InternalStartLabel;
-  *EndLabel   = InternalEndLabel;
+        UnicodeSPrint (
+          mPrivate->PortString,
+          (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
+          L"Warning! \"%s\" uses same NIC as Attempt \"%s\".",
+          AttemptName1,
+          AttemptName2
+          );
 
-  return EFI_SUCCESS;
+        CreatePopUp (
+          EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+          &Key,
+          mPrivate->PortString,
+          NULL
+          );
 
-Exit:
+        FreePool (AttemptName1);
+        FreePool (AttemptName2);
+      }
+    }
 
-  if (*StartOpCodeHandle != NULL) {
-    HiiFreeOpCodeHandle (*StartOpCodeHandle);
-  }
+    if (IfrNvData->Enabled == ISCSI_DISABLED &&
+        Attempt->SessionConfigData.Enabled != ISCSI_DISABLED) {
 
-  if (*EndOpCodeHandle != NULL) {
-    HiiFreeOpCodeHandle (*EndOpCodeHandle);
-  }
-  
-  return Status;
-}
+      //
+      // User updates the Attempt from "Enabled"/"Enabled for MPIO" to "Disabled".
+      //
+      if (Attempt->SessionConfigData.Enabled == ISCSI_ENABLED_FOR_MPIO) {
+        if (mPrivate->MpioCount < 1) {
+          return EFI_ABORTED;
+        }
 
-/**
-  Callback function when user presses "Add an Attempt".
+        if (--mPrivate->MpioCount == 0) {
+          mPrivate->EnableMpio = FALSE;
+        }
+      } else if (Attempt->SessionConfigData.Enabled == ISCSI_ENABLED) {
+        if (mPrivate->SinglePathCount < 1) {
+          return EFI_ABORTED;
+        }
+        mPrivate->SinglePathCount--;
+      }
 
-  @retval EFI_OUT_OF_RESOURCES   Does not have sufficient resources to finish this
-                                 operation.
+    } else if (IfrNvData->Enabled == ISCSI_ENABLED_FOR_MPIO &&
+               Attempt->SessionConfigData.Enabled == ISCSI_ENABLED) {
+      //
+      // User updates the Attempt from "Enabled" to "Enabled for MPIO".
+      //
+      if (mPrivate->SinglePathCount < 1) {
+        return EFI_ABORTED;
+      }
+
+      mPrivate->EnableMpio = TRUE;
+      mPrivate->MpioCount++;
+      mPrivate->SinglePathCount--;
+
+    } else if (IfrNvData->Enabled == ISCSI_ENABLED &&
+               Attempt->SessionConfigData.Enabled == ISCSI_ENABLED_FOR_MPIO) {
+      //
+      // User updates the Attempt from "Enabled for MPIO" to "Enabled".
+      //
+      if (mPrivate->MpioCount < 1) {
+        return EFI_ABORTED;
+      }
+
+      if (--mPrivate->MpioCount == 0) {
+        mPrivate->EnableMpio = FALSE;
+      }
+      mPrivate->SinglePathCount++;
+
+    } else if (IfrNvData->Enabled != ISCSI_DISABLED &&
+               Attempt->SessionConfigData.Enabled == ISCSI_DISABLED) {
+      //
+      // User updates the Attempt from "Disabled" to "Enabled"/"Enabled for MPIO".
+      //
+      if (IfrNvData->Enabled == ISCSI_ENABLED_FOR_MPIO) {
+        mPrivate->EnableMpio = TRUE;
+        mPrivate->MpioCount++;
+
+      } else if (IfrNvData->Enabled == ISCSI_ENABLED) {
+        mPrivate->SinglePathCount++;
+      }
+    }
+    Attempt->SessionConfigData.Enabled = IfrNvData->Enabled;
+
+  } else if ((OffSet >= ATTEMPT_ADDRESS_TYPE_VAR_OFFSET) && (OffSet < ATTEMPT_CONNECT_RETRY_VAR_OFFSET)) {
+    AttemptIndex = (UINT8) ((OffSet - ATTEMPT_ADDRESS_TYPE_VAR_OFFSET) + 1);
+    Attempt = IScsiConfigGetAttemptByConfigIndex (AttemptIndex);
+    if (Attempt == NULL) {
+      return EFI_INVALID_PARAMETER;
+    }
+    Attempt->SessionConfigData.IpMode = IfrNvData->ISCSIIpAddressTypeList[AttemptIndex - 1];
+    if (Attempt->SessionConfigData.IpMode < IP_MODE_AUTOCONFIG) {
+      Attempt->AutoConfigureMode = 0;
+    }
+
+  } else if ((OffSet >= ATTEMPT_CONNECT_RETRY_VAR_OFFSET) && (OffSet < ATTEMPT_CONNECT_TIMEOUT_VAR_OFFSET)) {
+    AttemptIndex = (UINT8) ((OffSet - ATTEMPT_CONNECT_RETRY_VAR_OFFSET) + 1);
+    Attempt = IScsiConfigGetAttemptByConfigIndex (AttemptIndex);
+    if (Attempt == NULL) {
+      return EFI_INVALID_PARAMETER;
+    }
+    Attempt->SessionConfigData.ConnectRetryCount = IfrNvData->ISCSIConnectRetry[AttemptIndex - 1];
+    if (Attempt->SessionConfigData.ConnectRetryCount == 0) {
+      Attempt->SessionConfigData.ConnectRetryCount = CONNECT_MIN_RETRY;
+    }
+
+  } else if ((OffSet >= ATTEMPT_CONNECT_TIMEOUT_VAR_OFFSET) && (OffSet < ATTEMPT_INITIATOR_VIA_DHCP_VAR_OFFSET)) {
+    AttemptIndex = (UINT8) ((OffSet - ATTEMPT_CONNECT_TIMEOUT_VAR_OFFSET) / 2 + 1);
+    Attempt = IScsiConfigGetAttemptByConfigIndex (AttemptIndex);
+    if (Attempt == NULL) {
+      return EFI_INVALID_PARAMETER;
+    }
+    Attempt->SessionConfigData.ConnectTimeout = IfrNvData->ISCSIConnectTimeout[AttemptIndex - 1];
+    if (Attempt->SessionConfigData.ConnectTimeout == 0) {
+      Attempt->SessionConfigData.ConnectTimeout = CONNECT_DEFAULT_TIMEOUT;
+    }
+
+    if (Attempt->SessionConfigData.Enabled != ISCSI_DISABLED) {
+      if (Attempt->SessionConfigData.ConnectTimeout < CONNECT_MIN_TIMEOUT) {
+        CreatePopUp (
+          EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+          &Key,
+          L"Connection Establishing Timeout is less than minimum value 100ms.",
+          NULL
+          );
+        return EFI_INVALID_PARAMETER;
+      }
+    }
+
+  } else if ((OffSet >= ATTEMPT_INITIATOR_VIA_DHCP_VAR_OFFSET) && (OffSet < ATTEMPT_TARGET_VIA_DHCP_VAR_OFFSET)) {
+    AttemptIndex = (UINT8) ((OffSet - ATTEMPT_INITIATOR_VIA_DHCP_VAR_OFFSET) + 1);
+    Attempt = IScsiConfigGetAttemptByConfigIndex (AttemptIndex);
+    if (Attempt == NULL) {
+      return EFI_INVALID_PARAMETER;
+    }
+    Attempt->SessionConfigData.InitiatorInfoFromDhcp = IfrNvData->ISCSIInitiatorInfoViaDHCP[AttemptIndex - 1];
+
+  } else if ((OffSet >= ATTEMPT_TARGET_VIA_DHCP_VAR_OFFSET) && (OffSet < ATTEMPT_TARGET_TCP_PORT_VAR_OFFSET)) {
+    AttemptIndex = (UINT8) ((OffSet - ATTEMPT_TARGET_VIA_DHCP_VAR_OFFSET) + 1);
+    Attempt = IScsiConfigGetAttemptByConfigIndex (AttemptIndex);
+    if (Attempt == NULL) {
+      return EFI_INVALID_PARAMETER;
+    }
+
+    if ((Attempt->SessionConfigData.IpMode < IP_MODE_AUTOCONFIG) && (Attempt->SessionConfigData.InitiatorInfoFromDhcp)) {
+      Attempt->SessionConfigData.TargetInfoFromDhcp = IfrNvData->ISCSITargetInfoViaDHCP[AttemptIndex - 1];
+    } else {
+      CreatePopUp (
+        EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+        &Key,
+        L"Invalid Configuration, Check value of IpMode or Enable DHCP!",
+        NULL
+        );
+      return EFI_INVALID_PARAMETER;
+    }
+
+  } else if ((OffSet >= ATTEMPT_TARGET_TCP_PORT_VAR_OFFSET) && (OffSet < ATTEMPT_AUTHENTICATION_METHOD_VAR_OFFSET)) {
+    AttemptIndex = (UINT8) ((OffSet - ATTEMPT_TARGET_TCP_PORT_VAR_OFFSET) / 2 + 1);
+    Attempt = IScsiConfigGetAttemptByConfigIndex (AttemptIndex);
+    if (Attempt == NULL) {
+      return EFI_INVALID_PARAMETER;
+    }
+    if ((Attempt->SessionConfigData.IpMode < IP_MODE_AUTOCONFIG) && (!Attempt->SessionConfigData.TargetInfoFromDhcp)) {
+      Attempt->SessionConfigData.TargetPort = IfrNvData->ISCSITargetTcpPort[AttemptIndex - 1];
+      if (Attempt->SessionConfigData.TargetPort == 0) {
+        Attempt->SessionConfigData.TargetPort = ISCSI_WELL_KNOWN_PORT;
+      }
+    } else {
+      CreatePopUp (
+        EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+        &Key,
+        L"Invalid Configuration, Check value of IpMode or Target Via DHCP!",
+        NULL
+        );
+      return EFI_INVALID_PARAMETER;
+    }
+
+  } else if ((OffSet >= ATTEMPT_AUTHENTICATION_METHOD_VAR_OFFSET) && (OffSet < ATTEMPT_CHARTYPE_VAR_OFFSET)) {
+    AttemptIndex = (UINT8) ((OffSet - ATTEMPT_AUTHENTICATION_METHOD_VAR_OFFSET) + 1);
+    Attempt = IScsiConfigGetAttemptByConfigIndex (AttemptIndex);
+    if (Attempt == NULL) {
+      return EFI_INVALID_PARAMETER;
+    }
+
+    Attempt->AuthenticationType = IfrNvData->ISCSIAuthenticationMethod[AttemptIndex - 1];
+
+  } else if ((OffSet >= ATTEMPT_CHARTYPE_VAR_OFFSET) && (OffSet < ATTEMPT_ISID_VAR_OFFSET)) {
+    AttemptIndex = (UINT8) ((OffSet - ATTEMPT_CHARTYPE_VAR_OFFSET) + 1);
+    Attempt = IScsiConfigGetAttemptByConfigIndex (AttemptIndex);
+    if (Attempt == NULL) {
+      return EFI_INVALID_PARAMETER;
+    }
+    if (Attempt->AuthenticationType == ISCSI_AUTH_TYPE_CHAP) {
+      Attempt->AuthConfigData.CHAP.CHAPType = IfrNvData->ISCSIChapType[AttemptIndex - 1];
+    }
+
+  } else if (OffSet >= ATTEMPT_ISID_VAR_OFFSET) {
+    Index = (UINT8) ((OffSet - ATTEMPT_ISID_VAR_OFFSET) / sizeof (KEYWORD_STR));
+    AttemptIndex = Index + 1;
+    Attempt = IScsiConfigGetAttemptByConfigIndex (AttemptIndex);
+    if (Attempt == NULL) {
+      return EFI_INVALID_PARAMETER;
+    }
+
+    OffSet = OffSet - Index * sizeof (KEYWORD_STR);
+
+    if ((OffSet >= ATTEMPT_ISID_VAR_OFFSET) && (OffSet < ATTEMPT_INITIATOR_IP_ADDRESS_VAR_OFFSET)) {
+      IScsiParseIsIdFromString (IfrNvData->Keyword[Index].ISCSIISID, Attempt->SessionConfigData.IsId);
+
+    }  else if ((OffSet >= ATTEMPT_INITIATOR_IP_ADDRESS_VAR_OFFSET) && (OffSet < ATTEMPT_INITIATOR_NET_MASK_VAR_OFFSET)) {
+      if ((Attempt->SessionConfigData.IpMode == IP_MODE_IP4) && (!Attempt->SessionConfigData.InitiatorInfoFromDhcp)) {
+        //
+        // Config Local ip
+        //
+        Status = NetLibStrToIp4 (IfrNvData->Keyword[Index].ISCSIInitiatorIpAddress, &HostIp.v4);
+        if (EFI_ERROR (Status) || ((Attempt->SessionConfigData.SubnetMask.Addr[0] != 0) &&
+             !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), NTOHL(*(UINT32*)Attempt->SessionConfigData.SubnetMask.Addr)))) {
+          CreatePopUp (
+            EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+            &Key,
+            L"Invalid IP address!",
+            NULL
+            );
+          return EFI_INVALID_PARAMETER;
+        } else {
+          CopyMem (&Attempt->SessionConfigData.LocalIp, &HostIp.v4, sizeof (HostIp.v4));
+        }
+      } else {
+        CreatePopUp (
+          EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+          &Key,
+          L"Invalid Configuration, Check value of IpMode or Enable DHCP!",
+          NULL
+          );
+        return EFI_INVALID_PARAMETER;
+      }
+
+    } else if ((OffSet >= ATTEMPT_INITIATOR_NET_MASK_VAR_OFFSET) && (OffSet < ATTEMPT_INITIATOR_GATE_WAY_VAR_OFFSET)) {
+      if ((Attempt->SessionConfigData.IpMode == IP_MODE_IP4) && (!Attempt->SessionConfigData.InitiatorInfoFromDhcp)) {
+        Status = NetLibStrToIp4 (IfrNvData->Keyword[Index].ISCSIInitiatorNetmask, &SubnetMask.v4);
+        if (EFI_ERROR (Status) || ((SubnetMask.Addr[0] != 0) && (IScsiGetSubnetMaskPrefixLength (&SubnetMask.v4) == 0))) {
+          CreatePopUp (
+            EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+            &Key,
+            L"Invalid Subnet Mask!",
+            NULL
+            );
+          return EFI_INVALID_PARAMETER;
+        } else {
+          CopyMem (&Attempt->SessionConfigData.SubnetMask, &SubnetMask.v4, sizeof (SubnetMask.v4));
+        }
+      } else {
+        CreatePopUp (
+          EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+          &Key,
+          L"Invalid Configuration, Check value of IpMode or Enable DHCP!",
+          NULL
+          );
+        return EFI_INVALID_PARAMETER;
+      }
+
+    } else if ((OffSet >= ATTEMPT_INITIATOR_GATE_WAY_VAR_OFFSET) && (OffSet < ATTEMPT_TARGET_NAME_VAR_OFFSET)) {
+      if ((Attempt->SessionConfigData.IpMode == IP_MODE_IP4) && (!Attempt->SessionConfigData.InitiatorInfoFromDhcp)) {
+        Status = NetLibStrToIp4 (IfrNvData->Keyword[Index].ISCSIInitiatorGateway, &Gateway.v4);
+        if (EFI_ERROR (Status) ||
+          ((Gateway.Addr[0] != 0) && (Attempt->SessionConfigData.SubnetMask.Addr[0] != 0) &&
+             !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), NTOHL(*(UINT32*)Attempt->SessionConfigData.SubnetMask.Addr)))) {
+          CreatePopUp (
+            EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+            &Key,
+            L"Invalid Gateway!",
+            NULL
+            );
+          return EFI_INVALID_PARAMETER;
+        } else {
+          CopyMem (&Attempt->SessionConfigData.Gateway, &Gateway.v4, sizeof (Gateway.v4));
+        }
+      } else {
+        CreatePopUp (
+          EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+          &Key,
+          L"Invalid Configuration, Check value of IpMode or Enable DHCP!",
+          NULL
+          );
+        return EFI_INVALID_PARAMETER;
+      }
+
+    } else if ((OffSet >= ATTEMPT_TARGET_NAME_VAR_OFFSET) && (OffSet < ATTEMPT_TARGET_IP_ADDRESS_VAR_OFFSET)) {
+      if ((Attempt->SessionConfigData.IpMode < IP_MODE_AUTOCONFIG) && (!Attempt->SessionConfigData.TargetInfoFromDhcp)) {
+        UnicodeStrToAsciiStrS (IfrNvData->Keyword[Index].ISCSITargetName, IScsiName, ISCSI_NAME_MAX_SIZE);
+        Status = IScsiNormalizeName (IScsiName, AsciiStrLen (IScsiName));
+        if (EFI_ERROR (Status)) {
+          CreatePopUp (
+            EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+            &Key,
+            L"Invalid iSCSI Name!",
+            NULL
+            );
+        } else {
+          AsciiStrCpyS (Attempt->SessionConfigData.TargetName, ISCSI_NAME_MAX_SIZE, IScsiName);
+        }
+        if (Attempt->SessionConfigData.Enabled != ISCSI_DISABLED) {
+          if (Attempt->SessionConfigData.TargetName[0] == L'\0') {
+            CreatePopUp (
+              EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+              &Key,
+              L"iSCSI target name is NULL!",
+              NULL
+              );
+            return EFI_INVALID_PARAMETER;
+          }
+        }
+      } else {
+        CreatePopUp (
+          EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+          &Key,
+          L"Invalid Configuration, Check value of IpMode or Target Via DHCP!",
+          NULL
+          );
+        return EFI_INVALID_PARAMETER;
+      }
+
+    } else if ((OffSet >= ATTEMPT_TARGET_IP_ADDRESS_VAR_OFFSET) && (OffSet < ATTEMPT_LUN_VAR_OFFSET)) {
+      if ((Attempt->SessionConfigData.IpMode < IP_MODE_AUTOCONFIG) && (!Attempt->SessionConfigData.TargetInfoFromDhcp)) {
+        UnicodeStrToAsciiStrS (IfrNvData->Keyword[Index].ISCSITargetIpAddress, IpString, IP_STR_MAX_SIZE);
+        Status = IScsiAsciiStrToIp (IpString, Attempt->SessionConfigData.IpMode, &HostIp);
+        if (EFI_ERROR (Status) || !IpIsUnicast (&HostIp, Attempt->SessionConfigData.IpMode)) {
+          CreatePopUp (
+            EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+            &Key,
+            L"Invalid IP address!",
+            NULL
+            );
+          return EFI_INVALID_PARAMETER;
+        } else {
+          CopyMem (&Attempt->SessionConfigData.TargetIp, &HostIp, sizeof (HostIp));
+        }
+      } else {
+        CreatePopUp (
+          EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+          &Key,
+          L"Invalid Configuration, Check value of IpMode or Target Via DHCP!",
+          NULL
+          );
+        return EFI_INVALID_PARAMETER;
+      }
+
+    } else if ((OffSet >= ATTEMPT_LUN_VAR_OFFSET) && (OffSet < ATTEMPT_CHAR_USER_NAME_VAR_OFFSET)) {
+      if ((Attempt->SessionConfigData.IpMode < IP_MODE_AUTOCONFIG) && (Attempt->SessionConfigData.TargetInfoFromDhcp == 0)) {
+        //
+        // Config LUN.
+        //
+        UnicodeStrToAsciiStrS (IfrNvData->Keyword[Index].ISCSILUN, LunString, ISCSI_LUN_STR_MAX_LEN);
+        Status = IScsiAsciiStrToLun (LunString, (UINT8 *) &Lun);
+        if (EFI_ERROR (Status)) {
+          CreatePopUp (
+            EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+            &Key,
+            L"Invalid LUN string, Examples are: 4752-3A4F-6b7e-2F99, 6734-9-156f-127, 4186-9!",
+            NULL
+            );
+        } else {
+          CopyMem (&Attempt->SessionConfigData.BootLun, &Lun, sizeof (Lun));
+        }
+      } else {
+        CreatePopUp (
+          EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+          &Key,
+          L"Invalid Configuration, Check value of IpMode or Target Via DHCP!",
+          NULL
+          );
+        return EFI_INVALID_PARAMETER;
+      }
+
+    } else if ((OffSet >= ATTEMPT_CHAR_USER_NAME_VAR_OFFSET) && (OffSet < ATTEMPT_CHAR_SECRET_VAR_OFFSET)) {
+      if (Attempt->AuthenticationType == ISCSI_AUTH_TYPE_CHAP) {
+        UnicodeStrToAsciiStrS (
+          IfrNvData->Keyword[Index].ISCSIChapUsername,
+          Attempt->AuthConfigData.CHAP.CHAPName,
+          ISCSI_CHAP_NAME_STORAGE
+          );
+
+        if (Attempt->SessionConfigData.Enabled != ISCSI_DISABLED) {
+          if (IfrNvData->CHAPName[0] == L'\0') {
+            CreatePopUp (
+              EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+              &Key,
+              L"CHAP Name is invalid!",
+              NULL
+              );
+            return EFI_INVALID_PARAMETER;
+          }
+        }
+      } else {
+        CreatePopUp (
+          EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+          &Key,
+          L"Invalid Configuration, Check value of AuthenticationType!",
+          NULL
+          );
+        return EFI_INVALID_PARAMETER;
+      }
+
+    } else if ((OffSet >= ATTEMPT_CHAR_SECRET_VAR_OFFSET) && (OffSet < ATTEMPT_CHAR_REVERSE_USER_NAME_VAR_OFFSET)) {
+      if (Attempt->AuthenticationType == ISCSI_AUTH_TYPE_CHAP) {
+        UnicodeStrToAsciiStrS (
+          IfrNvData->Keyword[Index].ISCSIChapSecret,
+          Attempt->AuthConfigData.CHAP.CHAPSecret,
+          ISCSI_CHAP_SECRET_STORAGE
+          );
+
+        if (Attempt->SessionConfigData.Enabled != ISCSI_DISABLED) {
+          if (IfrNvData->CHAPSecret[0] == L'\0') {
+            CreatePopUp (
+              EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+              &Key,
+              L"CHAP Secret is invalid!",
+              NULL
+              );
+            return EFI_INVALID_PARAMETER;
+          }
+        }
+      } else {
+        CreatePopUp (
+          EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+          &Key,
+          L"Invalid Configuration, Check value of AuthenticationType!",
+          NULL
+          );
+        return EFI_INVALID_PARAMETER;
+      }
+
+    } else if ((OffSet >= ATTEMPT_CHAR_REVERSE_USER_NAME_VAR_OFFSET) && (OffSet < ATTEMPT_CHAR_REVERSE_SECRET_VAR_OFFSET)) {
+      if (Attempt->AuthConfigData.CHAP.CHAPType == ISCSI_CHAP_MUTUAL) {
+        UnicodeStrToAsciiStrS (
+          IfrNvData->Keyword[Index].ISCSIReverseChapUsername,
+          Attempt->AuthConfigData.CHAP.ReverseCHAPName,
+          ISCSI_CHAP_NAME_STORAGE
+          );
+        if (Attempt->SessionConfigData.Enabled != ISCSI_DISABLED) {
+          if (IfrNvData->ReverseCHAPName[0] == L'\0') {
+            CreatePopUp (
+              EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+              &Key,
+              L"Reverse CHAP Name is invalid!",
+              NULL
+              );
+            return EFI_INVALID_PARAMETER;
+          }
+        }
+      } else {
+        CreatePopUp (
+          EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+          &Key,
+          L"Invalid Configuration, Check value of AuthenticationType or Chap Type!",
+          NULL
+          );
+        return EFI_INVALID_PARAMETER;
+      }
+
+    } else if (OffSet >= ATTEMPT_CHAR_REVERSE_SECRET_VAR_OFFSET) {
+      if (Attempt->AuthConfigData.CHAP.CHAPType == ISCSI_CHAP_MUTUAL) {
+        UnicodeStrToAsciiStrS (
+          IfrNvData->Keyword[Index].ISCSIReverseChapSecret,
+          Attempt->AuthConfigData.CHAP.ReverseCHAPSecret,
+          ISCSI_CHAP_SECRET_STORAGE
+          );
+
+        if (Attempt->SessionConfigData.Enabled != ISCSI_DISABLED) {
+          if (IfrNvData->ReverseCHAPSecret[0] == L'\0') {
+            CreatePopUp (
+              EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+              &Key,
+              L"Reverse CHAP Secret is invalid!",
+              NULL
+              );
+            return EFI_INVALID_PARAMETER;
+          }
+        }
+      } else {
+        CreatePopUp (
+          EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+          &Key,
+          L"Invalid Configuration, Check value of AuthenticationType or Chap Type!",
+          NULL
+          );
+        return EFI_INVALID_PARAMETER;
+      }
+    }
+  }
+
+
+
+  //
+  // Record the user configuration information in NVR.
+  //
+
+  UnicodeSPrint (mPrivate->PortString, (UINTN) ISCSI_NAME_IFR_MAX_SIZE, L"Attempt %d", Attempt->AttemptConfigIndex);
+  return gRT->SetVariable (
+                mPrivate->PortString,
+                &gEfiIScsiInitiatorNameProtocolGuid,
+                ISCSI_CONFIG_VAR_ATTR,
+                sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA),
+                Attempt
+                );
+
+}
+
+/**
+  Create Hii Extend Label OpCode as the start opcode and end opcode. It is
+  a help function.
+
+  @param[in]  StartLabelNumber   The number of start label.
+  @param[out] StartOpCodeHandle  Points to the start opcode handle.
+  @param[out] StartLabel         Points to the created start opcode.
+  @param[out] EndOpCodeHandle    Points to the end opcode handle.
+  @param[out] EndLabel           Points to the created end opcode.
+
+  @retval EFI_OUT_OF_RESOURCES   Do not have sufficient resource to finish this
+                                 operation.
+  @retval EFI_INVALID_PARAMETER  Any input parameter is invalid.
+  @retval EFI_SUCCESS            The operation is completed successfully.
+
+**/
+EFI_STATUS
+IScsiCreateOpCode (
+  IN  UINT16                        StartLabelNumber,
+  OUT VOID                          **StartOpCodeHandle,
+  OUT EFI_IFR_GUID_LABEL            **StartLabel,
+  OUT VOID                          **EndOpCodeHandle,
+  OUT EFI_IFR_GUID_LABEL            **EndLabel
+  )
+{
+  EFI_STATUS                        Status;
+  EFI_IFR_GUID_LABEL                *InternalStartLabel;
+  EFI_IFR_GUID_LABEL                *InternalEndLabel;
+
+  if (StartOpCodeHandle == NULL || StartLabel == NULL || EndOpCodeHandle == NULL || EndLabel == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  *StartOpCodeHandle = NULL;
+  *EndOpCodeHandle   = NULL;
+  Status             = EFI_OUT_OF_RESOURCES;
+
+  //
+  // Initialize the container for dynamic opcodes.
+  //
+  *StartOpCodeHandle = HiiAllocateOpCodeHandle ();
+  if (*StartOpCodeHandle == NULL) {
+    return Status;
+  }
+
+  *EndOpCodeHandle = HiiAllocateOpCodeHandle ();
+  if (*EndOpCodeHandle == NULL) {
+    goto Exit;
+  }
+
+  //
+  // Create Hii Extend Label OpCode as the start opcode.
+  //
+  InternalStartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (
+                                                *StartOpCodeHandle,
+                                                &gEfiIfrTianoGuid,
+                                                NULL,
+                                                sizeof (EFI_IFR_GUID_LABEL)
+                                                );
+  if (InternalStartLabel == NULL) {
+    goto Exit;
+  }
+
+  InternalStartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
+  InternalStartLabel->Number       = StartLabelNumber;
+
+  //
+  // Create Hii Extend Label OpCode as the end opcode.
+  //
+  InternalEndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (
+                                              *EndOpCodeHandle,
+                                              &gEfiIfrTianoGuid,
+                                              NULL,
+                                              sizeof (EFI_IFR_GUID_LABEL)
+                                              );
+  if (InternalEndLabel == NULL) {
+    goto Exit;
+  }
+
+  InternalEndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
+  InternalEndLabel->Number       = LABEL_END;
+
+  *StartLabel = InternalStartLabel;
+  *EndLabel   = InternalEndLabel;
+
+  return EFI_SUCCESS;
+
+Exit:
+
+  if (*StartOpCodeHandle != NULL) {
+    HiiFreeOpCodeHandle (*StartOpCodeHandle);
+  }
+
+  if (*EndOpCodeHandle != NULL) {
+    HiiFreeOpCodeHandle (*EndOpCodeHandle);
+  }
+  return Status;
+}
+
+/**
+  Update the MAIN form to display the configured attempts.
+
+**/
+VOID
+IScsiConfigUpdateAttempt (
+  VOID
+  )
+{
+  LIST_ENTRY                    *Entry;
+  ISCSI_ATTEMPT_CONFIG_NVDATA   *AttemptConfigData;
+  VOID                          *StartOpCodeHandle;
+  EFI_IFR_GUID_LABEL            *StartLabel;
+  VOID                          *EndOpCodeHandle;
+  EFI_IFR_GUID_LABEL            *EndLabel;
+  EFI_STATUS                    Status;
+
+  Status = IScsiCreateOpCode (
+             ATTEMPT_ENTRY_LABEL,
+             &StartOpCodeHandle,
+             &StartLabel,
+             &EndOpCodeHandle,
+             &EndLabel
+             );
+  if (EFI_ERROR (Status)) {
+    return ;
+  }
+
+  NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) {
+    AttemptConfigData = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);
+    if (AttemptConfigData->Actived == ISCSI_ACTIVE_ENABLED) {
+      //
+      // Update Attempt Help Info.
+      //
+      UnicodeSPrint (mPrivate->PortString, (UINTN) ISCSI_NAME_IFR_MAX_SIZE, L"Attempt %d", (UINTN) AttemptConfigData->AttemptConfigIndex);
+      AttemptConfigData->AttemptTitleToken = HiiSetString (
+                                               mCallbackInfo->RegisteredHandle,
+                                               0,
+                                               mPrivate->PortString,
+                                               NULL
+                                               );
+      if (AttemptConfigData->AttemptTitleToken == 0) {
+        return ;
+      }
+
+      HiiCreateGotoOpCode (
+        StartOpCodeHandle,                         // Container for dynamic created opcodes
+        FORMID_ATTEMPT_FORM,                       // Form ID
+        AttemptConfigData->AttemptTitleToken,      // Prompt text
+        AttemptConfigData->AttemptTitleHelpToken,  // Help text
+        EFI_IFR_FLAG_CALLBACK,                     // Question flag
+        (UINT16) (KEY_ATTEMPT_ENTRY_BASE + AttemptConfigData->AttemptConfigIndex)   // Question ID
+        );
+    }
+  }
+
+  HiiUpdateForm (
+    mCallbackInfo->RegisteredHandle, // HII handle
+    &gIScsiConfigGuid,               // Formset GUID
+    FORMID_MAIN_FORM,                // Form ID
+    StartOpCodeHandle,               // Label for where to insert opcodes
+    EndOpCodeHandle                  // Replace data
+  );
+
+  HiiFreeOpCodeHandle (StartOpCodeHandle);
+  HiiFreeOpCodeHandle (EndOpCodeHandle);
+}
+
+/**
+  Callback function when user presses "Add an Attempt".
+
+  @retval EFI_OUT_OF_RESOURCES   Does not have sufficient resources to finish this
+                                 operation.
   @retval EFI_SUCCESS            The operation is completed successfully.
 
 **/
 EFI_STATUS
 IScsiConfigAddAttempt (
@@ -1107,80 +1993,186 @@ Exit:
   HiiFreeOpCodeHandle (EndOpCodeHandle);
   
   return Status;
 }
 
-
 /**
-  Update the MAIN form to display the configured attempts.
+  Add the attempts by keywords.
+
+  @param[in]  AttemptList        The new attempt List will be added.
+
+  @retval EFI_SUCCESS            The operation to add attempt list successfully.
+  @retval EFI_INVALID_PARAMETER  Any parameter is invalid.
+  @retval EFI_NOT_FOUND          Cannot find the corresponding variable.
+  @retval EFI_OUT_OF_RESOURCES   Fail to finish the operation due to lack of
+                                 resources.
 
 **/
-VOID
-IScsiConfigUpdateAttempt (
-  VOID
+EFI_STATUS
+IScsiConfigAddAttemptsByKeywords (
+  IN UINT8                   *AttemptList
   )
 {
-  CHAR16                        AttemptName[ATTEMPT_NAME_MAX_SIZE];
-  LIST_ENTRY                    *Entry;
-  ISCSI_ATTEMPT_CONFIG_NVDATA   *AttemptConfigData;
-  VOID                          *StartOpCodeHandle;
-  EFI_IFR_GUID_LABEL            *StartLabel;
-  VOID                          *EndOpCodeHandle;
-  EFI_IFR_GUID_LABEL            *EndLabel;
-  EFI_STATUS                    Status;
+  UINT8                       Index;
+  UINT8                       Number;
+  UINTN                       TotalNumber;
+  UINT8                       Nic;
+  UINT8                       *AttemptConfigOrder;
+  UINTN                       AttemptConfigOrderSize;
+  UINT8                       *AttemptConfigOrderTmp;
+  ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;
+  ISCSI_NIC_INFO              *NicInfo;
+  CHAR16                      MacString[ISCSI_MAX_MAC_STRING_LEN];
+  CHAR16                      IScsiMode[64];
+  CHAR16                      IpMode[64];
+  EFI_STATUS                  Status;
 
-  Status = IScsiCreateOpCode (
-             ATTEMPT_ENTRY_LABEL,
-             &StartOpCodeHandle,
-             &StartLabel,
-             &EndOpCodeHandle,
-             &EndLabel
-             );
-  if (EFI_ERROR (Status)) {
-    return ;
+  Nic = mPrivate->CurrentNic;
+  NicInfo = IScsiGetNicInfoByIndex (Nic);
+  if (NicInfo == NULL) {
+    return EFI_NOT_FOUND;
   }
 
-  NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) {
-    AttemptConfigData = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);
+  //
+  // The MAC info will be recorded in Config Data.
+  //
+  IScsiMacAddrToStr (
+    &NicInfo->PermanentAddress,
+    NicInfo->HwAddressSize,
+    NicInfo->VlanId,
+    MacString
+    );
+
+  for (Index = 0; Index < PcdGet8 (PcdMaxIScsiAttemptNumber); Index++) {
+    if (AttemptList[Index] == 0) {
+      continue;
+    }
+
+    //
+    // Add the attempt.
+    //
+    Number = AttemptList[Index];
+
+    UnicodeSPrint (
+      mPrivate->PortString,
+      (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
+      L"Attempt %d",
+      Number
+      );
+
+    GetVariable2 (
+           mPrivate->PortString,
+           &gEfiIScsiInitiatorNameProtocolGuid,
+           (VOID**)&AttemptConfigData,
+           NULL
+           );
+    if (AttemptConfigData == NULL || AttemptConfigData->Actived == ISCSI_ACTIVE_ENABLED) {
+      return EFI_INVALID_PARAMETER;
+    }
+
+    AttemptConfigData->Actived = ISCSI_ACTIVE_ENABLED;
+    AttemptConfigData->NicIndex = NicInfo->NicIndex;
+    UnicodeStrToAsciiStrS (MacString, AttemptConfigData->MacString, ISCSI_MAX_MAC_STRING_LEN);
+
+    //
+    // Generate OUI-format ISID based on MAC address.
+    //
+    CopyMem (AttemptConfigData->SessionConfigData.IsId, &NicInfo->PermanentAddress, 6);
+    AttemptConfigData->SessionConfigData.IsId[0] =
+      (UINT8) (AttemptConfigData->SessionConfigData.IsId[0] & 0x3F);
+
+    //
+    // Configure the iSCSI Mode and IpMode to default.
+    // Add Attempt Help Info.
+    //
+    UnicodeSPrint (IScsiMode, 64, L"Disabled");
+    UnicodeSPrint (IpMode, 64, L"IP4");
+    UnicodeSPrint (
+      mPrivate->PortString,
+      (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
+      L"MAC: %s, PFA: Bus %d | Dev %d | Func %d, iSCSI mode: %s, IP version: %s",
+      MacString,
+      NicInfo->BusNumber,
+      NicInfo->DeviceNumber,
+      NicInfo->FunctionNumber,
+      IScsiMode,
+      IpMode
+      );
+
+    AttemptConfigData->AttemptTitleHelpToken = HiiSetString (
+                                                 mCallbackInfo->RegisteredHandle,
+                                                 0,
+                                                 mPrivate->PortString,
+                                                 NULL
+                                                 );
+    if (AttemptConfigData->AttemptTitleHelpToken == 0) {
+      return EFI_OUT_OF_RESOURCES;
+    }
+
+    //
+    // Get current Attempt order and number.
+    //
+    AttemptConfigOrder = IScsiGetVariableAndSize (
+                           L"AttemptOrder",
+                           &gIScsiConfigGuid,
+                           &AttemptConfigOrderSize
+                           );
+    TotalNumber = AttemptConfigOrderSize / sizeof (UINT8);
+    TotalNumber++;
+
+    //
+    // Append the new created attempt order to the end.
+    //
+    AttemptConfigOrderTmp = AllocateZeroPool (TotalNumber * sizeof (UINT8));
+    if (AttemptConfigOrderTmp == NULL) {
+      if (AttemptConfigOrder != NULL) {
+        FreePool (AttemptConfigOrder);
+      }
+      return EFI_OUT_OF_RESOURCES;
+    }
+    if (AttemptConfigOrder != NULL) {
+      CopyMem (AttemptConfigOrderTmp, AttemptConfigOrder, AttemptConfigOrderSize);
+      FreePool (AttemptConfigOrder);
+    }
+
+    AttemptConfigOrderTmp[TotalNumber - 1] = Number;
+    AttemptConfigOrder               = AttemptConfigOrderTmp;
+    AttemptConfigOrderSize           = TotalNumber * sizeof (UINT8);
 
-    AsciiStrToUnicodeStrS (AttemptConfigData->AttemptName, AttemptName, ARRAY_SIZE (AttemptName));
-    UnicodeSPrint (mPrivate->PortString, (UINTN) 128, L"Attempt %s", AttemptName);
-    AttemptConfigData->AttemptTitleToken = HiiSetString (
-                                             mCallbackInfo->RegisteredHandle,
-                                             0,
-                                             mPrivate->PortString,
-                                             NULL
-                                             );
-    if (AttemptConfigData->AttemptTitleToken == 0) {
-      return ;
+    Status = gRT->SetVariable (
+                    L"AttemptOrder",
+                    &gIScsiConfigGuid,
+                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+                    AttemptConfigOrderSize,
+                    AttemptConfigOrder
+                    );
+    FreePool (AttemptConfigOrder);
+    if (EFI_ERROR (Status)) {
+      return Status;
     }
 
-    HiiCreateGotoOpCode (
-      StartOpCodeHandle,                         // Container for dynamic created opcodes
-      FORMID_ATTEMPT_FORM,                       // Form ID
-      AttemptConfigData->AttemptTitleToken,      // Prompt text
-      AttemptConfigData->AttemptTitleHelpToken,  // Help text
-      EFI_IFR_FLAG_CALLBACK,                     // Question flag
-      (UINT16) (KEY_ATTEMPT_ENTRY_BASE + AttemptConfigData->AttemptConfigIndex)   // Question ID
-      );
-  }
+    //
+    // Record the attempt in global link list.
+    //
+    InsertTailList (&mPrivate->AttemptConfigs, &AttemptConfigData->Link);
+    mPrivate->AttemptCount++;
+    UnicodeSPrint (mPrivate->PortString, (UINTN) ISCSI_NAME_IFR_MAX_SIZE, L"Attempt %d", AttemptConfigData->AttemptConfigIndex);
+    gRT->SetVariable (
+           mPrivate->PortString,
+           &gEfiIScsiInitiatorNameProtocolGuid,
+           ISCSI_CONFIG_VAR_ATTR,
+           sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA),
+           AttemptConfigData
+           );
 
-  HiiUpdateForm (
-    mCallbackInfo->RegisteredHandle, // HII handle
-    &gIScsiConfigGuid,               // Formset GUID
-    FORMID_MAIN_FORM,                // Form ID
-    StartOpCodeHandle,               // Label for where to insert opcodes
-    EndOpCodeHandle                  // Replace data
-  );    
+  }
 
-  HiiFreeOpCodeHandle (StartOpCodeHandle);
-  HiiFreeOpCodeHandle (EndOpCodeHandle);
+  return EFI_SUCCESS;
 }
 
-
 /**
-  Callback function when user presses "Commit Changes and Exit" in Delete Attempts.
+  Callback function when user presses "Commit Changes and Exit" in Delete Attempts or Delete Attempts by Keyword.
 
   @param[in]  IfrNvData          The IFR NV data.
 
   @retval EFI_NOT_FOUND          Cannot find the corresponding variable.
   @retval EFI_SUCCESS            The operation is completed successfully.
@@ -1193,23 +2185,26 @@ IScsiConfigUpdateAttempt (
 EFI_STATUS
 IScsiConfigDeleteAttempts (
   IN ISCSI_CONFIG_IFR_NVDATA  *IfrNvData
   )
 {
-  EFI_STATUS                  Status;
-  UINTN                       Index;
-  UINTN                       NewIndex;
-  ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;
-  UINT8                       *AttemptConfigOrder;
-  UINTN                       AttemptConfigOrderSize;
-  UINT8                       *AttemptNewOrder;
-  UINT32                      Attribute;
-  UINTN                       Total;
-  UINTN                       NewTotal;
-  LIST_ENTRY                  *Entry;
-  LIST_ENTRY                  *NextEntry;
-  CHAR16                      MacString[ISCSI_MAX_MAC_STRING_LEN];
+  EFI_STATUS                    Status;
+  UINTN                         Index;
+  UINTN                         NewIndex;
+  ISCSI_ATTEMPT_CONFIG_NVDATA   *AttemptConfigData;
+  UINT8                         *AttemptConfigOrder;
+  UINTN                         AttemptConfigOrderSize;
+  UINT8                         *AttemptNewOrder;
+  UINT8                         AttemptConfigIndex;
+  UINT32                        Attribute;
+  UINTN                         Total;
+  UINTN                         NewTotal;
+  LIST_ENTRY                    *Entry;
+  LIST_ENTRY                    *NextEntry;
+  ISCSI_SESSION_CONFIG_NVDATA   *ConfigData;
+
+  Index     = 0;
 
   AttemptConfigOrder = IScsiGetVariableAndSize (
                          L"AttemptOrder",
                          &gIScsiConfigGuid,
                          &AttemptConfigOrderSize
@@ -1224,11 +2219,10 @@ IScsiConfigDeleteAttempts (
     goto Error;
   }
 
   Total    = AttemptConfigOrderSize / sizeof (UINT8);
   NewTotal = Total;
-  Index    = 0;
 
   NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &mPrivate->AttemptConfigs) {
     if (IfrNvData->DeleteAttemptList[Index] == 0) {
       Index++;
       continue;
@@ -1269,26 +2263,48 @@ IScsiConfigDeleteAttempts (
       }
 
       mPrivate->SinglePathCount--;
     }
 
-    AsciiStrToUnicodeStrS (AttemptConfigData->MacString, MacString, ARRAY_SIZE (MacString));
+    AttemptConfigIndex = AttemptConfigData->AttemptConfigIndex;
+    FreePool (AttemptConfigData);
+
+    //
+    // Create a new Attempt
+    //
+    AttemptConfigData = AllocateZeroPool (sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA));
+    if (AttemptConfigData == NULL) {
+      return EFI_OUT_OF_RESOURCES;
+    }
+    ConfigData                    = &AttemptConfigData->SessionConfigData;
+    ConfigData->TargetPort        = ISCSI_WELL_KNOWN_PORT;
+    ConfigData->ConnectTimeout    = CONNECT_DEFAULT_TIMEOUT;
+    ConfigData->ConnectRetryCount = CONNECT_MIN_RETRY;
+
+    AttemptConfigData->AuthenticationType           = ISCSI_AUTH_TYPE_CHAP;
+    AttemptConfigData->AuthConfigData.CHAP.CHAPType = ISCSI_CHAP_UNI;
+    //
+    // Configure the Attempt index and set variable.
+    //
+    AttemptConfigData->AttemptConfigIndex = AttemptConfigIndex;
 
+    //
+    // Set the attempt name to default.
+    //
     UnicodeSPrint (
       mPrivate->PortString,
-      (UINTN) 128,
-      L"%s%d",
-      MacString,
+      (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
+      L"Attempt %d",
       (UINTN) AttemptConfigData->AttemptConfigIndex
       );
-
+    UnicodeStrToAsciiStrS (mPrivate->PortString, AttemptConfigData->AttemptName, ATTEMPT_NAME_SIZE);
     gRT->SetVariable (
            mPrivate->PortString,
            &gEfiIScsiInitiatorNameProtocolGuid,
-           0,
-           0,
-           NULL
+           ISCSI_CONFIG_VAR_ATTR,
+           sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA),
+           AttemptConfigData
            );
 
     //
     // Mark the attempt order in NVR to be deleted - 0.
     //
@@ -1298,10 +2314,13 @@ IScsiConfigDeleteAttempts (
         break;
       }
     }
 
     NewTotal--;
+    if (mCallbackInfo->Current == AttemptConfigData) {
+      mCallbackInfo->Current = NULL;
+    }
     FreePool (AttemptConfigData);
 
     //
     // Check next Attempt.
     //
@@ -1337,11 +2356,11 @@ Error:
   }
 
   if (AttemptNewOrder != NULL) {
     FreePool (AttemptNewOrder);
   }
-  
+
   return Status;
 }
 
 
 /**
@@ -1536,13 +2555,12 @@ Error:
   }
 
   return Status;
 }
 
-
 /**
-  Callback function when user presses "Commit Changes and Exit" in Change Attempt Order.
+  Callback function when user presses "Commit Changes and Exit" in Change Attempt Order or Change Attempt Order by Keyword.
 
   @param[in]  IfrNvData          The IFR nv data.
 
   @retval EFI_OUT_OF_RESOURCES   Does not have sufficient resources to finish this
                                  operation.
@@ -1654,10 +2672,11 @@ Exit:
   @param[in]  IfrNvData          The IFR nv data.
 
   @retval EFI_OUT_OF_RESOURCES   Does not have sufficient resources to finish this
                                  operation.
   @retval EFI_NOT_FOUND          Cannot find the corresponding variable.
+  @retval EFI_UNSUPPORTED        Can not create more attempts.
   @retval EFI_SUCCESS            The operation is completed successfully.
 
 **/
 EFI_STATUS
 IScsiConfigProcessDefault (
@@ -1665,19 +2684,18 @@ IScsiConfigProcessDefault (
   IN  ISCSI_CONFIG_IFR_NVDATA      *IfrNvData
   )
 {
   BOOLEAN                     NewAttempt;
   ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;
-  ISCSI_SESSION_CONFIG_NVDATA *ConfigData;
   UINT8                       CurrentAttemptConfigIndex;
   ISCSI_NIC_INFO              *NicInfo;
   UINT8                       NicIndex;
   CHAR16                      MacString[ISCSI_MAX_MAC_STRING_LEN];
   UINT8                       *AttemptConfigOrder;
   UINTN                       AttemptConfigOrderSize;
-  UINTN                       TotalNumber;
   UINTN                       Index;
+  EFI_INPUT_KEY               Key;
 
   //
   // Is User creating a new attempt?
   //
   NewAttempt = FALSE;
@@ -1699,80 +2717,63 @@ IScsiConfigProcessDefault (
     //
     // Don't process anything.
     //
     return EFI_SUCCESS;
   }
-  
-  //
-  // Free any attempt that is previously created but not saved to system.
-  //
-  if (mPrivate->NewAttempt != NULL) {
-    FreePool (mPrivate->NewAttempt);
-    mPrivate->NewAttempt = NULL;
-  }
 
   if (NewAttempt) {
     //
     // Determine which NIC user has selected for the new created attempt.
     //
     NicIndex = (UINT8) (KeyValue - KEY_MAC_ENTRY_BASE);
     NicInfo = IScsiGetNicInfoByIndex (NicIndex);
     if (NicInfo == NULL) {
       return EFI_NOT_FOUND;
     }
-    
-    //
-    // Create new attempt.
-    //
-
-    AttemptConfigData = AllocateZeroPool (sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA));
-    if (AttemptConfigData == NULL) {
-      return EFI_OUT_OF_RESOURCES;
-    }
-
-    ConfigData                    = &AttemptConfigData->SessionConfigData;
-    ConfigData->TargetPort        = ISCSI_WELL_KNOWN_PORT;
-    ConfigData->ConnectTimeout    = CONNECT_DEFAULT_TIMEOUT;
-    ConfigData->ConnectRetryCount = CONNECT_MIN_RETRY;
-
-    AttemptConfigData->AuthenticationType           = ISCSI_AUTH_TYPE_CHAP;
-    AttemptConfigData->AuthConfigData.CHAP.CHAPType = ISCSI_CHAP_UNI;
 
     //
-    // Get current order number for this attempt.
+    // Create an attempt following the initialized attempt order.
     //
     AttemptConfigOrder = IScsiGetVariableAndSize (
-                           L"AttemptOrder",
+                           L"InitiatorAttemptOrder",
                            &gIScsiConfigGuid,
                            &AttemptConfigOrderSize
                            );
 
-    TotalNumber = AttemptConfigOrderSize / sizeof (UINT8);
+    if (AttemptConfigOrder != NULL) {
 
-    if (AttemptConfigOrder == NULL) {
-      CurrentAttemptConfigIndex = 1;
-    } else {
-      //
-      // Get the max attempt config index.
-      //
-      CurrentAttemptConfigIndex = AttemptConfigOrder[0];
-      for (Index = 1; Index < TotalNumber; Index++) {
-        if (CurrentAttemptConfigIndex < AttemptConfigOrder[Index]) {
-          CurrentAttemptConfigIndex = AttemptConfigOrder[Index];
+      for (Index = 0; Index < AttemptConfigOrderSize / sizeof (UINT8); Index++) {
+        UnicodeSPrint (
+          mPrivate->PortString,
+          (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
+          L"Attempt %d",
+          (UINTN) AttemptConfigOrder[Index]
+          );
+        GetVariable2 (
+                     mPrivate->PortString,
+                     &gEfiIScsiInitiatorNameProtocolGuid,
+                     (VOID**)&AttemptConfigData,
+                     NULL
+                     );
+        if (AttemptConfigData == NULL || AttemptConfigData->Actived == ISCSI_ACTIVE_ENABLED) {
+          continue;
         }
+
+        break;
       }
 
-      CurrentAttemptConfigIndex++;
+      if (Index > PcdGet8 (PcdMaxIScsiAttemptNumber)) {
+        CreatePopUp (
+          EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+          &Key,
+          L"Can not create more attempts, Please configure the PcdMaxIScsiAttemptNumber if needed!",
+          NULL
+          );
+        return EFI_UNSUPPORTED;
+      }
     }
 
-    TotalNumber++;
-
-    //
-    // Record the mapping between attempt order and attempt's configdata.
-    //
-    AttemptConfigData->AttemptConfigIndex  = CurrentAttemptConfigIndex;
-
     if (AttemptConfigOrder != NULL) {
       FreePool (AttemptConfigOrder);
     }
 
     //
@@ -1785,10 +2786,11 @@ IScsiConfigProcessDefault (
       MacString
       );
 
     UnicodeStrToAsciiStrS (MacString, AttemptConfigData->MacString, sizeof (AttemptConfigData->MacString));
     AttemptConfigData->NicIndex = NicIndex;
+    AttemptConfigData->Actived = ISCSI_ACTIVE_ENABLED;
 
     //
     // Generate OUI-format ISID based on MAC address.
     //
     CopyMem (AttemptConfigData->SessionConfigData.IsId, &NicInfo->PermanentAddress, 6);
@@ -1814,31 +2816,13 @@ IScsiConfigProcessDefault (
                                                   mPrivate->PortString,
                                                   NULL
                                                   );
     if (AttemptConfigData->AttemptTitleHelpToken == 0) {
       FreePool (AttemptConfigData);
-      return EFI_INVALID_PARAMETER;
+      return EFI_OUT_OF_RESOURCES;
     }
 
-    //
-    // Set the attempt name to default.
-    //
-    UnicodeSPrint (
-      mPrivate->PortString,
-      (UINTN) 128,
-      L"%d",
-      (UINTN) AttemptConfigData->AttemptConfigIndex
-      );
-    UnicodeStrToAsciiStrS (mPrivate->PortString, AttemptConfigData->AttemptName, sizeof (AttemptConfigData->AttemptName));
-
-    //
-    // Save the created Attempt temporarily. If user does not save the attempt
-    // by press 'KEY_SAVE_ATTEMPT_CONFIG' later, iSCSI driver would know that
-    // and free resources.
-    //
-    mPrivate->NewAttempt = (VOID *) AttemptConfigData;
-
   } else {
     //
     // Determine which Attempt user has selected to configure.
     // Get the attempt configuration data.
     //
@@ -1979,15 +2963,21 @@ IScsiFormExtractConfig (
   Private = ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This);
   IfrNvData = AllocateZeroPool (sizeof (ISCSI_CONFIG_IFR_NVDATA));
   if (IfrNvData == NULL) {
     return EFI_OUT_OF_RESOURCES;
   }
-  
-  if (Private->Current != NULL) {
+
+
+  if (Private->Current!= NULL) {
     IScsiConvertAttemptConfigDataToIfrNvData (Private->Current, IfrNvData);
   }
 
+  //
+  // Extract all AttemptConfigData to Keyword stroage of IfrNvData.
+  //
+  IScsiConvertAttemptConfigDataToIfrNvDataByKeyword (IfrNvData);
+
   BufferSize    = ISCSI_NAME_MAX_SIZE;
   InitiatorName = (CHAR8 *) AllocateZeroPool (BufferSize);
   if (InitiatorName == NULL) {
     FreePool (IfrNvData);
     return EFI_OUT_OF_RESOURCES;
@@ -2105,10 +3095,30 @@ IScsiFormRouteConfig (
   IN  CONST EFI_HII_CONFIG_ACCESS_PROTOCOL   *This,
   IN  CONST EFI_STRING                       Configuration,
   OUT EFI_STRING                             *Progress
   )
 {
+  EFI_STATUS                       Status;
+  ISCSI_CONFIG_IFR_NVDATA          *IfrNvData;
+  ISCSI_ATTEMPT_CONFIG_NVDATA      *AttemptConfigData;
+  LIST_ENTRY                       *Entry;
+  LIST_ENTRY                       *NextEntry;
+  ISCSI_NIC_INFO                   *NicInfo;
+  EFI_INPUT_KEY                    Key;
+  CHAR16                           MacString[ISCSI_MAX_MAC_STRING_LEN];
+  CHAR8                            *InitiatorName;
+  UINT8                            *AttemptList;
+  UINTN                            BufferSize;
+  UINTN                            OffSet;
+  UINTN                            Index;
+  UINTN                            Index2;
+
+  Index   = 0;
+  Index2  = 0;
+  NicInfo = NULL;
+  AttemptList = NULL;
+
   if (This == NULL || Configuration == NULL || Progress == NULL) {
     return EFI_INVALID_PARAMETER;
   }
 
   //
@@ -2118,14 +3128,184 @@ IScsiFormRouteConfig (
   if (!HiiIsConfigHdrMatch (Configuration, &gIScsiConfigGuid, mVendorStorageName)) {
     *Progress = Configuration;
     return EFI_NOT_FOUND;
   }
 
-  *Progress = Configuration + StrLen (Configuration);
-  return EFI_SUCCESS;
-}
+  IfrNvData = AllocateZeroPool (sizeof (ISCSI_CONFIG_IFR_NVDATA));
+  if (IfrNvData == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  BufferSize    = ISCSI_NAME_MAX_SIZE;
+  InitiatorName = (CHAR8 *) AllocateZeroPool (BufferSize);
+  if (InitiatorName == NULL) {
+    Status = EFI_OUT_OF_RESOURCES;
+    goto Exit;
+  }
+
+  //
+  // Convert <ConfigResp> to buffer data by helper function ConfigToBlock().
+  //
+  BufferSize = sizeof (ISCSI_CONFIG_IFR_NVDATA);
+  Status = gHiiConfigRouting->ConfigToBlock (
+                             gHiiConfigRouting,
+                             Configuration,
+                             (UINT8 *) IfrNvData,
+                             &BufferSize,
+                             Progress
+                             );
+  if (EFI_ERROR (Status)) {
+    goto Exit;
+  }
+
+  if (IfrNvData->InitiatorName[0] != L'\0') {
+    UnicodeStrToAsciiStrS (IfrNvData->InitiatorName, InitiatorName, ISCSI_NAME_MAX_SIZE);
+    BufferSize  = AsciiStrSize (InitiatorName);
+
+    Status      = gIScsiInitiatorName.Set (&gIScsiInitiatorName, &BufferSize, InitiatorName);
+    if (EFI_ERROR (Status)) {
+      CreatePopUp (
+        EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+        &Key,
+        L"Invalid iSCSI Name!",
+        NULL
+        );
+      goto Exit;
+    }
+  } else {
+    Status = gIScsiInitiatorName.Get (&gIScsiInitiatorName, &BufferSize, InitiatorName);
+    if (EFI_ERROR (Status)) {
+      CreatePopUp (
+        EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+        &Key,
+        L"Error: please configure iSCSI initiator name first!",
+        NULL
+        );
+      goto Exit;
+    }
+
+    if (IfrNvData->ISCSIAddAttemptList[0] != L'\0') {
+      Status =IScsiGetAttemptIndexList (IfrNvData->ISCSIAddAttemptList, IfrNvData->AddAttemptList, TRUE);
+      if (EFI_ERROR (Status)) {
+          CreatePopUp (
+            EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+            &Key,
+            L"Error: The add attempt list is invalid",
+            NULL
+            );
+        goto Exit;
+      }
+
+      Status = IScsiConfigAddAttemptsByKeywords (IfrNvData->AddAttemptList);
+      if (EFI_ERROR (Status)) {
+        goto Exit;
+      }
+
+    } else if (IfrNvData->ISCSIDeleteAttemptList[0] != L'\0') {
+      AttemptList =(UINT8 *) AllocateZeroPool ((ISCSI_MAX_ATTEMPTS_NUM + 1) * sizeof (UINT8));
+      if (AttemptList == NULL) {
+        Status = EFI_OUT_OF_RESOURCES;
+        goto Exit;
+      }
+      Status = IScsiGetAttemptIndexList (IfrNvData->ISCSIDeleteAttemptList, AttemptList, FALSE);
+      if (EFI_ERROR (Status)) {
+          CreatePopUp (
+            EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+            &Key,
+            L"Error: The delete attempt list is invalid",
+            NULL
+            );
+        goto Exit;
+      }
+
+      //
+      // Mark the attempt which will be delete in the global list.
+      //
+      NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &mPrivate->AttemptConfigs) {
+        AttemptConfigData = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);
+        while (AttemptList[Index] != 0) {
+          if (AttemptConfigData->AttemptConfigIndex == AttemptList[Index]) {
+            IfrNvData->DeleteAttemptList[Index2] = 1;
+            break;
+          }
+          Index ++;
+        }
+        Index2 ++;
+        Index = 0;
+      }
+
+      Status = IScsiConfigDeleteAttempts (IfrNvData);
+      if (EFI_ERROR (Status)) {
+        goto Exit;
+      }
+
+      FreePool (AttemptList);
+
+    } else if (IfrNvData->ISCSIAttemptOrder[0] != L'\0') {
+      Status = IScsiGetAttemptIndexList (IfrNvData->ISCSIAttemptOrder, IfrNvData->DynamicOrderedList, FALSE);
+      if (EFI_ERROR (Status)) {
+          CreatePopUp (
+            EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+            &Key,
+            L"Error: The new attempt order list is invalid",
+            NULL
+            );
+        goto Exit;
+      }
+
+      Status = IScsiConfigOrderAttempts (IfrNvData);
+      if (EFI_ERROR (Status)) {
+        goto Exit;
+      }
+
+    } else if (IfrNvData->ISCSIMacAddr[0] != L'\0') {
+      NET_LIST_FOR_EACH (Entry, &mPrivate->NicInfoList) {
+        NicInfo = NET_LIST_USER_STRUCT (Entry, ISCSI_NIC_INFO, Link);
+        IScsiMacAddrToStr (
+        &NicInfo->PermanentAddress,
+        NicInfo->HwAddressSize,
+        NicInfo->VlanId,
+        MacString
+        );
+        if (!StrCmp(MacString, IfrNvData->ISCSIMacAddr)) {
+          mPrivate->CurrentNic = NicInfo->NicIndex;
+          break;
+        }
+      }
+
+      if ((NicInfo == NULL) || (NicInfo->NicIndex == 0)) {
+        Status = EFI_NOT_FOUND;
+        goto Exit;
+      }
+
+    } else {
+      Status = IScsiGetValue (Configuration, L"&OFFSET=", &OffSet);
+      if (EFI_ERROR (Status)) {
+        goto Exit;
+      }
+      Status = IScsiConvertlfrNvDataToAttemptConfigDataByKeyword (IfrNvData, OffSet);
+      if (EFI_ERROR (Status)) {
+        goto Exit;
+      }
+    }
+  }
+
+  IScsiConfigUpdateAttempt ();
+
+  Status = EFI_SUCCESS;
+
+Exit:
+  if (InitiatorName != NULL) {
+    FreePool (InitiatorName);
+  }
 
+  if (IfrNvData != NULL) {
+    FreePool (IfrNvData);
+  }
+
+  return Status;
+}
 
 /**
    
   This function is called to provide results data to the driver.
   This data consists of a unique key that is used to identify
@@ -2171,11 +3351,10 @@ IScsiFormCallback (
   EFI_IP_ADDRESS              SubnetMask;
   EFI_IP_ADDRESS              Gateway;
   ISCSI_CONFIG_IFR_NVDATA     *IfrNvData;
   ISCSI_CONFIG_IFR_NVDATA     OldIfrNvData;
   EFI_STATUS                  Status;
-  CHAR16                      AttemptName[ATTEMPT_NAME_SIZE + 4];
   EFI_INPUT_KEY               Key;
 
   if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) || (Action == EFI_BROWSER_ACTION_FORM_CLOSE)) {
     //
     // Do nothing for UEFI OPEN/CLOSE Action
@@ -2286,36 +3465,18 @@ IScsiFormCallback (
           );      
       }
 
       *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
       break;
-    case KEY_ATTEMPT_NAME:
-      if (StrLen (IfrNvData->AttemptName) > ATTEMPT_NAME_SIZE) {
-        CopyMem (AttemptName, IfrNvData->AttemptName, ATTEMPT_NAME_SIZE * sizeof (CHAR16));
-        CopyMem (&AttemptName[ATTEMPT_NAME_SIZE], L"...", 4 * sizeof (CHAR16));
-      } else {
-        CopyMem (
-          AttemptName,
-          IfrNvData->AttemptName,
-          (StrLen (IfrNvData->AttemptName) + 1) * sizeof (CHAR16)
-          );
-      }
-
-      UnicodeStrToAsciiStrS (IfrNvData->AttemptName, Private->Current->AttemptName, sizeof (Private->Current->AttemptName));
-
-      IScsiConfigUpdateAttempt ();
-
-      *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
-      break;
       
     case KEY_SAVE_ATTEMPT_CONFIG:
       Status = IScsiConvertIfrNvDataToAttemptConfigData (IfrNvData, Private->Current);
       if (EFI_ERROR (Status)) {
         break;
       }
 
-      *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
+      *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;
       break;
 
     case KEY_SAVE_ORDER_CHANGES:
       //
       // Sync the Attempt Order to NVR.
@@ -2660,17 +3821,10 @@ IScsiConfigFormUnload (
     mPrivate->NicCount--;
   }
 
   ASSERT (mPrivate->NicCount == 0);
 
-  //
-  // Free attempt is created but not saved to system.
-  //
-  if (mPrivate->NewAttempt != NULL) {
-    FreePool (mPrivate->NewAttempt);
-  }
-
   FreePool (mPrivate);
   mPrivate = NULL;
 
   //
   // Remove HII package list.
diff --git a/NetworkPkg/IScsiDxe/IScsiConfig.h b/NetworkPkg/IScsiDxe/IScsiConfig.h
index daa0d34..042df4b 100644
--- a/NetworkPkg/IScsiDxe/IScsiConfig.h
+++ b/NetworkPkg/IScsiDxe/IScsiConfig.h
@@ -1,10 +1,10 @@
 /** @file
   The header file of functions for configuring or getting the parameters
   relating to iSCSI.
 
-Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
 http://opensource.org/licenses/bsd-license.php
 
@@ -35,15 +35,59 @@ extern ISCSI_FORM_CALLBACK_INFO    *mCallbackInfo;
 #define DYNAMIC_ONE_OF_VAR_OFFSET           VAR_OFFSET  (Enabled)
 #define DYNAMIC_ORDERED_LIST_QUESTION_ID    QUESTION_ID (DynamicOrderedList)
 #define DYNAMIC_ORDERED_LIST_VAR_OFFSET     VAR_OFFSET  (DynamicOrderedList)
 #define ATTEMPT_DEL_QUESTION_ID             QUESTION_ID (DeleteAttemptList)
 #define ATTEMPT_DEL_VAR_OFFSET              VAR_OFFSET  (DeleteAttemptList)
+#define ATTEMPT_ADD_QUESTION_ID             QUESTION_ID (AddAttemptList)
+#define ATTEMPT_ADD_VAR_OFFSET              VAR_OFFSET  (AddAttemptList)
 
 //
-// sizeof (EFI_MAC_ADDRESS) * 3
+// Define QuestionId and OffSet for Keywords.
 //
-#define ISCSI_MAX_MAC_STRING_LEN            96
+#define ATTEMPT_ATTEMPT_NAME_QUESTION_ID             QUESTION_ID (ISCSIAttemptName)
+#define ATTEMPT_ATTEMPT_NAME_VAR_OFFSET              VAR_OFFSET  (ISCSIAttemptName)
+#define ATTEMPT_BOOTENABLE_QUESTION_ID               QUESTION_ID (ISCSIBootEnableList)
+#define ATTEMPT_BOOTENABLE_VAR_OFFSET                VAR_OFFSET  (ISCSIBootEnableList)
+#define ATTEMPT_ADDRESS_TYPE_QUESTION_ID             QUESTION_ID (ISCSIIpAddressTypeList)
+#define ATTEMPT_ADDRESS_TYPE_VAR_OFFSET              VAR_OFFSET  (ISCSIIpAddressTypeList)
+#define ATTEMPT_CONNECT_RETRY_QUESTION_ID            QUESTION_ID (ISCSIConnectRetry)
+#define ATTEMPT_CONNECT_RETRY_VAR_OFFSET             VAR_OFFSET  (ISCSIConnectRetry)
+#define ATTEMPT_CONNECT_TIMEOUT_QUESTION_ID          QUESTION_ID (ISCSIConnectTimeout)
+#define ATTEMPT_CONNECT_TIMEOUT_VAR_OFFSET           VAR_OFFSET  (ISCSIConnectTimeout)
+#define ATTEMPT_ISID_QUESTION_ID                     QUESTION_ID (Keyword->ISCSIISID)
+#define ATTEMPT_ISID_VAR_OFFSET                      VAR_OFFSET  (Keyword->ISCSIISID)
+#define ATTEMPT_INITIATOR_VIA_DHCP_QUESTION_ID       QUESTION_ID (ISCSIInitiatorInfoViaDHCP)
+#define ATTEMPT_INITIATOR_VIA_DHCP_VAR_OFFSET        VAR_OFFSET  (ISCSIInitiatorInfoViaDHCP)
+#define ATTEMPT_INITIATOR_IP_ADDRESS_QUESTION_ID     QUESTION_ID (Keyword->ISCSIInitiatorIpAddress)
+#define ATTEMPT_INITIATOR_IP_ADDRESS_VAR_OFFSET      VAR_OFFSET  (Keyword->ISCSIInitiatorIpAddress)
+#define ATTEMPT_INITIATOR_NET_MASK_QUESTION_ID       QUESTION_ID (Keyword->ISCSIInitiatorNetmask)
+#define ATTEMPT_INITIATOR_NET_MASK_VAR_OFFSET        VAR_OFFSET  (Keyword->ISCSIInitiatorNetmask)
+#define ATTEMPT_INITIATOR_GATE_WAY_QUESTION_ID       QUESTION_ID (Keyword->ISCSIInitiatorGateway)
+#define ATTEMPT_INITIATOR_GATE_WAY_VAR_OFFSET        VAR_OFFSET  (Keyword->ISCSIInitiatorGateway)
+#define ATTEMPT_TARGET_VIA_DHCP_QUESTION_ID          QUESTION_ID (ISCSITargetInfoViaDHCP)
+#define ATTEMPT_TARGET_VIA_DHCP_VAR_OFFSET           VAR_OFFSET  (ISCSITargetInfoViaDHCP)
+#define ATTEMPT_TARGET_NAME_QUESTION_ID              QUESTION_ID (Keyword->ISCSITargetName)
+#define ATTEMPT_TARGET_NAME_VAR_OFFSET               VAR_OFFSET  (Keyword->ISCSITargetName)
+#define ATTEMPT_TARGET_IP_ADDRESS_QUESTION_ID        QUESTION_ID (Keyword->ISCSITargetIpAddress)
+#define ATTEMPT_TARGET_IP_ADDRESS_VAR_OFFSET         VAR_OFFSET  (Keyword->ISCSITargetIpAddress)
+#define ATTEMPT_TARGET_TCP_PORT_QUESTION_ID          QUESTION_ID (ISCSITargetTcpPort)
+#define ATTEMPT_TARGET_TCP_PORT_VAR_OFFSET           VAR_OFFSET  (ISCSITargetTcpPort)
+#define ATTEMPT_LUN_QUESTION_ID                      QUESTION_ID (Keyword->ISCSILUN)
+#define ATTEMPT_LUN_VAR_OFFSET                       VAR_OFFSET  (Keyword->ISCSILUN)
+#define ATTEMPT_AUTHENTICATION_METHOD_QUESTION_ID    QUESTION_ID (ISCSIAuthenticationMethod)
+#define ATTEMPT_AUTHENTICATION_METHOD_VAR_OFFSET     VAR_OFFSET  (ISCSIAuthenticationMethod)
+#define ATTEMPT_CHARTYPE_QUESTION_ID                 QUESTION_ID (ISCSIChapType)
+#define ATTEMPT_CHARTYPE_VAR_OFFSET                  VAR_OFFSET  (ISCSIChapType)
+#define ATTEMPT_CHAR_USER_NAME_QUESTION_ID           QUESTION_ID (Keyword->ISCSIChapUsername)
+#define ATTEMPT_CHAR_USER_NAME_VAR_OFFSET            VAR_OFFSET  (Keyword->ISCSIChapUsername)
+#define ATTEMPT_CHAR_SECRET_QUESTION_ID              QUESTION_ID (Keyword->ISCSIChapSecret)
+#define ATTEMPT_CHAR_SECRET_VAR_OFFSET               VAR_OFFSET  (Keyword->ISCSIChapSecret)
+#define ATTEMPT_CHAR_REVERSE_USER_NAME_QUESTION_ID   QUESTION_ID (Keyword->ISCSIReverseChapUsername)
+#define ATTEMPT_CHAR_REVERSE_USER_NAME_VAR_OFFSET    VAR_OFFSET  (Keyword->ISCSIReverseChapUsername)
+#define ATTEMPT_CHAR_REVERSE_SECRET_QUESTION_ID      QUESTION_ID (Keyword->ISCSIReverseChapSecret)
+#define ATTEMPT_CHAR_REVERSE_SECRET_VAR_OFFSET       VAR_OFFSET  (Keyword->ISCSIReverseChapSecret)
+
 
 #define ISCSI_INITATOR_NAME_VAR_NAME        L"I_NAME"
 
 #define ISCSI_CONFIG_VAR_ATTR               (EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE)
 
@@ -66,21 +110,22 @@ struct _ISCSI_ATTEMPT_CONFIG_NVDATA {
   BOOLEAN                          ValidiBFTPath;
   BOOLEAN                          ValidPath;
   UINT8                            AutoConfigureMode;
   EFI_STRING_ID                    AttemptTitleToken;
   EFI_STRING_ID                    AttemptTitleHelpToken;
-  CHAR8                            AttemptName[ATTEMPT_NAME_MAX_SIZE];
+  CHAR8                            AttemptName[ATTEMPT_NAME_SIZE];
   CHAR8                            MacString[ISCSI_MAX_MAC_STRING_LEN];
   EFI_IP_ADDRESS                   PrimaryDns;
   EFI_IP_ADDRESS                   SecondaryDns;
   EFI_IP_ADDRESS                   DhcpServer;
   ISCSI_SESSION_CONFIG_NVDATA      SessionConfigData;
   UINT8                            AuthenticationType;
   union {
     ISCSI_CHAP_AUTH_CONFIG_NVDATA  CHAP;
   } AuthConfigData;
   BOOLEAN                          AutoConfigureSuccess;
+  UINT8                            Actived;
 };
 
 ///
 /// HII specific Vendor Device Path definition.
 ///
@@ -100,10 +145,35 @@ struct _ISCSI_FORM_CALLBACK_INFO {
   EFI_HII_HANDLE                   RegisteredHandle;
   ISCSI_ATTEMPT_CONFIG_NVDATA      *Current;
 };
 
 /**
+  Create Hii Extend Label OpCode as the start opcode and end opcode. It is
+  a help function.
+
+  @param[in]  StartLabelNumber   The number of start label.
+  @param[out] StartOpCodeHandle  Points to the start opcode handle.
+  @param[out] StartLabel         Points to the created start opcode.
+  @param[out] EndOpCodeHandle    Points to the end opcode handle.
+  @param[out] EndLabel           Points to the created end opcode.
+
+  @retval EFI_OUT_OF_RESOURCES   Do not have sufficient resource to finish this
+                                 operation.
+  @retval EFI_INVALID_PARAMETER  Any input parameter is invalid.
+  @retval EFI_SUCCESS            The operation is completed successfully.
+
+**/
+EFI_STATUS
+IScsiCreateOpCode (
+  IN  UINT16                        StartLabelNumber,
+  OUT VOID                          **StartOpCodeHandle,
+  OUT EFI_IFR_GUID_LABEL            **StartLabel,
+  OUT VOID                          **EndOpCodeHandle,
+  OUT EFI_IFR_GUID_LABEL            **EndLabel
+  );
+
+/**
   Initialize the iSCSI configuration form.
 
   @param[in]  DriverBindingHandle The iSCSI driverbinding handle.
 
   @retval EFI_SUCCESS             The iSCSI configuration form is initialized.
diff --git a/NetworkPkg/IScsiDxe/IScsiConfigNVDataStruc.h b/NetworkPkg/IScsiDxe/IScsiConfigNVDataStruc.h
index 5f22767..cb6e7ac 100644
--- a/NetworkPkg/IScsiDxe/IScsiConfigNVDataStruc.h
+++ b/NetworkPkg/IScsiDxe/IScsiConfigNVDataStruc.h
@@ -24,25 +24,28 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define FORMID_MAC_FORM           2
 #define FORMID_ATTEMPT_FORM       3
 #define FORMID_ORDER_FORM         4
 #define FORMID_DELETE_FORM        5
 
+#define ISCSI_MAX_ATTEMPTS_NUM    FixedPcdGet8 (PcdMaxIScsiAttemptNumber)
+
 #define ISCSI_NAME_IFR_MIN_SIZE   4
 #define ISCSI_NAME_IFR_MAX_SIZE   223
 #define ISCSI_NAME_MAX_SIZE       224
 
-#define ATTEMPT_NAME_MAX_SIZE     96
-#define ATTEMPT_NAME_SIZE         10
+#define ATTEMPT_NAME_LIST_SIZE    96
+#define ATTEMPT_NAME_SIZE         12
 
 #define CONNECT_MIN_RETRY         0
 #define CONNECT_MAX_RETRY         16
 
 #define CONNECT_MIN_TIMEOUT       100
 #define CONNECT_MAX_TIMEOUT       20000
 #define CONNECT_DEFAULT_TIMEOUT   1000
 
-#define ISCSI_MAX_ATTEMPTS_NUM    255
+#define ISCSI_ACTIVE_DISABLED     0
+#define ISCSI_ACTIVE_ENABLED      1
 
 #define ISCSI_DISABLED            0
 #define ISCSI_ENABLED             1
 #define ISCSI_ENABLED_FOR_MPIO    2
 
@@ -65,10 +68,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define IP_MAX_SIZE               39
 #define IP_STR_MAX_SIZE           40
 
 #define LUN_MIN_SIZE              1
 #define LUN_MAX_SIZE              20
+#define ISCSI_LUN_STR_MAX_LEN     21
 
 #define ISCSI_CHAP_UNI            0
 #define ISCSI_CHAP_MUTUAL         1
 
 #define TARGET_PORT_MIN_NUM       0
@@ -110,21 +114,22 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define KEY_DEVICE_ENTRY_BASE     0x1000
 #define KEY_MAC_ENTRY_BASE        0x2000
 #define MAC_ENTRY_LABEL           0x3000
 #define ORDER_ENTRY_LABEL         0x4000
 #define DELETE_ENTRY_LABEL        0x5000
+#define KEYWORD_ENTRY_LABEL       0x6000
 #define CONFIG_OPTION_OFFSET      0x9000
 
-#define ISCSI_LUN_STR_MAX_LEN     21
 #define ISCSI_CHAP_SECRET_MIN_LEN 12
 #define ISCSI_CHAP_SECRET_MAX_LEN 16
 //
 // ISCSI_CHAP_SECRET_STORAGE = ISCSI_CHAP_SECRET_MAX_LEN + sizeof (NULL-Terminator)
 //
-#define ISCSI_CHAP_SECRET_STORAGE 17
-#define ISCSI_CHAP_NAME_MAX_LEN   126
-#define ISCSI_CHAP_NAME_STORAGE   127
+#define ISCSI_CHAP_SECRET_STORAGE  17
+
+#define ISCSI_CHAP_NAME_MAX_LEN    126
+#define ISCSI_CHAP_NAME_STORAGE    127
 
 #define KERBEROS_SECRET_MIN_LEN   12
 #define KERBEROS_SECRET_MAX_LEN   16
 #define KERBEROS_SECRET_STORAGE   17
 #define KERBEROS_NAME_MAX_LEN     96
@@ -133,21 +138,43 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 
 #define ISID_CONFIGURABLE_MIN_LEN 6
 #define ISID_CONFIGURABLE_MAX_LEN 12
 #define ISID_CONFIGURABLE_STORAGE 13
 
+//
+// sizeof (EFI_MAC_ADDRESS) * 3
+//
+#define ISCSI_MAX_MAC_STRING_LEN            96
+
 ///
 /// Macro used for target Url.
 ///
 #define ISCSI_TARGET_URI_MIN_SIZE     0
 #define ISCSI_TARGET_URI_MAX_SIZE     255
 
 #pragma pack(1)
+
+//
+// Used by keyword.
+//
+typedef struct {
+  CHAR16  ISCSIISID[ISID_CONFIGURABLE_STORAGE];
+  CHAR16  ISCSIInitiatorIpAddress[IP4_STR_MAX_SIZE];
+  CHAR16  ISCSIInitiatorNetmask[IP4_STR_MAX_SIZE];
+  CHAR16  ISCSIInitiatorGateway[IP4_STR_MAX_SIZE];
+  CHAR16  ISCSITargetName[ISCSI_NAME_MAX_SIZE];
+  CHAR16  ISCSITargetIpAddress[IP_STR_MAX_SIZE];
+  CHAR16  ISCSILUN[ISCSI_LUN_STR_MAX_LEN];
+  CHAR16  ISCSIChapUsername[ISCSI_CHAP_NAME_STORAGE];
+  CHAR16  ISCSIChapSecret[ISCSI_CHAP_SECRET_STORAGE];
+  CHAR16  ISCSIReverseChapUsername[ISCSI_CHAP_NAME_STORAGE];
+  CHAR16  ISCSIReverseChapSecret[ISCSI_CHAP_SECRET_STORAGE];
+} KEYWORD_STR;
+
 typedef struct _ISCSI_CONFIG_IFR_NVDATA {
   CHAR16  InitiatorName[ISCSI_NAME_MAX_SIZE];
-  CHAR16  AttemptName[ATTEMPT_NAME_MAX_SIZE];
-
+  CHAR16  AttemptName[ATTEMPT_NAME_SIZE];
   UINT8   Enabled;
   UINT8   IpMode;
 
   UINT8   ConnectRetryCount;
   UINT8   Padding1;
@@ -181,11 +208,31 @@ typedef struct _ISCSI_CONFIG_IFR_NVDATA {
   CHAR16  KerberosKDCIp[IP_STR_MAX_SIZE];
   UINT16  KerberosKDCPort;
 
   UINT8   DynamicOrderedList[ISCSI_MAX_ATTEMPTS_NUM];
   UINT8   DeleteAttemptList[ISCSI_MAX_ATTEMPTS_NUM];
-
+  UINT8   AddAttemptList[ISCSI_MAX_ATTEMPTS_NUM];
   CHAR16  IsId[ISID_CONFIGURABLE_STORAGE];
+
+  //
+  // This will be used by keywords.
+  //
+  CHAR16  ISCSIMacAddr[ISCSI_MAX_MAC_STRING_LEN];
+  CHAR16  ISCSIAttemptOrder[ATTEMPT_NAME_LIST_SIZE];
+  CHAR16  ISCSIAddAttemptList[ATTEMPT_NAME_LIST_SIZE];
+  CHAR16  ISCSIDeleteAttemptList[ATTEMPT_NAME_LIST_SIZE];
+  CHAR16  ISCSIDisplayAttemptList[ATTEMPT_NAME_LIST_SIZE];
+  CHAR16  ISCSIAttemptName[ATTEMPT_NAME_LIST_SIZE];
+  UINT8   ISCSIBootEnableList[ISCSI_MAX_ATTEMPTS_NUM];
+  UINT8   ISCSIIpAddressTypeList[ISCSI_MAX_ATTEMPTS_NUM];
+  UINT8   ISCSIConnectRetry[ISCSI_MAX_ATTEMPTS_NUM];
+  UINT16  ISCSIConnectTimeout[ISCSI_MAX_ATTEMPTS_NUM];
+  UINT8   ISCSIInitiatorInfoViaDHCP[ISCSI_MAX_ATTEMPTS_NUM];
+  UINT8   ISCSITargetInfoViaDHCP[ISCSI_MAX_ATTEMPTS_NUM];
+  UINT16  ISCSITargetTcpPort[ISCSI_MAX_ATTEMPTS_NUM];
+  UINT8   ISCSIAuthenticationMethod[ISCSI_MAX_ATTEMPTS_NUM];
+  UINT8   ISCSIChapType[ISCSI_MAX_ATTEMPTS_NUM];
+  KEYWORD_STR Keyword[ISCSI_MAX_ATTEMPTS_NUM];
 } ISCSI_CONFIG_IFR_NVDATA;
 #pragma pack()
 
 #endif
diff --git a/NetworkPkg/IScsiDxe/IScsiConfigStrings.uni b/NetworkPkg/IScsiDxe/IScsiConfigStrings.uni
index 11e8b09..7952258 100644
--- a/NetworkPkg/IScsiDxe/IScsiConfigStrings.uni
+++ b/NetworkPkg/IScsiDxe/IScsiConfigStrings.uni
@@ -10,28 +10,30 @@
 // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 //
 // Module Name:
 //
 //   IScsiConfigStrings.uni
-// 
+//
 // Abstract:
-// 
+//
 //   String definitions for iSCSI configuration.
-// 
+//
 // Revision History:
-// 
+//
 // --*/
 
 /=#
 
 #langdef en-US "English"
+#langdef x-UEFI-ns "UefiNameSpace"
 
 #string STR_ISCSI_CONFIG_FORM_TITLE     #language en-US "iSCSI Configuration"  
 #string STR_ISCSI_CONFIG_FORM_HELP      #language en-US "Configure the iSCSI parameters."   
 #string STR_ISCSI_MAIN_FORM_TITLE       #language en-US "iSCSI Configuration"
 #string STR_ISCSI_MAC_FORM_TITLE        #language en-US "MAC Selection"
 #string STR_ISCSI_CONFIG_INIT_NAME      #language en-US "iSCSI Initiator Name"
+                                        #language x-UEFI-ns "iSCSIInitiatorName"
 #string STR_ISCSI_CONFIG_INIT_NAME_HELP #language en-US "The worldwide unique name of iSCSI Initiator. Only IQN format is accepted."
 #string STR_ISCSI_ATTEMPT_NAME          #language en-US "iSCSI Attempt Name"
 #string STR_ISCSI_ATTEMPT_NAME_HELP     #language en-US "The human name defined for this attempt."
 #string STR_ISCSI_CONFIG_RETRY          #language en-US "Connection Retry Count"
 #string STR_ISCSI_CONFIG_RETRY_HELP     #language en-US "The minimum value is 0 and the maximum is 16. 0 means no retry."
@@ -66,11 +68,11 @@
 #string STR_ISCSI_TARGET_ADDRESS        #language en-US "  Target Address"
 #string STR_ISCSI_TARGET_ADDRESS_HELP   #language en-US "Enter Target address in IPv4,IPv6 or URL format.You need to configure DNS server address in advance if input a URL string."
 #string STR_ISCSI_TARGET_PORT           #language en-US "  Target Port"
 #string STR_ISCSI_BOOT_LUN              #language en-US "  Boot LUN"
 #string STR_ISCSI_BOOT_LUN_HELP         #language en-US "Hexadecimal representation of the LU number. Examples are: 4752-3A4F-6b7e-2F99, 6734-9-156f-127, 4186-9"
-#string STR_ISCSI_ENABLE_DHCP           #language en-US "Enable DHCP"         
+#string STR_ISCSI_ENABLE_DHCP           #language en-US "Enable DHCP"
 #string STR_ISCSI_ENABLE_DHCP_ON_TARGET #language en-US "Get target info via DHCP"
 #string STR_CHAP_TYPE_PROMPT            #language en-US "  CHAP Type"
 #string STR_CHAP_TYPE_HELP              #language en-US "None, One way CHAP or mutual CHAP"
 #string STR_CHAP_TYPE_UNI               #language en-US "One way"
 #string STR_CHAP_TYPE_MUTUAL            #language en-US "Mutual"
@@ -81,11 +83,19 @@
 #string STR_ISCSI_REVERSE_CHAP_SECRET   #language en-US "    Reverse CHAP Secret"
 #string STR_RETURN_MAIN_FORM            #language en-US "Back to Previous Page"
 #string STR_SAVE_CHANGES                #language en-US "Save Changes"
 #string STR_SAVE_CHANGES_HELP           #language en-US "Must reboot system manually for changes to take place."
 #string STR_NULL                        #language en-US ""
-#string STR_SAVE_AND_EXIT               #language en-US "Commit Changes and Exit"                                      
-#string STR_NO_SAVE_AND_EXIT            #language en-US "Discard Changes and Exit"                                       
+#string STR_SAVE_AND_EXIT               #language en-US "Commit Changes and Exit"
+#string STR_NO_SAVE_AND_EXIT            #language en-US "Discard Changes and Exit"
 #string STR_ISCSI_CONFIG_ISID           #language en-US "ISID"
 #string STR_ISCSI_CONFIG_ISID_HELP      #language en-US "OUI-format ISID in 6 bytes, default value are derived from MAC address. Only last 3 bytes are configurable. Example: update 0ABBCCDDEEFF to 0ABBCCF07901 by input F07901."
-
-  
\ No newline at end of file
+#string STR_ISCSI_MAC_PROMPT            #language en-US "Configure the mac address for the attempt"
+                                        #language x-UEFI-ns "iSCSIMacAddr"
+#string STR_ISCSI_ADD_ATTEMPTS          #language en-US "Add Attempts"
+                                        #language x-UEFI-ns "iSCSIAddAttempts"
+#string STR_ISCSI_DELETE_ATTEMPTS       #language en-US "Delete Attempts"
+                                        #language x-UEFI-ns "iSCSIDeleteAttempts"
+#string STR_ISCSI_DISPLAY_ATTEMPTS      #language en-US "Display Attempts"
+                                        #language x-UEFI-ns "iSCSIDisplayAttemptList"
+#string STR_ISCSI_ATTEMPT_ORDER         #language en-US "New Attempt Order"
+                                        #language x-UEFI-ns "iSCSIAttemptOrder"
diff --git a/NetworkPkg/IScsiDxe/IScsiConfigVfr.vfr b/NetworkPkg/IScsiDxe/IScsiConfigVfr.vfr
index c469a78..d401419 100644
--- a/NetworkPkg/IScsiDxe/IScsiConfigVfr.vfr
+++ b/NetworkPkg/IScsiDxe/IScsiConfigVfr.vfr
@@ -119,14 +119,14 @@ formset
     title  = STRING_TOKEN(STR_ISCSI_ATTEMPT_FORM_TITLE);
 
     string  varid   = ISCSI_CONFIG_IFR_NVDATA.AttemptName,
             prompt  = STRING_TOKEN(STR_ISCSI_ATTEMPT_NAME),
             help    = STRING_TOKEN(STR_ISCSI_ATTEMPT_NAME_HELP),
-            flags   = INTERACTIVE,
+            flags   = READ_ONLY,
             key     = KEY_ATTEMPT_NAME,
             minsize = 0,
-            maxsize = ATTEMPT_NAME_MAX_SIZE,
+            maxsize = ATTEMPT_NAME_SIZE,
     endstring;
 
     subtitle text = STRING_TOKEN(STR_NULL);
 
     oneof varid  = ISCSI_CONFIG_IFR_NVDATA.Enabled,
@@ -340,10 +340,52 @@ formset
             maxsize  = ISCSI_CHAP_SECRET_MAX_LEN,
     endstring;
 
     endif;
 
+    suppressif TRUE;
+
+    string  varid   = ISCSI_CONFIG_IFR_NVDATA.ISCSIMacAddr,
+            prompt  = STRING_TOKEN(STR_ISCSI_MAC_PROMPT),
+            help    = STRING_TOKEN(STR_ISCSI_MAC_PROMPT),
+            minsize = 0,
+            maxsize = ISCSI_MAX_MAC_STRING_LEN,
+    endstring;
+
+    string  varid   = ISCSI_CONFIG_IFR_NVDATA.ISCSIAttemptOrder,
+            prompt  = STRING_TOKEN(STR_ISCSI_ATTEMPT_ORDER),
+            help    = STRING_TOKEN(STR_ISCSI_ATTEMPT_ORDER),
+            minsize = 0,
+            maxsize = ATTEMPT_NAME_LIST_SIZE,
+    endstring;
+
+    string  varid   = ISCSI_CONFIG_IFR_NVDATA.ISCSIAddAttemptList,
+            prompt  = STRING_TOKEN(STR_ISCSI_ADD_ATTEMPTS),
+            help    = STRING_TOKEN(STR_ISCSI_ADD_ATTEMPTS),
+            minsize = 0,
+            maxsize = ATTEMPT_NAME_LIST_SIZE,
+    endstring;
+
+    string  varid   = ISCSI_CONFIG_IFR_NVDATA.ISCSIDeleteAttemptList,
+            prompt  = STRING_TOKEN(STR_ISCSI_DELETE_ATTEMPTS),
+            help    = STRING_TOKEN(STR_ISCSI_DELETE_ATTEMPTS),
+            minsize = 0,
+            maxsize = ATTEMPT_NAME_LIST_SIZE,
+    endstring;
+
+    string  varid   = ISCSI_CONFIG_IFR_NVDATA.ISCSIDisplayAttemptList,
+            prompt  = STRING_TOKEN(STR_ISCSI_DISPLAY_ATTEMPTS),
+            help    = STRING_TOKEN(STR_ISCSI_DISPLAY_ATTEMPTS),
+            flags   = READ_ONLY,
+            minsize = 0,
+            maxsize = ATTEMPT_NAME_LIST_SIZE,
+    endstring;
+
+    label KEYWORD_ENTRY_LABEL;
+    label LABEL_END;
+    endif;
+
     subtitle text = STRING_TOKEN(STR_NULL);
 
     text
       help   = STRING_TOKEN (STR_SAVE_CHANGES_HELP),
       text   = STRING_TOKEN (STR_SAVE_CHANGES),
diff --git a/NetworkPkg/IScsiDxe/IScsiDriver.c b/NetworkPkg/IScsiDxe/IScsiDriver.c
index 59f387f..4f9c90b 100644
--- a/NetworkPkg/IScsiDxe/IScsiDriver.c
+++ b/NetworkPkg/IScsiDxe/IScsiDriver.c
@@ -371,11 +371,10 @@ IScsiStart (
   EFI_HANDLE                      *HandleBuffer;
   UINTN                           NumberOfHandles;
   EFI_DEVICE_PATH_PROTOCOL        *DevicePath;
   EFI_GUID                        *IScsiPrivateGuid;
   EFI_GUID                        *TcpServiceBindingGuid;
-  CHAR16                          MacString[ISCSI_MAX_MAC_STRING_LEN];
   BOOLEAN                         NeedUpdate;
   VOID                            *Interface;
   EFI_GUID                        *ProtocolGuid;
   UINT8                           NetworkBootPolicy;
   ISCSI_SESSION_CONFIG_NVDATA     *NvData;
@@ -695,16 +694,14 @@ IScsiStart (
 
     Session->Private    = Private;
     Session->ConfigData = AttemptConfigData;
     Session->AuthType   = AttemptConfigData->AuthenticationType;
 
-    AsciiStrToUnicodeStrS (AttemptConfigData->MacString, MacString, ARRAY_SIZE (MacString));
     UnicodeSPrint (
       mPrivate->PortString,
       (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
-      L"%s%d",
-      MacString,
+      L"Attempt %d",
       (UINTN) AttemptConfigData->AttemptConfigIndex
       );
 
     if (Session->AuthType == ISCSI_AUTH_TYPE_CHAP) {
       Session->AuthData.CHAP.AuthConfig = &AttemptConfigData->AuthConfigData.CHAP;
@@ -1802,10 +1799,26 @@ IScsiDriverEntryPoint (
   if (EFI_ERROR (Status)) {
     goto Error4;
   }
 
   //
+  // Create the Maxmum Attempts.
+  //
+  Status = IScsiCreateAttempts (PcdGet8 (PcdMaxIScsiAttemptNumber));
+  if (EFI_ERROR (Status)) {
+    goto Error5;
+  }
+
+  //
+  // Creat Keywords for all the Attempts.
+  //
+  Status = IScsiCreateKeywords (PcdGet8 (PcdMaxIScsiAttemptNumber));
+  if (EFI_ERROR (Status)) {
+    goto Error5;
+  }
+
+  //
   // There should be only one EFI_AUTHENTICATION_INFO_PROTOCOL. If already exists,
   // do not produce the protocol instance.
   //
   Status = gBS->LocateProtocol (
                   &gEfiAuthenticationInfoProtocolGuid,
@@ -1818,19 +1831,22 @@ IScsiDriverEntryPoint (
                     &gEfiAuthenticationInfoProtocolGuid,
                     EFI_NATIVE_INTERFACE,
                     &gIScsiAuthenticationInfo
                     );
     if (EFI_ERROR (Status)) {
-      goto Error5;
+      goto Error6;
     }    
   }
 
   return EFI_SUCCESS;
 
-Error5:
+Error6:
   IScsiConfigFormUnload (gIScsiIp4DriverBinding.DriverBindingHandle);
 
+Error5:
+  IScsiCleanAttemptVariable ();
+
 Error4:
   FreePool (mPrivate);
 
 Error3:
   gBS->UninstallMultipleProtocolInterfaces (
diff --git a/NetworkPkg/IScsiDxe/IScsiDriver.h b/NetworkPkg/IScsiDxe/IScsiDriver.h
index 7bfa07f..6c6e11b 100644
--- a/NetworkPkg/IScsiDxe/IScsiDriver.h
+++ b/NetworkPkg/IScsiDxe/IScsiDriver.h
@@ -1,9 +1,9 @@
 /** @file
   The header file of IScsiDriver.c.
 
-Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
 (C) Copyright 2017 Hewlett Packard Enterprise Development LP<BR>
 
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -66,11 +66,10 @@ typedef struct {
   UINT8           BootSelectedIndex;
   UINT8           AttemptCount;
   LIST_ENTRY      AttemptConfigs;       // User configured Attempt list.
   CHAR8           InitiatorName[ISCSI_NAME_MAX_SIZE];
   UINTN           InitiatorNameLength;
-  VOID            *NewAttempt;          // Attempt is created but not saved.
 } ISCSI_PRIVATE_DATA;
 
 extern ISCSI_PRIVATE_DATA                 *mPrivate;
 
 typedef struct {
diff --git a/NetworkPkg/IScsiDxe/IScsiDxe.inf b/NetworkPkg/IScsiDxe/IScsiDxe.inf
index 699ffd1..922f69e 100644
--- a/NetworkPkg/IScsiDxe/IScsiDxe.inf
+++ b/NetworkPkg/IScsiDxe/IScsiDxe.inf
@@ -126,17 +126,20 @@
   gEfiAcpi20TableGuid                           ## SOMETIMES_CONSUMES ## SystemTable
   gEfiAdapterInfoNetworkBootGuid                ## SOMETIMES_CONSUMES ## UNDEFINED
   
   ## SOMETIMES_PRODUCES ## Variable:L"AttemptOrder"
   ## SOMETIMES_CONSUMES ## Variable:L"AttemptOrder"
+  ## SOMETIMES_PRODUCES ## Variable:L"InitiatorAttemptOrder"
+  ## SOMETIMES_CONSUMES ## Variable:L"InitiatorAttemptOrder"
   ## SOMETIMES_CONSUMES ## UNDEFINED # HiiIsConfigHdrMatch   mVendorStorageName
   ## SOMETIMES_PRODUCES ## UNDEFINED # HiiConstructConfigHdr mVendorStorageName
   ## SOMETIMES_PRODUCES ## UNDEFINED # HiiGetBrowserData     mVendorStorageName
   ## SOMETIMES_CONSUMES ## UNDEFINED # HiiSetBrowserData     mVendorStorageName
   ## SOMETIMES_CONSUMES ## HII
   gIScsiConfigGuid
 
 [Pcd]
   gEfiNetworkPkgTokenSpaceGuid.PcdIScsiAIPNetworkBootPolicy ## CONSUMES
-  
+  gEfiNetworkPkgTokenSpaceGuid.PcdMaxIScsiAttemptNumber     ## CONSUMES
+
 [UserExtensions.TianoCore."ExtraFiles"]
   IScsiDxeExtra.uni
diff --git a/NetworkPkg/IScsiDxe/IScsiMisc.c b/NetworkPkg/IScsiDxe/IScsiMisc.c
index e8e8f9c..1cdd4fe 100644
--- a/NetworkPkg/IScsiDxe/IScsiMisc.c
+++ b/NetworkPkg/IScsiDxe/IScsiMisc.c
@@ -641,21 +641,790 @@ IScsiRemoveNic (
 
       FreePool (AttemptConfigData);
     }
   }
 
-  //
-  // Free attempt is created but not saved to system.
-  //
-  if (mPrivate->NewAttempt != NULL) {
-    FreePool (mPrivate->NewAttempt);
-    mPrivate->NewAttempt = NULL;
+  return EFI_SUCCESS;
+}
+
+/**
+  Create and initialize the Attempts.
+
+  @param[in]  AttemptNum          The number of Attempts will be created.
+
+  @retval EFI_SUCCESS             The Attempts have been created successfully.
+  @retval Others                  Failed to create the Attempt.
+
+**/
+EFI_STATUS
+IScsiCreateAttempts (
+  IN UINTN            AttemptNum
+)
+{
+  ISCSI_ATTEMPT_CONFIG_NVDATA   *AttemptConfigData;
+  ISCSI_SESSION_CONFIG_NVDATA   *ConfigData;
+  UINT8                         *AttemptConfigOrder;
+  UINTN                         AttemptConfigOrderSize;
+  UINT8                         *AttemptOrderTmp;
+  UINTN                         TotalNumber;
+  UINT8                         Index;
+  EFI_STATUS                    Status;
+
+  for (Index = 1; Index <= AttemptNum; Index ++) {
+    //
+    // Get the initialized attempt order. This is used to essure creating attempts by order.
+    //
+    AttemptConfigOrder = IScsiGetVariableAndSize (
+                           L"InitiatorAttemptOrder",
+                           &gIScsiConfigGuid,
+                           &AttemptConfigOrderSize
+                           );
+    TotalNumber = AttemptConfigOrderSize / sizeof (UINT8);
+    if (TotalNumber == AttemptNum) {
+      Status = EFI_SUCCESS;
+      break;
+    }
+    TotalNumber++;
+
+    //
+    // Append the new created attempt to the end.
+    //
+    AttemptOrderTmp = AllocateZeroPool (TotalNumber * sizeof (UINT8));
+    if (AttemptOrderTmp == NULL) {
+      if (AttemptConfigOrder != NULL) {
+        FreePool (AttemptConfigOrder);
+      }
+      return EFI_OUT_OF_RESOURCES;
+    }
+
+    if (AttemptConfigOrder != NULL) {
+      CopyMem (AttemptOrderTmp, AttemptConfigOrder, AttemptConfigOrderSize);
+      FreePool (AttemptConfigOrder);
+    }
+
+    AttemptOrderTmp[TotalNumber - 1] = Index;
+    AttemptConfigOrder               = AttemptOrderTmp;
+    AttemptConfigOrderSize           = TotalNumber * sizeof (UINT8);
+
+    Status = gRT->SetVariable (
+                    L"InitiatorAttemptOrder",
+                    &gIScsiConfigGuid,
+                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+                    AttemptConfigOrderSize,
+                    AttemptConfigOrder
+                    );
+    FreePool (AttemptConfigOrder);
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
+
+    //
+    // Create new Attempt
+    //
+    AttemptConfigData = AllocateZeroPool (sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA));
+    if (AttemptConfigData == NULL) {
+      return EFI_OUT_OF_RESOURCES;
+    }
+    ConfigData                    = &AttemptConfigData->SessionConfigData;
+    ConfigData->TargetPort        = ISCSI_WELL_KNOWN_PORT;
+    ConfigData->ConnectTimeout    = CONNECT_DEFAULT_TIMEOUT;
+    ConfigData->ConnectRetryCount = CONNECT_MIN_RETRY;
+
+    AttemptConfigData->AuthenticationType           = ISCSI_AUTH_TYPE_CHAP;
+    AttemptConfigData->AuthConfigData.CHAP.CHAPType = ISCSI_CHAP_UNI;
+    //
+    // Configure the Attempt index and set variable.
+    //
+    AttemptConfigData->AttemptConfigIndex = Index;
+
+    //
+    // Set the attempt name according to the order.
+    //
+    UnicodeSPrint (
+      mPrivate->PortString,
+      (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
+      L"Attempt %d",
+      (UINTN) AttemptConfigData->AttemptConfigIndex
+      );
+    UnicodeStrToAsciiStrS (mPrivate->PortString, AttemptConfigData->AttemptName, ATTEMPT_NAME_SIZE);
+
+    Status = gRT->SetVariable (
+                    mPrivate->PortString,
+                    &gEfiIScsiInitiatorNameProtocolGuid,
+                    ISCSI_CONFIG_VAR_ATTR,
+                    sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA),
+                    AttemptConfigData
+                    );
+    FreePool (AttemptConfigData);
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
   }
 
   return EFI_SUCCESS;
 }
 
+/**
+  Create the iSCSI configuration Keywords for each attempt.
+
+  @param[in]  KeywordNum          The number Sets of Keywords will be created.
+
+  @retval EFI_SUCCESS             The operation is completed.
+  @retval Others                  Failed to create the Keywords.
+
+**/
+EFI_STATUS
+IScsiCreateKeywords (
+  IN UINTN            KeywordNum
+)
+{
+  VOID                          *StartOpCodeHandle;
+  EFI_IFR_GUID_LABEL            *StartLabel;
+  VOID                          *EndOpCodeHandle;
+  EFI_IFR_GUID_LABEL            *EndLabel;
+  UINTN                         Index;
+  EFI_STRING_ID                 StringToken;
+  CHAR16                        StringId[64];
+  CHAR16                        KeywordId[32];
+  EFI_STATUS                    Status;
+
+  Status = IScsiCreateOpCode (
+             KEYWORD_ENTRY_LABEL,
+             &StartOpCodeHandle,
+             &StartLabel,
+             &EndOpCodeHandle,
+             &EndLabel
+             );
+  if (EFI_ERROR (Status)) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  for (Index = 1; Index <= KeywordNum; Index ++) {
+    //
+    // Create iSCSIAttemptName Keyword.
+    //
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_ATTEMPTT_NAME_PROMPT%d", Index);
+    StringToken =  HiiSetString (
+                   mCallbackInfo->RegisteredHandle,
+                   0,
+                   StringId,
+                   NULL
+                   );
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIAttemptName:%d", Index);
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");
+    HiiCreateStringOpCode (
+      StartOpCodeHandle,
+      (EFI_QUESTION_ID) (ATTEMPT_ATTEMPT_NAME_QUESTION_ID + (Index - 1)),
+      CONFIGURATION_VARSTORE_ID,
+      (UINT16) (ATTEMPT_ATTEMPT_NAME_VAR_OFFSET + ATTEMPT_NAME_SIZE * (Index - 1) * sizeof (CHAR16)),
+      StringToken,
+      StringToken,
+      EFI_IFR_FLAG_READ_ONLY,
+      0,
+      0,
+      ATTEMPT_NAME_SIZE,
+      NULL
+      );
+
+    //
+    // Create iSCSIBootEnable Keyword.
+    //
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_MODE_PROMPT%d", Index);
+    StringToken =  HiiSetString (
+                   mCallbackInfo->RegisteredHandle,
+                   0,
+                   StringId,
+                   NULL
+                   );
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIBootEnable:%d", Index);
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");
+    HiiCreateNumericOpCode (
+      StartOpCodeHandle,
+      (EFI_QUESTION_ID) (ATTEMPT_BOOTENABLE_QUESTION_ID + (Index - 1)),
+      CONFIGURATION_VARSTORE_ID,
+      (UINT16) (ATTEMPT_BOOTENABLE_VAR_OFFSET + (Index - 1)),
+      StringToken,
+      StringToken,
+      0,
+      EFI_IFR_NUMERIC_SIZE_1,
+      0,
+      2,
+      0,
+      NULL
+      );
+
+    //
+    // Create iSCSIIpAddressType Keyword.
+    //
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_IP_MODE_PROMPT%d", Index);
+    StringToken =  HiiSetString (
+                   mCallbackInfo->RegisteredHandle,
+                   0,
+                   StringId,
+                   NULL
+                   );
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIIpAddressType:%d", Index);
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");
+    HiiCreateNumericOpCode (
+      StartOpCodeHandle,
+      (EFI_QUESTION_ID) (ATTEMPT_ADDRESS_TYPE_QUESTION_ID + (Index - 1)),
+      CONFIGURATION_VARSTORE_ID,
+      (UINT16) (ATTEMPT_ADDRESS_TYPE_VAR_OFFSET + (Index - 1)),
+      StringToken,
+      StringToken,
+      0,
+      EFI_IFR_NUMERIC_SIZE_1,
+      0,
+      2,
+      0,
+      NULL
+      );
+
+    //
+    // Create iSCSIConnectRetry Keyword.
+    //
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_CONNECT_RETRY_PROMPT%d", Index);
+    StringToken =  HiiSetString (
+                   mCallbackInfo->RegisteredHandle,
+                   0,
+                   StringId,
+                   NULL
+                   );
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIConnectRetry:%d", Index);
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");
+    HiiCreateNumericOpCode (
+      StartOpCodeHandle,
+      (EFI_QUESTION_ID) (ATTEMPT_CONNECT_RETRY_QUESTION_ID + (Index - 1)),
+      CONFIGURATION_VARSTORE_ID,
+      (UINT16) (ATTEMPT_CONNECT_RETRY_VAR_OFFSET + (Index - 1)),
+      StringToken,
+      StringToken,
+      0,
+      EFI_IFR_NUMERIC_SIZE_1,
+      0,
+      16,
+      0,
+      NULL
+      );
+
+    //
+    // Create iSCSIConnectTimeout Keyword.
+    //
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_CONNECT_TIMEOUT_PROMPT%d", Index);
+    StringToken =  HiiSetString (
+                   mCallbackInfo->RegisteredHandle,
+                   0,
+                   StringId,
+                   NULL
+                   );
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIConnectTimeout:%d", Index);
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");
+    HiiCreateNumericOpCode (
+      StartOpCodeHandle,
+      (EFI_QUESTION_ID) (ATTEMPT_CONNECT_TIMEOUT_QUESTION_ID + (Index - 1)),
+      CONFIGURATION_VARSTORE_ID,
+      (UINT16) (ATTEMPT_CONNECT_TIMEOUT_VAR_OFFSET + 2 * (Index - 1)),
+      StringToken,
+      StringToken,
+      0,
+      EFI_IFR_NUMERIC_SIZE_2,
+      CONNECT_MIN_TIMEOUT,
+      CONNECT_MAX_TIMEOUT,
+      0,
+      NULL
+      );
+
+    //
+    // Create ISID Keyword.
+    //
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_ISID_PROMPT%d", Index);
+    StringToken =  HiiSetString (
+                   mCallbackInfo->RegisteredHandle,
+                   0,
+                   StringId,
+                   NULL
+                   );
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIISID:%d", Index);
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");
+    HiiCreateStringOpCode (
+      StartOpCodeHandle,
+      (EFI_QUESTION_ID) (ATTEMPT_ISID_QUESTION_ID + (Index - 1)),
+      CONFIGURATION_VARSTORE_ID,
+      (UINT16) (ATTEMPT_ISID_VAR_OFFSET + sizeof (KEYWORD_STR) * (Index - 1)),
+      StringToken,
+      StringToken,
+      0,
+      0,
+      ISID_CONFIGURABLE_MIN_LEN,
+      ISID_CONFIGURABLE_STORAGE,
+      NULL
+      );
+
+    //
+    // Create iSCSIInitiatorInfoViaDHCP Keyword.
+    //
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_INITIATOR_VIA_DHCP_PROMPT%d", Index);
+    StringToken =  HiiSetString (
+                   mCallbackInfo->RegisteredHandle,
+                   0,
+                   StringId,
+                   NULL
+                   );
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIInitiatorInfoViaDHCP:%d", Index);
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");
+    HiiCreateNumericOpCode (
+    StartOpCodeHandle,
+    (EFI_QUESTION_ID) (ATTEMPT_INITIATOR_VIA_DHCP_QUESTION_ID + (Index - 1)),
+    CONFIGURATION_VARSTORE_ID,
+    (UINT16) (ATTEMPT_INITIATOR_VIA_DHCP_VAR_OFFSET + (Index - 1)),
+    StringToken,
+    StringToken,
+    0,
+    0,
+    0,
+    1,
+    0,
+    NULL
+    );
+
+    //
+    // Create iSCSIInitiatorIpAddress Keyword.
+    //
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_INITIATOR_IP_ADDRESS_PROMPT%d", Index);
+    StringToken =  HiiSetString (
+                   mCallbackInfo->RegisteredHandle,
+                   0,
+                   StringId,
+                   NULL
+                   );
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIInitiatorIpAddress:%d", Index);
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");
+    HiiCreateStringOpCode (
+      StartOpCodeHandle,
+      (EFI_QUESTION_ID) (ATTEMPT_INITIATOR_IP_ADDRESS_QUESTION_ID + (Index - 1)),
+      CONFIGURATION_VARSTORE_ID,
+      (UINT16) (ATTEMPT_INITIATOR_IP_ADDRESS_VAR_OFFSET + sizeof (KEYWORD_STR) * (Index - 1)),
+      StringToken,
+      StringToken,
+      0,
+      0,
+      IP4_MIN_SIZE,
+      IP4_MAX_SIZE,
+      NULL
+      );
+
+    //
+    // Create iSCSIInitiatorNetmask Keyword.
+    //
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_INITIATOR_NET_MASK_PROMPT%d", Index);
+    StringToken =  HiiSetString (
+                   mCallbackInfo->RegisteredHandle,
+                   0,
+                   StringId,
+                   NULL
+                   );
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIInitiatorNetmask:%d", Index);
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");
+    HiiCreateStringOpCode (
+      StartOpCodeHandle,
+      (EFI_QUESTION_ID) (ATTEMPT_INITIATOR_NET_MASK_QUESTION_ID + (Index - 1)),
+      CONFIGURATION_VARSTORE_ID,
+      (UINT16) (ATTEMPT_INITIATOR_NET_MASK_VAR_OFFSET + sizeof (KEYWORD_STR) * (Index - 1)),
+      StringToken,
+      StringToken,
+      0,
+      0,
+      IP4_MIN_SIZE,
+      IP4_MAX_SIZE,
+      NULL
+      );
+
+    //
+    // Create iSCSIInitiatorGateway Keyword.
+    //
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_INITIATOR_GATE_PROMPT%d", Index);
+    StringToken =  HiiSetString (
+                   mCallbackInfo->RegisteredHandle,
+                   0,
+                   StringId,
+                   NULL
+                   );
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIInitiatorGateway:%d", Index);
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");
+    HiiCreateStringOpCode (
+      StartOpCodeHandle,
+      (EFI_QUESTION_ID) (ATTEMPT_INITIATOR_GATE_WAY_QUESTION_ID + (Index - 1)),
+      CONFIGURATION_VARSTORE_ID,
+      (UINT16) (ATTEMPT_INITIATOR_GATE_WAY_VAR_OFFSET + sizeof (KEYWORD_STR) * (Index - 1)),
+      StringToken,
+      StringToken,
+      0,
+      0,
+      IP4_MIN_SIZE,
+      IP4_MAX_SIZE,
+      NULL
+      );
+
+    //
+    // Create iSCSITargetInfoViaDHCP Keyword.
+    //
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_TARGET_VIA_DHCP_PROMPT%d", Index);
+    StringToken =  HiiSetString (
+                   mCallbackInfo->RegisteredHandle,
+                   0,
+                   StringId,
+                   NULL
+                   );
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSITargetInfoViaDHCP:%d", Index);
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");
+    HiiCreateNumericOpCode (
+    StartOpCodeHandle,
+    (EFI_QUESTION_ID) (ATTEMPT_TARGET_VIA_DHCP_QUESTION_ID + (Index - 1)),
+    CONFIGURATION_VARSTORE_ID,
+    (UINT16) (ATTEMPT_TARGET_VIA_DHCP_VAR_OFFSET + (Index - 1)),
+    StringToken,
+    StringToken,
+    0,
+    0,
+    0,
+    1,
+    0,
+    NULL
+    );
+
+    //
+    // Create iSCSITargetTcpPort Keyword.
+    //
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_TARGET_TCP_PORT_PROMPT%d", Index);
+    StringToken =  HiiSetString (
+                   mCallbackInfo->RegisteredHandle,
+                   0,
+                   StringId,
+                   NULL
+                   );
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSITargetTcpPort:%d", Index);
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");
+    HiiCreateNumericOpCode (
+      StartOpCodeHandle,
+      (EFI_QUESTION_ID) (ATTEMPT_TARGET_TCP_PORT_QUESTION_ID + (Index - 1)),
+      CONFIGURATION_VARSTORE_ID,
+      (UINT16) (ATTEMPT_TARGET_TCP_PORT_VAR_OFFSET + 2 * (Index - 1)),
+      StringToken,
+      StringToken,
+      0,
+      EFI_IFR_NUMERIC_SIZE_2,
+      TARGET_PORT_MIN_NUM,
+      TARGET_PORT_MAX_NUM,
+      0,
+      NULL
+      );
+
+    //
+    // Create iSCSITargetName Keyword.
+    //
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_TARGET_NAME_PROMPT%d", Index);
+    StringToken =  HiiSetString (
+                   mCallbackInfo->RegisteredHandle,
+                   0,
+                   StringId,
+                   NULL
+                   );
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSITargetName:%d", Index);
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");
+    HiiCreateStringOpCode (
+      StartOpCodeHandle,
+      (EFI_QUESTION_ID) (ATTEMPT_TARGET_NAME_QUESTION_ID + (Index - 1)),
+      CONFIGURATION_VARSTORE_ID,
+      (UINT16) (ATTEMPT_TARGET_NAME_VAR_OFFSET + sizeof (KEYWORD_STR) * (Index - 1)),
+      StringToken,
+      StringToken,
+      0,
+      0,
+      ISCSI_NAME_IFR_MIN_SIZE,
+      ISCSI_NAME_IFR_MAX_SIZE,
+      NULL
+      );
+
+    //
+    // Create iSCSITargetIpAddress Keyword.
+    //
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_TARGET_IP_ADDRESS_PROMPT%d", Index);
+    StringToken =  HiiSetString (
+                   mCallbackInfo->RegisteredHandle,
+                   0,
+                   StringId,
+                   NULL
+                   );
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSITargetIpAddress:%d", Index);
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");
+    HiiCreateStringOpCode (
+      StartOpCodeHandle,
+      (EFI_QUESTION_ID) (ATTEMPT_TARGET_IP_ADDRESS_QUESTION_ID + (Index - 1)),
+      CONFIGURATION_VARSTORE_ID,
+      (UINT16) (ATTEMPT_TARGET_IP_ADDRESS_VAR_OFFSET + sizeof (KEYWORD_STR) * (Index - 1)),
+      StringToken,
+      StringToken,
+      0,
+      0,
+      IP_MIN_SIZE,
+      IP_MAX_SIZE,
+      NULL
+      );
+
+    //
+    // Create iSCSILUN Keyword.
+    //
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_LUN_PROMPT%d", Index);
+    StringToken =  HiiSetString (
+                   mCallbackInfo->RegisteredHandle,
+                   0,
+                   StringId,
+                   NULL
+                   );
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSILUN:%d", Index);
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");
+    HiiCreateStringOpCode (
+      StartOpCodeHandle,
+      (EFI_QUESTION_ID) (ATTEMPT_LUN_QUESTION_ID + (Index - 1)),
+      CONFIGURATION_VARSTORE_ID,
+      (UINT16) (ATTEMPT_LUN_VAR_OFFSET + sizeof (KEYWORD_STR) * (Index - 1)),
+      StringToken,
+      StringToken,
+      0,
+      0,
+      LUN_MIN_SIZE,
+      LUN_MAX_SIZE,
+      NULL
+      );
+
+    //
+    // Create iSCSIAuthenticationMethod Keyword.
+    //
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_AUTHENTICATION_METHOD_PROMPT%d", Index);
+    StringToken =  HiiSetString (
+                   mCallbackInfo->RegisteredHandle,
+                   0,
+                   StringId,
+                   NULL
+                   );
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIAuthenticationMethod:%d", Index);
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");
+    HiiCreateNumericOpCode (
+    StartOpCodeHandle,
+    (EFI_QUESTION_ID) (ATTEMPT_AUTHENTICATION_METHOD_QUESTION_ID + (Index - 1)),
+    CONFIGURATION_VARSTORE_ID,
+    (UINT16) (ATTEMPT_AUTHENTICATION_METHOD_VAR_OFFSET + (Index - 1)),
+    StringToken,
+    StringToken,
+    0,
+    0,
+    0,
+    1,
+    0,
+    NULL
+    );
+
+    //
+    // Create iSCSIChapType Keyword.
+    //
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_CHARTYPE_PROMPT%d", Index);
+    StringToken =  HiiSetString (
+                   mCallbackInfo->RegisteredHandle,
+                   0,
+                   StringId,
+                   NULL
+                   );
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIChapType:%d", Index);
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");
+    HiiCreateNumericOpCode (
+    StartOpCodeHandle,
+    (EFI_QUESTION_ID) (ATTEMPT_CHARTYPE_QUESTION_ID + (Index - 1)),
+    CONFIGURATION_VARSTORE_ID,
+    (UINT16) (ATTEMPT_CHARTYPE_VAR_OFFSET + (Index - 1)),
+    StringToken,
+    StringToken,
+    0,
+    0,
+    0,
+    1,
+    0,
+    NULL
+    );
+
+    //
+    // Create iSCSIChapUsername Keyword.
+    //
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_CHAR_USER_NAME_PROMPT%d", Index);
+    StringToken =  HiiSetString (
+                   mCallbackInfo->RegisteredHandle,
+                   0,
+                   StringId,
+                   NULL
+                   );
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIChapUsername:%d", Index);
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");
+    HiiCreateStringOpCode (
+      StartOpCodeHandle,
+      (EFI_QUESTION_ID) (ATTEMPT_CHAR_USER_NAME_QUESTION_ID + (Index - 1)),
+      CONFIGURATION_VARSTORE_ID,
+      (UINT16) (ATTEMPT_CHAR_USER_NAME_VAR_OFFSET + sizeof (KEYWORD_STR) * (Index - 1)),
+      StringToken,
+      StringToken,
+      0,
+      0,
+      0,
+      ISCSI_CHAP_NAME_MAX_LEN,
+      NULL
+      );
+
+    //
+    // Create iSCSIChapSecret Keyword.
+    //
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_CHAR_SECRET_PROMPT%d", Index);
+    StringToken =  HiiSetString (
+                   mCallbackInfo->RegisteredHandle,
+                   0,
+                   StringId,
+                   NULL
+                   );
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIChapSecret:%d", Index);
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");
+    HiiCreateStringOpCode (
+      StartOpCodeHandle,
+      (EFI_QUESTION_ID) (ATTEMPT_CHAR_SECRET_QUESTION_ID + (Index - 1)),
+      CONFIGURATION_VARSTORE_ID,
+      (UINT16) (ATTEMPT_CHAR_SECRET_VAR_OFFSET + sizeof (KEYWORD_STR) * (Index - 1)),
+      StringToken,
+      StringToken,
+      0,
+      0,
+      ISCSI_CHAP_SECRET_MIN_LEN,
+      ISCSI_CHAP_SECRET_MAX_LEN,
+      NULL
+      );
+
+    //
+    // Create iSCSIReverseChapUsername Keyword.
+    //
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_CHAR_REVERSE_USER_NAME_PROMPT%d", Index);
+    StringToken =  HiiSetString (
+                   mCallbackInfo->RegisteredHandle,
+                   0,
+                   StringId,
+                   NULL
+                   );
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIReverseChapUsername:%d", Index);
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");
+    HiiCreateStringOpCode (
+      StartOpCodeHandle,
+      (EFI_QUESTION_ID) (ATTEMPT_CHAR_REVERSE_USER_NAME_QUESTION_ID + (Index - 1)),
+      CONFIGURATION_VARSTORE_ID,
+      (UINT16) (ATTEMPT_CHAR_REVERSE_USER_NAME_VAR_OFFSET + sizeof (KEYWORD_STR) * (Index - 1)),
+      StringToken,
+      StringToken,
+      0,
+      0,
+      0,
+      ISCSI_CHAP_NAME_MAX_LEN,
+      NULL
+      );
+
+    //
+    // Create iSCSIReverseChapSecret Keyword.
+    //
+    UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_CHAR_REVERSE_SECRET_PROMPT%d", Index);
+    StringToken =  HiiSetString (
+                   mCallbackInfo->RegisteredHandle,
+                   0,
+                   StringId,
+                   NULL
+                   );
+    UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIReverseChapSecret:%d", Index);
+    HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId, "x-UEFI-ns");
+    HiiCreateStringOpCode (
+      StartOpCodeHandle,
+      (EFI_QUESTION_ID) (ATTEMPT_CHAR_REVERSE_SECRET_QUESTION_ID + (Index - 1)),
+      CONFIGURATION_VARSTORE_ID,
+      (UINT16) (ATTEMPT_CHAR_REVERSE_SECRET_VAR_OFFSET + sizeof (KEYWORD_STR) * (Index - 1)),
+      StringToken,
+      StringToken,
+      0,
+      0,
+      ISCSI_CHAP_SECRET_MIN_LEN,
+      ISCSI_CHAP_SECRET_MAX_LEN,
+      NULL
+      );
+  }
+
+  Status = HiiUpdateForm (
+             mCallbackInfo->RegisteredHandle, // HII handle
+             &gIScsiConfigGuid,               // Formset GUID
+             FORMID_ATTEMPT_FORM,             // Form ID
+             StartOpCodeHandle,               // Label for where to insert opcodes
+             EndOpCodeHandle                  // Replace data
+             );
+
+  HiiFreeOpCodeHandle (StartOpCodeHandle);
+  HiiFreeOpCodeHandle (EndOpCodeHandle);
+
+  return Status;
+}
+
+/**
+
+  Free the attempt configure data variable.
+
+**/
+VOID
+IScsiCleanAttemptVariable (
+  IN   VOID
+)
+{
+  ISCSI_ATTEMPT_CONFIG_NVDATA   *AttemptConfigData;
+  UINT8                         *AttemptConfigOrder;
+  UINTN                         AttemptConfigOrderSize;
+  UINTN                         Index;
+
+  //
+  // Get the initialized attempt order.
+  //
+  AttemptConfigOrder = IScsiGetVariableAndSize (
+                         L"InitiatorAttemptOrder",
+                         &gIScsiConfigGuid,
+                         &AttemptConfigOrderSize
+                         );
+  if (AttemptConfigOrder == NULL || AttemptConfigOrderSize == 0) {
+    return;
+  }
+
+  for (Index = 1; Index < AttemptConfigOrderSize / sizeof (UINT8); Index++) {
+    UnicodeSPrint (
+      mPrivate->PortString,
+      (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
+      L"Attempt %d",
+      Index
+      );
+
+    GetVariable2 (
+      mPrivate->PortString,
+      &gEfiIScsiInitiatorNameProtocolGuid,
+      (VOID**)&AttemptConfigData,
+      NULL
+      );
+
+    if (AttemptConfigData != NULL) {
+      gRT->SetVariable (
+             mPrivate->PortString,
+             &gEfiIScsiInitiatorNameProtocolGuid,
+             0,
+             0,
+             NULL
+             );
+    }
+  }
+  return;
+}
 
 /**
   Get the recorded NIC info from global structure by the Index.
 
   @param[in]  NicIndex          The index indicates the position of NIC info.
@@ -929,10 +1698,11 @@ IScsiDhcpIsConfigured (
   EFI_STATUS                  Status;
   EFI_MAC_ADDRESS             MacAddr;
   UINTN                       HwAddressSize;
   UINT16                      VlanId;
   CHAR16                      MacString[ISCSI_MAX_MAC_STRING_LEN];
+  CHAR16                      AttemptMacString[ISCSI_MAX_MAC_STRING_LEN];
   CHAR16                      AttemptName[ISCSI_NAME_IFR_MAX_SIZE];
   
   AttemptConfigOrder = IScsiGetVariableAndSize (
                          L"AttemptOrder",
                          &gIScsiConfigGuid,
@@ -957,12 +1727,11 @@ IScsiDhcpIsConfigured (
   
   for (Index = 0; Index < AttemptConfigOrderSize / sizeof (UINT8); Index++) {
     UnicodeSPrint (
       AttemptName,
       (UINTN) 128,
-      L"%s%d",
-      MacString,
+      L"Attempt %d",
       (UINTN) AttemptConfigOrder[Index]
       );
     Status = GetVariable2 (
                AttemptName,
                &gEfiIScsiInitiatorNameProtocolGuid,
@@ -983,11 +1752,17 @@ IScsiDhcpIsConfigured (
     if (AttemptTmp->SessionConfigData.IpMode != IP_MODE_AUTOCONFIG && 
         AttemptTmp->SessionConfigData.IpMode != ((IpVersion == IP_VERSION_4) ? IP_MODE_IP4 : IP_MODE_IP6)) {
       FreePool (AttemptTmp);
       continue;
     }
-    
+
+    AsciiStrToUnicodeStrS (AttemptTmp->MacString, AttemptMacString, sizeof (AttemptMacString) / sizeof (AttemptMacString[0]));
+
+    if (AttemptTmp->Actived == ISCSI_ACTIVE_DISABLED || StrCmp (MacString, AttemptMacString)) {
+      continue;
+    }
+
     if(AttemptTmp->SessionConfigData.IpMode == IP_MODE_AUTOCONFIG ||
        AttemptTmp->SessionConfigData.InitiatorInfoFromDhcp == TRUE ||
        AttemptTmp->SessionConfigData.TargetInfoFromDhcp == TRUE) { 
       FreePool (AttemptTmp);
       FreePool (AttemptConfigOrder);
@@ -1104,10 +1879,11 @@ IScsiGetConfigData (
   IN ISCSI_DRIVER_DATA  *Private
   )
 {
   EFI_STATUS                  Status;
   CHAR16                      MacString[ISCSI_MAX_MAC_STRING_LEN];
+  CHAR16                      AttemptMacString[ISCSI_MAX_MAC_STRING_LEN];
   UINTN                       Index;
   ISCSI_NIC_INFO              *NicInfo;
   ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;
   ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptTmp;
   UINT8                       *AttemptConfigOrder;
@@ -1195,16 +1971,14 @@ IScsiGetConfigData (
           }
 
           //
           // Refresh the state of this attempt to NVR.
           //
-          AsciiStrToUnicodeStrS (AttemptTmp->MacString, MacString, ARRAY_SIZE (MacString));
           UnicodeSPrint (
             mPrivate->PortString,
             (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
-            L"%s%d",
-            MacString,
+            L"Attempt %d",
             (UINTN) AttemptTmp->AttemptConfigIndex
             );
 
           gRT->SetVariable (
                  mPrivate->PortString,
@@ -1234,16 +2008,14 @@ IScsiGetConfigData (
         }
 
         //
         // Refresh the state of this attempt to NVR.
         //
-        AsciiStrToUnicodeStrS (AttemptTmp->MacString, MacString, ARRAY_SIZE (MacString));
         UnicodeSPrint (
           mPrivate->PortString,
           (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
-          L"%s%d",
-          MacString,
+          L"Attempt %d",
           (UINTN) AttemptTmp->AttemptConfigIndex
           );
 
         gRT->SetVariable (
                mPrivate->PortString,
@@ -1267,24 +2039,25 @@ IScsiGetConfigData (
     NicInfo = IScsiGetNicInfoByIndex (mPrivate->CurrentNic);
     ASSERT (NicInfo != NULL);
     IScsiMacAddrToStr (&NicInfo->PermanentAddress, NicInfo->HwAddressSize, NicInfo->VlanId, MacString);
     UnicodeSPrint (
       mPrivate->PortString,
-      (UINTN) 128,
-      L"%s%d",
-      MacString,
+      (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
+      L"Attempt %d",
       (UINTN) AttemptConfigOrder[Index]
       );
 
     GetVariable2 (
       mPrivate->PortString,
       &gEfiIScsiInitiatorNameProtocolGuid,
       (VOID**)&AttemptConfigData,
       NULL
       );
+    AsciiStrToUnicodeStrS (AttemptConfigData->MacString, AttemptMacString, sizeof (AttemptMacString) / sizeof (AttemptMacString[0]));
 
-    if (AttemptConfigData == NULL) {
+    if (AttemptConfigData == NULL || AttemptConfigData->Actived == ISCSI_ACTIVE_DISABLED ||
+        StrCmp (MacString, AttemptMacString)) {
       continue;
     }
 
     ASSERT (AttemptConfigOrder[Index] == AttemptConfigData->AttemptConfigIndex);
 
@@ -1325,16 +2098,14 @@ IScsiGetConfigData (
       }
 
       //
       // Refresh the state of this attempt to NVR.
       //
-      AsciiStrToUnicodeStrS (AttemptConfigData->MacString, MacString, ARRAY_SIZE (MacString));
       UnicodeSPrint (
         mPrivate->PortString,
         (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
-        L"%s%d",
-        MacString,
+        L"Attempt %d",
         (UINTN) AttemptConfigData->AttemptConfigIndex
         );
 
       gRT->SetVariable (
              mPrivate->PortString,
diff --git a/NetworkPkg/IScsiDxe/IScsiMisc.h b/NetworkPkg/IScsiDxe/IScsiMisc.h
index 2c0fe07..2ec18b5 100644
--- a/NetworkPkg/IScsiDxe/IScsiMisc.h
+++ b/NetworkPkg/IScsiDxe/IScsiMisc.h
@@ -242,10 +242,48 @@ EFI_STATUS
 IScsiRemoveNic (
   IN EFI_HANDLE  Controller
   );
 
 /**
+  Create and initialize the Attempts.
+
+  @param[in]  AttemptNum          The number of Attempts will be created.
+
+  @retval EFI_SUCCESS             The Attempts have been created successfully.
+  @retval Others                  Failed to create the Attempt.
+
+**/
+EFI_STATUS
+IScsiCreateAttempts (
+  IN UINTN            AttemptNum
+);
+
+/**
+  Create the iSCSI configuration Keywords for each attempt.
+
+  @param[in]  KeywordNum          The number Sets of Keywords will be created.
+
+  @retval EFI_SUCCESS             The operation is completed.
+  @retval Others                  Failed to create the Keywords.
+
+**/
+EFI_STATUS
+IScsiCreateKeywords (
+  IN UINTN            KeywordNum
+);
+
+/**
+
+  Free the attempt configure data variable.
+
+**/
+VOID
+IScsiCleanAttemptVariable (
+  IN   VOID
+);
+
+/**
   Get the recorded NIC information from a global structure by the Index.
 
   @param[in]  NicIndex          The index indicates the position of NIC info.
 
   @return Pointer to the NIC info or NULL if not found.
diff --git a/NetworkPkg/NetworkPkg.dec b/NetworkPkg/NetworkPkg.dec
index 2aa8894..28558d3 100644
--- a/NetworkPkg/NetworkPkg.dec
+++ b/NetworkPkg/NetworkPkg.dec
@@ -43,11 +43,15 @@
   # Include/Guid/TlsAuthConfigHii.h
   gTlsAuthConfigGuid            = { 0xb0eae4f8, 0x9a04, 0x4c6d, { 0xa7, 0x48, 0x79, 0x3d, 0xaa, 0xf, 0x65, 0xdf }}
   
   # Include/Guid/TlsAuthentication.h
   gEfiTlsCaCertificateGuid      = { 0xfd2340D0, 0x3dab, 0x4349, { 0xa6, 0xc7, 0x3b, 0x4f, 0x12, 0xb4, 0x8e, 0xae }}
-  
+
+[PcdsFixedAtBuild]
+  ## The max attempt number will be created by iSCSI driver.
+  # @Prompt Max attempt number.
+  gEfiNetworkPkgTokenSpaceGuid.PcdMaxIScsiAttemptNumber|0x08|UINT8|0x0000000D
 
 [PcdsFeatureFlag]
   ## Indicates if the IPsec IKEv2 Certificate Authentication feature is enabled or not.<BR><BR>
   #   TRUE  - Certificate Authentication feature is enabled.<BR>
   #   FALSE - Does not support Certificate Authentication.<BR>
-- 
1.9.5.msysgit.1



           reply	other threads:[~2017-02-20  8:50 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <1487314532-50492-1-git-send-email-lubo.zhang@intel.com>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BC0C045B0E2A584CA4575E779FA2C12A1A8B054E@SHSMSX103.ccr.corp.intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox