From nobody Sat Nov 2 14:33:00 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487314558294851.4570012106552; Thu, 16 Feb 2017 22:55:58 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3EB288212D; Thu, 16 Feb 2017 22:55:56 -0800 (PST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 65A808212C for ; Thu, 16 Feb 2017 22:55:54 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Feb 2017 22:55:54 -0800 Received: from shwdeopenpsi116.ccr.corp.intel.com ([10.239.9.7]) by fmsmga006.fm.intel.com with ESMTP; 16 Feb 2017 22:55:51 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,171,1484035200"; d="scan'208";a="66893808" From: Zhang Lubo To: edk2-devel@lists.01.org Date: Fri, 17 Feb 2017 14:55:32 +0800 Message-Id: <1487314532-50492-1-git-send-email-lubo.zhang@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 Subject: [edk2] [PATCH v2] NetworkPkg:Add scriptable configuration to iSCSI driver by X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ye Ting , Fu Siyuan , Wu Jiaxin MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 Cc: Ye Ting Cc: Fu Siyuan Cc: Wu Jiaxin Reviewed-by: Ye Ting =20 --- 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/IScsiC= onfig.c index 40ea75a..d07bdcb 100644 --- a/NetworkPkg/IScsiDxe/IScsiConfig.c +++ b/NetworkPkg/IScsiDxe/IScsiConfig.c @@ -288,10 +288,102 @@ IScsiConvertIsIdToString ( =20 return EFI_SUCCESS; } =20 /** + Get the Offset value specified by the input String. + + @param[in] Configuration A null-terminated Unicode string in + format. + @param[in] String The string is "&OFFSET=3D". + @param[out] Value The Offset value. + + @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary + structures. + @retval EFI_SUCCESS Value of 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 =3D NULL; + StringPtr =3D StrStr (Configuration, String); + ASSERT(StringPtr !=3D NULL); + StringPtr +=3D StrLen (String); + TmpPtr =3D StringPtr; + + while (*StringPtr !=3D L'\0' && *StringPtr !=3D L'&') { + StringPtr ++; + } + Length =3D StringPtr - TmpPtr; + Len =3D Length + 1; + + Str =3D AllocateZeroPool (Len * sizeof (CHAR16)); + if (Str =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto Exit; + } + + CopyMem (Str, TmpPtr, Len * sizeof (CHAR16)); + *(Str + Length) =3D L'\0'; + + Len =3D (Len + 1) / 2; + Buf =3D (UINT8 *) AllocateZeroPool (Len); + if (Buf =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto Exit; + } + + ZeroMem (TmpStr, sizeof (TmpStr)); + for (Index =3D 0; Index < Length; Index ++) { + TmpStr[0] =3D Str[Length - Index - 1]; + DigitUint8 =3D (UINT8) StrHexToUint64 (TmpStr); + if ((Index & 1) =3D=3D 0) { + Buf [Index/2] =3D DigitUint8; + } else { + Buf [Index/2] =3D (UINT8) ((DigitUint8 << 4) + Buf [Index/2]); + } + } + + *Value =3D 0; + CopyMem ( + Value, + Buf, + (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (U= INTN) + ); + + FreePool (Buf); + Status =3D EFI_SUCCESS; + +Exit: + if (Str !=3D NULL) { + FreePool (Str); + } + + return Status; +} + +/** Get the attempt config data from global structure by the ConfigIndex. =20 @param[in] AttemptConfigIndex The unique index indicates the attemp= t. =20 @return Pointer to the attempt config data. @@ -347,10 +439,68 @@ IScsiConfigGetAttemptByNic ( } =20 return NULL; } =20 +/** + 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 atte= mpts. + 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 =3D 0; + + if ((AttemptNameList =3D=3D NULL) || (*AttemptNameList =3D=3D L'\0')) { + return EFI_INVALID_PARAMETER; + } + + AttemptStr =3D AttemptNameList; + Len =3D StrLen (L"attempt:"); + + while (*AttemptStr !=3D L'\0') { + AttemptStr =3D StrStr (AttemptStr, L"attempt:"); + if (AttemptStr =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + AttemptStr +=3D Len; + AttemptIndex =3D (UINT8)(*AttemptStr - L'0'); + AttemptConfigData =3D IScsiConfigGetAttemptByConfigIndex (AttemptInde= x); + if (IsAddAttempts) { + if ((AttemptConfigData !=3D NULL) || ((AttemptIndex) > PcdGet8 (PcdM= axIScsiAttemptNumber))) { + return EFI_INVALID_PARAMETER; + } + } else { + if (AttemptConfigData =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + } + + AttemptIndexList[Index] =3D AttemptIndex; + Index ++; + AttemptStr +=3D 2; + } + return EFI_SUCCESS; +} =20 /** Convert the iSCSI configuration data into the IFR data. =20 @param[in] Attempt The iSCSI attempt config data. @@ -459,10 +609,125 @@ IScsiConvertAttemptConfigDataToIfrNvData ( sizeof (IfrNvData->AttemptName) / sizeof (IfrNvData->AttemptName[0]) ); } =20 /** + 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 =3D NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, = Link); + // + // Normal session configuration parameters. + // + SessionConfigData =3D &Attempt->SessionConfigData; + + Index =3D 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) =3D L':'; + *(AttemptNameList + StrLen (AttemptNameList)) =3D L' '; + + AsciiStrToUnicodeStrS ( + Attempt->AttemptName, + IfrNvData->ISCSIAttemptName + ATTEMPT_NAME_SIZE * Index, + ATTEMPT_NAME_SIZE + ); + + IfrNvData->ISCSIBootEnableList[Index] =3D SessionConfigData->= Enabled; + IfrNvData->ISCSIIpAddressTypeList[Index] =3D SessionConfigData->= IpMode; + + IfrNvData->ISCSIInitiatorInfoViaDHCP[Index] =3D SessionConfigData->= InitiatorInfoFromDhcp; + IfrNvData->ISCSITargetInfoViaDHCP[Index] =3D SessionConfigData->= TargetInfoFromDhcp; + IfrNvData->ISCSIConnectRetry[Index] =3D SessionConfigData->= ConnectRetryCount; + IfrNvData->ISCSIConnectTimeout[Index] =3D SessionConfigData->= ConnectTimeout; + IfrNvData->ISCSITargetTcpPort[Index] =3D SessionConfigData->= TargetPort; + + if (SessionConfigData->IpMode =3D=3D IP_MODE_IP4) { + CopyMem (&Ip.v4, &SessionConfigData->LocalIp, sizeof (EFI_IPv4_ADDRE= SS)); + IScsiIpToStr (&Ip, FALSE, IfrNvData->Keyword[Index].ISCSIInitiatorIp= Address); + CopyMem (&Ip.v4, &SessionConfigData->SubnetMask, sizeof (EFI_IPv4_AD= DRESS)); + IScsiIpToStr (&Ip, FALSE, IfrNvData->Keyword[Index].ISCSIInitiatorNe= tmask); + CopyMem (&Ip.v4, &SessionConfigData->Gateway, sizeof (EFI_IPv4_ADDRE= SS)); + IScsiIpToStr (&Ip, FALSE, IfrNvData->Keyword[Index].ISCSIInitiatorGa= teway); + CopyMem (&Ip.v4, &SessionConfigData->TargetIp, sizeof (EFI_IPv4_ADDR= ESS)); + IScsiIpToStr (&Ip, FALSE, IfrNvData->Keyword[Index].ISCSITargetIpAdd= ress); + } else if (SessionConfigData->IpMode =3D=3D IP_MODE_IP6) { + ZeroMem (IfrNvData->Keyword[Index].ISCSITargetIpAddress, sizeof (Ifr= NvData->TargetIp)); + IP6_COPY_ADDRESS (&Ip.v6, &SessionConfigData->TargetIp); + IScsiIpToStr (&Ip, TRUE, IfrNvData->Keyword[Index].ISCSITargetIpAddr= ess); + } + + AsciiStrToUnicodeStrS ( + SessionConfigData->TargetName, + IfrNvData->Keyword[Index].ISCSITargetName, + ISCSI_NAME_MAX_SIZE + ); + + IScsiLunToUnicodeStr (SessionConfigData->BootLun, IfrNvData->Keyword[I= ndex].ISCSILUN); + IScsiConvertIsIdToString (IfrNvData->Keyword[Index].ISCSIISID, Session= ConfigData->IsId); + + IfrNvData->ISCSIAuthenticationMethod[Index] =3D Attempt->Authentica= tionType; + + if (Attempt->AuthenticationType =3D=3D ISCSI_AUTH_TYPE_CHAP) { + AuthConfigData =3D &Attempt->AuthConfigData.CHAP; + IfrNvData->ISCSIChapType[Index] =3D 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_NAM= E_LIST_SIZE); +} + +/** Convert the IFR data to iSCSI configuration data. =20 @param[in] IfrNvData Point to ISCSI_CONFIG_IFR_NVDATA. @param[in, out] Attempt The iSCSI attempt config data. =20 @@ -534,11 +799,11 @@ IScsiConvertIfrNvDataToAttemptConfigData ( EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Connection Establishing Timeout is less than minimum value 100ms= .", NULL ); - =20 + return EFI_INVALID_PARAMETER; } =20 // // 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 ); - =20 + return EFI_INVALID_PARAMETER; } else if (!IP4_NET_EQUAL (HostIp.Addr[0], Gateway.Addr[0], Subnet= Mask.Addr[0])) { CreatePopUp ( EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Local IP and Gateway are not in the same subnet.", NULL ); - =20 + return EFI_INVALID_PARAMETER; } } } // @@ -611,11 +876,10 @@ IScsiConvertIfrNvDataToAttemptConfigData ( ); return EFI_INVALID_PARAMETER; } } =20 - // // Validate the authentication info. // if (IfrNvData->AuthenticationType =3D=3D ISCSI_AUTH_TYPE_CHAP) { if ((IfrNvData->CHAPName[0] =3D=3D '\0') || (IfrNvData->CHAPSecret[0= ] =3D=3D '\0')) { @@ -645,30 +909,23 @@ IScsiConvertIfrNvDataToAttemptConfigData ( // // Check whether this attempt uses NIC which is already used by existi= ng attempt. // SameNicAttempt =3D IScsiConfigGetAttemptByNic (Attempt, IfrNvData->Ena= bled); if (SameNicAttempt !=3D NULL) { - AttemptName1 =3D (CHAR16 *) AllocateZeroPool (ATTEMPT_NAME_MAX_SIZE = * sizeof (CHAR16)); + AttemptName1 =3D (CHAR16 *) AllocateZeroPool (ATTEMPT_NAME_SIZE * si= zeof (CHAR16)); if (AttemptName1 =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; } =20 - AttemptName2 =3D (CHAR16 *) AllocateZeroPool (ATTEMPT_NAME_MAX_SIZE = * sizeof (CHAR16)); + AttemptName2 =3D (CHAR16 *) AllocateZeroPool (ATTEMPT_NAME_SIZE * si= zeof (CHAR16)); if (AttemptName2 =3D=3D NULL) { FreePool (AttemptName1); return EFI_OUT_OF_RESOURCES; } =20 - =20 - AsciiStrToUnicodeStrS (Attempt->AttemptName, AttemptName1, ATTEMPT_N= AME_MAX_SIZE); - if (StrLen (AttemptName1) > ATTEMPT_NAME_SIZE) { - CopyMem (&AttemptName1[ATTEMPT_NAME_SIZE], L"...", 4 * sizeof (CHA= R16)); - } =20 - AsciiStrToUnicodeStrS (SameNicAttempt->AttemptName, AttemptName2, AT= TEMPT_NAME_MAX_SIZE); - if (StrLen (AttemptName2) > ATTEMPT_NAME_SIZE) { - CopyMem (&AttemptName2[ATTEMPT_NAME_SIZE], L"...", 4 * sizeof (CHA= R16)); - } + AsciiStrToUnicodeStrS (Attempt->AttemptName, AttemptName1, ATTEMPT_N= AME_SIZE); + AsciiStrToUnicodeStrS (SameNicAttempt->AttemptName, AttemptName2, AT= TEMPT_NAME_SIZE); =20 UnicodeSPrint ( mPrivate->PortString, (UINTN) ISCSI_NAME_IFR_MAX_SIZE, L"Warning! Attempt \"%s\" uses same NIC as Attempt \"%s\".", @@ -689,11 +946,10 @@ IScsiConvertIfrNvDataToAttemptConfigData ( } =20 // // Update the iSCSI Mode data and record it in attempt help info. // - Attempt->SessionConfigData.Enabled =3D IfrNvData->Enabled; if (IfrNvData->Enabled =3D=3D ISCSI_DISABLED) { UnicodeSPrint (IScsiMode, 64, L"Disabled"); } else if (IfrNvData->Enabled =3D=3D ISCSI_ENABLED) { UnicodeSPrint (IScsiMode, 64, L"Enabled"); } else if (IfrNvData->Enabled =3D=3D ISCSI_ENABLED_FOR_MPIO) { @@ -813,15 +1069,14 @@ IScsiConvertIfrNvDataToAttemptConfigData ( } =20 } else if (ExistAttempt =3D=3D 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 exis= ting - // attempt, it should be a new created attempt. Save it to system now. - // =20 - ASSERT (Attempt =3D=3D mPrivate->NewAttempt); + // mCallbackInfo->Current in IScsiConfigProcessDefault. If input Attem= pt + // does not match any existing attempt, it should be a new created att= empt. + // Save it to system now. + // =20 // // Save current order number for this attempt. // AttemptConfigOrder =3D 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 =3D NULL; =20 if (IfrNvData->Enabled =3D=3D ISCSI_ENABLED_FOR_MPIO) { // // This new Attempt is enabled for MPIO; enable the multipath mode. // @@ -886,21 +1136,16 @@ IScsiConvertIfrNvDataToAttemptConfigData ( mPrivate->SinglePathCount++; } =20 IScsiConfigUpdateAttempt (); } + Attempt->SessionConfigData.Enabled =3D IfrNvData->Enabled; =20 // // 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); =20 FreePool (MacString); =20 return gRT->SetVariable ( mPrivate->PortString, @@ -910,114 +1155,755 @@ IScsiConvertIfrNvDataToAttemptConfigData ( Attempt ); } =20 /** - Create Hii Extend Label OpCode as the start opcode and end opcode. It is=20 - a help function. + Convert the IFR data to iSCSI configuration data by keyword. =20 - @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 configurati= on structure. =20 - @retval EFI_OUT_OF_RESOURCES Do not have sufficient resource to finish= this - operation. - @retval EFI_INVALID_PARAMETER Any input parameter is invalid. = =20 + @retval EFI_INVALID_PARAMETER Any input or configured parameter is inva= lid. @retval EFI_SUCCESS The operation is completed successfully. =20 **/ 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 =3D=3D NULL || StartLabel =3D=3D NULL || EndOpCode= Handle =3D=3D NULL || EndLabel =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - *StartOpCodeHandle =3D NULL; - *EndOpCodeHandle =3D NULL; - Status =3D 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; =20 - // - // Initialize the container for dynamic opcodes. - // - *StartOpCodeHandle =3D HiiAllocateOpCodeHandle (); - if (*StartOpCodeHandle =3D=3D NULL) { - return Status; - } + ZeroMem (IScsiName, sizeof (IScsiName)); =20 - *EndOpCodeHandle =3D HiiAllocateOpCodeHandle (); - if (*EndOpCodeHandle =3D=3D NULL) { - goto Exit; - } + if (OffSet < ATTEMPT_BOOTENABLE_VAR_OFFSET) { + return EFI_SUCCESS; =20 - // - // Create Hii Extend Label OpCode as the start opcode. - // - InternalStartLabel =3D (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode ( - *StartOpCodeHandle, - &gEfiIfrTianoGuid, - NULL, - sizeof (EFI_IFR_GUID_LABEL) - ); - if (InternalStartLabel =3D=3D NULL) { - goto Exit; - } - =20 - InternalStartLabel->ExtendOpCode =3D EFI_IFR_EXTEND_OP_LABEL; - InternalStartLabel->Number =3D StartLabelNumber; + } else if ((OffSet >=3D ATTEMPT_BOOTENABLE_VAR_OFFSET) && (OffSet < ATTE= MPT_ADDRESS_TYPE_VAR_OFFSET)) { + AttemptIndex =3D (UINT8) ((OffSet - ATTEMPT_BOOTENABLE_VAR_OFFSET) + 1= ); + Attempt =3D IScsiConfigGetAttemptByConfigIndex (AttemptIndex); + if (Attempt =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + IfrNvData->Enabled =3D IfrNvData->ISCSIBootEnableList[AttemptIndex - 1= ]; + // + // Validate the configuration of attempt. + // + if (IfrNvData->Enabled !=3D ISCSI_DISABLED) { + // + // Check whether this attempt uses NIC which is already used by exis= ting attempt. + // + SameNicAttempt =3D IScsiConfigGetAttemptByNic (Attempt, IfrNvData->E= nabled); + if (SameNicAttempt !=3D NULL) { + AttemptName1 =3D (CHAR16 *) AllocateZeroPool (ATTEMPT_NAME_SIZE * = sizeof (CHAR16)); + if (AttemptName1 =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } =20 - // - // Create Hii Extend Label OpCode as the end opcode. - // - InternalEndLabel =3D (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode ( - *EndOpCodeHandle, - &gEfiIfrTianoGuid, - NULL, - sizeof (EFI_IFR_GUID_LABEL) - ); - if (InternalEndLabel =3D=3D NULL) { - goto Exit; - } + AttemptName2 =3D (CHAR16 *) AllocateZeroPool (ATTEMPT_NAME_SIZE * = sizeof (CHAR16)); + if (AttemptName2 =3D=3D NULL) { + FreePool (AttemptName1); + return EFI_OUT_OF_RESOURCES; + } =20 - InternalEndLabel->ExtendOpCode =3D EFI_IFR_EXTEND_OP_LABEL; - InternalEndLabel->Number =3D LABEL_END; + AsciiStrToUnicodeStrS (Attempt->AttemptName, AttemptName1, ATTEMPT= _NAME_SIZE); + AsciiStrToUnicodeStrS (SameNicAttempt->AttemptName, AttemptName2, = ATTEMPT_NAME_SIZE); =20 - *StartLabel =3D InternalStartLabel; - *EndLabel =3D InternalEndLabel; + UnicodeSPrint ( + mPrivate->PortString, + (UINTN) ISCSI_NAME_IFR_MAX_SIZE, + L"Warning! \"%s\" uses same NIC as Attempt \"%s\".", + AttemptName1, + AttemptName2 + ); =20 - return EFI_SUCCESS; + CreatePopUp ( + EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, + &Key, + mPrivate->PortString, + NULL + ); =20 -Exit: + FreePool (AttemptName1); + FreePool (AttemptName2); + } + } =20 - if (*StartOpCodeHandle !=3D NULL) { - HiiFreeOpCodeHandle (*StartOpCodeHandle); - } + if (IfrNvData->Enabled =3D=3D ISCSI_DISABLED && + Attempt->SessionConfigData.Enabled !=3D ISCSI_DISABLED) { =20 - if (*EndOpCodeHandle !=3D NULL) { - HiiFreeOpCodeHandle (*EndOpCodeHandle); - } - =20 - return Status; -} + // + // User updates the Attempt from "Enabled"/"Enabled for MPIO" to "Di= sabled". + // + if (Attempt->SessionConfigData.Enabled =3D=3D ISCSI_ENABLED_FOR_MPIO= ) { + if (mPrivate->MpioCount < 1) { + return EFI_ABORTED; + } =20 -/** - Callback function when user presses "Add an Attempt". + if (--mPrivate->MpioCount =3D=3D 0) { + mPrivate->EnableMpio =3D FALSE; + } + } else if (Attempt->SessionConfigData.Enabled =3D=3D ISCSI_ENABLED) { + if (mPrivate->SinglePathCount < 1) { + return EFI_ABORTED; + } + mPrivate->SinglePathCount--; + } =20 - @retval EFI_OUT_OF_RESOURCES Does not have sufficient resources to fin= ish this - operation. + } else if (IfrNvData->Enabled =3D=3D ISCSI_ENABLED_FOR_MPIO && + Attempt->SessionConfigData.Enabled =3D=3D ISCSI_ENABLED) { + // + // User updates the Attempt from "Enabled" to "Enabled for MPIO". + // + if (mPrivate->SinglePathCount < 1) { + return EFI_ABORTED; + } + + mPrivate->EnableMpio =3D TRUE; + mPrivate->MpioCount++; + mPrivate->SinglePathCount--; + + } else if (IfrNvData->Enabled =3D=3D ISCSI_ENABLED && + Attempt->SessionConfigData.Enabled =3D=3D ISCSI_ENABLED_FOR= _MPIO) { + // + // User updates the Attempt from "Enabled for MPIO" to "Enabled". + // + if (mPrivate->MpioCount < 1) { + return EFI_ABORTED; + } + + if (--mPrivate->MpioCount =3D=3D 0) { + mPrivate->EnableMpio =3D FALSE; + } + mPrivate->SinglePathCount++; + + } else if (IfrNvData->Enabled !=3D ISCSI_DISABLED && + Attempt->SessionConfigData.Enabled =3D=3D ISCSI_DISABLED) { + // + // User updates the Attempt from "Disabled" to "Enabled"/"Enabled fo= r MPIO". + // + if (IfrNvData->Enabled =3D=3D ISCSI_ENABLED_FOR_MPIO) { + mPrivate->EnableMpio =3D TRUE; + mPrivate->MpioCount++; + + } else if (IfrNvData->Enabled =3D=3D ISCSI_ENABLED) { + mPrivate->SinglePathCount++; + } + } + Attempt->SessionConfigData.Enabled =3D IfrNvData->Enabled; + + } else if ((OffSet >=3D ATTEMPT_ADDRESS_TYPE_VAR_OFFSET) && (OffSet < AT= TEMPT_CONNECT_RETRY_VAR_OFFSET)) { + AttemptIndex =3D (UINT8) ((OffSet - ATTEMPT_ADDRESS_TYPE_VAR_OFFSET) += 1); + Attempt =3D IScsiConfigGetAttemptByConfigIndex (AttemptIndex); + if (Attempt =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + Attempt->SessionConfigData.IpMode =3D IfrNvData->ISCSIIpAddressTypeLis= t[AttemptIndex - 1]; + if (Attempt->SessionConfigData.IpMode < IP_MODE_AUTOCONFIG) { + Attempt->AutoConfigureMode =3D 0; + } + + } else if ((OffSet >=3D ATTEMPT_CONNECT_RETRY_VAR_OFFSET) && (OffSet < A= TTEMPT_CONNECT_TIMEOUT_VAR_OFFSET)) { + AttemptIndex =3D (UINT8) ((OffSet - ATTEMPT_CONNECT_RETRY_VAR_OFFSET) = + 1); + Attempt =3D IScsiConfigGetAttemptByConfigIndex (AttemptIndex); + if (Attempt =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + Attempt->SessionConfigData.ConnectRetryCount =3D IfrNvData->ISCSIConne= ctRetry[AttemptIndex - 1]; + if (Attempt->SessionConfigData.ConnectRetryCount =3D=3D 0) { + Attempt->SessionConfigData.ConnectRetryCount =3D CONNECT_MIN_RETRY; + } + + } else if ((OffSet >=3D ATTEMPT_CONNECT_TIMEOUT_VAR_OFFSET) && (OffSet <= ATTEMPT_INITIATOR_VIA_DHCP_VAR_OFFSET)) { + AttemptIndex =3D (UINT8) ((OffSet - ATTEMPT_CONNECT_TIMEOUT_VAR_OFFSET= ) / 2 + 1); + Attempt =3D IScsiConfigGetAttemptByConfigIndex (AttemptIndex); + if (Attempt =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + Attempt->SessionConfigData.ConnectTimeout =3D IfrNvData->ISCSIConnectT= imeout[AttemptIndex - 1]; + if (Attempt->SessionConfigData.ConnectTimeout =3D=3D 0) { + Attempt->SessionConfigData.ConnectTimeout =3D CONNECT_DEFAULT_TIMEOU= T; + } + + if (Attempt->SessionConfigData.Enabled !=3D 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 100= ms.", + NULL + ); + return EFI_INVALID_PARAMETER; + } + } + + } else if ((OffSet >=3D ATTEMPT_INITIATOR_VIA_DHCP_VAR_OFFSET) && (OffSe= t < ATTEMPT_TARGET_VIA_DHCP_VAR_OFFSET)) { + AttemptIndex =3D (UINT8) ((OffSet - ATTEMPT_INITIATOR_VIA_DHCP_VAR_OFF= SET) + 1); + Attempt =3D IScsiConfigGetAttemptByConfigIndex (AttemptIndex); + if (Attempt =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + Attempt->SessionConfigData.InitiatorInfoFromDhcp =3D IfrNvData->ISCSII= nitiatorInfoViaDHCP[AttemptIndex - 1]; + + } else if ((OffSet >=3D ATTEMPT_TARGET_VIA_DHCP_VAR_OFFSET) && (OffSet <= ATTEMPT_TARGET_TCP_PORT_VAR_OFFSET)) { + AttemptIndex =3D (UINT8) ((OffSet - ATTEMPT_TARGET_VIA_DHCP_VAR_OFFSET= ) + 1); + Attempt =3D IScsiConfigGetAttemptByConfigIndex (AttemptIndex); + if (Attempt =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if ((Attempt->SessionConfigData.IpMode < IP_MODE_AUTOCONFIG) && (Attem= pt->SessionConfigData.InitiatorInfoFromDhcp)) { + Attempt->SessionConfigData.TargetInfoFromDhcp =3D IfrNvData->ISCSITa= rgetInfoViaDHCP[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 >=3D ATTEMPT_TARGET_TCP_PORT_VAR_OFFSET) && (OffSet <= ATTEMPT_AUTHENTICATION_METHOD_VAR_OFFSET)) { + AttemptIndex =3D (UINT8) ((OffSet - ATTEMPT_TARGET_TCP_PORT_VAR_OFFSET= ) / 2 + 1); + Attempt =3D IScsiConfigGetAttemptByConfigIndex (AttemptIndex); + if (Attempt =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + if ((Attempt->SessionConfigData.IpMode < IP_MODE_AUTOCONFIG) && (!Atte= mpt->SessionConfigData.TargetInfoFromDhcp)) { + Attempt->SessionConfigData.TargetPort =3D IfrNvData->ISCSITargetTcpP= ort[AttemptIndex - 1]; + if (Attempt->SessionConfigData.TargetPort =3D=3D 0) { + Attempt->SessionConfigData.TargetPort =3D 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 >=3D ATTEMPT_AUTHENTICATION_METHOD_VAR_OFFSET) && (Of= fSet < ATTEMPT_CHARTYPE_VAR_OFFSET)) { + AttemptIndex =3D (UINT8) ((OffSet - ATTEMPT_AUTHENTICATION_METHOD_VAR_= OFFSET) + 1); + Attempt =3D IScsiConfigGetAttemptByConfigIndex (AttemptIndex); + if (Attempt =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + Attempt->AuthenticationType =3D IfrNvData->ISCSIAuthenticationMethod[A= ttemptIndex - 1]; + + } else if ((OffSet >=3D ATTEMPT_CHARTYPE_VAR_OFFSET) && (OffSet < ATTEMP= T_ISID_VAR_OFFSET)) { + AttemptIndex =3D (UINT8) ((OffSet - ATTEMPT_CHARTYPE_VAR_OFFSET) + 1); + Attempt =3D IScsiConfigGetAttemptByConfigIndex (AttemptIndex); + if (Attempt =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + if (Attempt->AuthenticationType =3D=3D ISCSI_AUTH_TYPE_CHAP) { + Attempt->AuthConfigData.CHAP.CHAPType =3D IfrNvData->ISCSIChapType[A= ttemptIndex - 1]; + } + + } else if (OffSet >=3D ATTEMPT_ISID_VAR_OFFSET) { + Index =3D (UINT8) ((OffSet - ATTEMPT_ISID_VAR_OFFSET) / sizeof (KEYWOR= D_STR)); + AttemptIndex =3D Index + 1; + Attempt =3D IScsiConfigGetAttemptByConfigIndex (AttemptIndex); + if (Attempt =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + OffSet =3D OffSet - Index * sizeof (KEYWORD_STR); + + if ((OffSet >=3D ATTEMPT_ISID_VAR_OFFSET) && (OffSet < ATTEMPT_INITIAT= OR_IP_ADDRESS_VAR_OFFSET)) { + IScsiParseIsIdFromString (IfrNvData->Keyword[Index].ISCSIISID, Attem= pt->SessionConfigData.IsId); + + } else if ((OffSet >=3D ATTEMPT_INITIATOR_IP_ADDRESS_VAR_OFFSET) && (= OffSet < ATTEMPT_INITIATOR_NET_MASK_VAR_OFFSET)) { + if ((Attempt->SessionConfigData.IpMode =3D=3D IP_MODE_IP4) && (!Atte= mpt->SessionConfigData.InitiatorInfoFromDhcp)) { + // + // Config Local ip + // + Status =3D NetLibStrToIp4 (IfrNvData->Keyword[Index].ISCSIInitiato= rIpAddress, &HostIp.v4); + if (EFI_ERROR (Status) || ((Attempt->SessionConfigData.SubnetMask.= Addr[0] !=3D 0) && + !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), NTOHL(*(UINT32*)Att= empt->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 >=3D ATTEMPT_INITIATOR_NET_MASK_VAR_OFFSET) && (Off= Set < ATTEMPT_INITIATOR_GATE_WAY_VAR_OFFSET)) { + if ((Attempt->SessionConfigData.IpMode =3D=3D IP_MODE_IP4) && (!Atte= mpt->SessionConfigData.InitiatorInfoFromDhcp)) { + Status =3D NetLibStrToIp4 (IfrNvData->Keyword[Index].ISCSIInitiato= rNetmask, &SubnetMask.v4); + if (EFI_ERROR (Status) || ((SubnetMask.Addr[0] !=3D 0) && (IScsiGe= tSubnetMaskPrefixLength (&SubnetMask.v4) =3D=3D 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 >=3D ATTEMPT_INITIATOR_GATE_WAY_VAR_OFFSET) && (Off= Set < ATTEMPT_TARGET_NAME_VAR_OFFSET)) { + if ((Attempt->SessionConfigData.IpMode =3D=3D IP_MODE_IP4) && (!Atte= mpt->SessionConfigData.InitiatorInfoFromDhcp)) { + Status =3D NetLibStrToIp4 (IfrNvData->Keyword[Index].ISCSIInitiato= rGateway, &Gateway.v4); + if (EFI_ERROR (Status) || + ((Gateway.Addr[0] !=3D 0) && (Attempt->SessionConfigData.SubnetM= ask.Addr[0] !=3D 0) && + !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), NTOHL(*(UINT32*)At= tempt->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, sizeo= f (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 >=3D ATTEMPT_TARGET_NAME_VAR_OFFSET) && (OffSet < A= TTEMPT_TARGET_IP_ADDRESS_VAR_OFFSET)) { + if ((Attempt->SessionConfigData.IpMode < IP_MODE_AUTOCONFIG) && (!At= tempt->SessionConfigData.TargetInfoFromDhcp)) { + UnicodeStrToAsciiStrS (IfrNvData->Keyword[Index].ISCSITargetName, = IScsiName, ISCSI_NAME_MAX_SIZE); + Status =3D 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 !=3D ISCSI_DISABLED) { + if (Attempt->SessionConfigData.TargetName[0] =3D=3D 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 DHC= P!", + NULL + ); + return EFI_INVALID_PARAMETER; + } + + } else if ((OffSet >=3D ATTEMPT_TARGET_IP_ADDRESS_VAR_OFFSET) && (OffS= et < ATTEMPT_LUN_VAR_OFFSET)) { + if ((Attempt->SessionConfigData.IpMode < IP_MODE_AUTOCONFIG) && (!At= tempt->SessionConfigData.TargetInfoFromDhcp)) { + UnicodeStrToAsciiStrS (IfrNvData->Keyword[Index].ISCSITargetIpAddr= ess, IpString, IP_STR_MAX_SIZE); + Status =3D IScsiAsciiStrToIp (IpString, Attempt->SessionConfigData= .IpMode, &HostIp); + if (EFI_ERROR (Status) || !IpIsUnicast (&HostIp, Attempt->SessionC= onfigData.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 DHC= P!", + NULL + ); + return EFI_INVALID_PARAMETER; + } + + } else if ((OffSet >=3D ATTEMPT_LUN_VAR_OFFSET) && (OffSet < ATTEMPT_C= HAR_USER_NAME_VAR_OFFSET)) { + if ((Attempt->SessionConfigData.IpMode < IP_MODE_AUTOCONFIG) && (Att= empt->SessionConfigData.TargetInfoFromDhcp =3D=3D 0)) { + // + // Config LUN. + // + UnicodeStrToAsciiStrS (IfrNvData->Keyword[Index].ISCSILUN, LunStri= ng, ISCSI_LUN_STR_MAX_LEN); + Status =3D 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 DHC= P!", + NULL + ); + return EFI_INVALID_PARAMETER; + } + + } else if ((OffSet >=3D ATTEMPT_CHAR_USER_NAME_VAR_OFFSET) && (OffSet = < ATTEMPT_CHAR_SECRET_VAR_OFFSET)) { + if (Attempt->AuthenticationType =3D=3D ISCSI_AUTH_TYPE_CHAP) { + UnicodeStrToAsciiStrS ( + IfrNvData->Keyword[Index].ISCSIChapUsername, + Attempt->AuthConfigData.CHAP.CHAPName, + ISCSI_CHAP_NAME_STORAGE + ); + + if (Attempt->SessionConfigData.Enabled !=3D ISCSI_DISABLED) { + if (IfrNvData->CHAPName[0] =3D=3D 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 >=3D ATTEMPT_CHAR_SECRET_VAR_OFFSET) && (OffSet < A= TTEMPT_CHAR_REVERSE_USER_NAME_VAR_OFFSET)) { + if (Attempt->AuthenticationType =3D=3D ISCSI_AUTH_TYPE_CHAP) { + UnicodeStrToAsciiStrS ( + IfrNvData->Keyword[Index].ISCSIChapSecret, + Attempt->AuthConfigData.CHAP.CHAPSecret, + ISCSI_CHAP_SECRET_STORAGE + ); + + if (Attempt->SessionConfigData.Enabled !=3D ISCSI_DISABLED) { + if (IfrNvData->CHAPSecret[0] =3D=3D 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 >=3D ATTEMPT_CHAR_REVERSE_USER_NAME_VAR_OFFSET) && = (OffSet < ATTEMPT_CHAR_REVERSE_SECRET_VAR_OFFSET)) { + if (Attempt->AuthConfigData.CHAP.CHAPType =3D=3D ISCSI_CHAP_MUTUAL) { + UnicodeStrToAsciiStrS ( + IfrNvData->Keyword[Index].ISCSIReverseChapUsername, + Attempt->AuthConfigData.CHAP.ReverseCHAPName, + ISCSI_CHAP_NAME_STORAGE + ); + if (Attempt->SessionConfigData.Enabled !=3D ISCSI_DISABLED) { + if (IfrNvData->ReverseCHAPName[0] =3D=3D 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 Ch= ap Type!", + NULL + ); + return EFI_INVALID_PARAMETER; + } + + } else if (OffSet >=3D ATTEMPT_CHAR_REVERSE_SECRET_VAR_OFFSET) { + if (Attempt->AuthConfigData.CHAP.CHAPType =3D=3D ISCSI_CHAP_MUTUAL) { + UnicodeStrToAsciiStrS ( + IfrNvData->Keyword[Index].ISCSIReverseChapSecret, + Attempt->AuthConfigData.CHAP.ReverseCHAPSecret, + ISCSI_CHAP_SECRET_STORAGE + ); + + if (Attempt->SessionConfigData.Enabled !=3D ISCSI_DISABLED) { + if (IfrNvData->ReverseCHAPSecret[0] =3D=3D 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 Ch= ap 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 =3D=3D NULL || StartLabel =3D=3D NULL || EndOpCode= Handle =3D=3D NULL || EndLabel =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + *StartOpCodeHandle =3D NULL; + *EndOpCodeHandle =3D NULL; + Status =3D EFI_OUT_OF_RESOURCES; + + // + // Initialize the container for dynamic opcodes. + // + *StartOpCodeHandle =3D HiiAllocateOpCodeHandle (); + if (*StartOpCodeHandle =3D=3D NULL) { + return Status; + } + + *EndOpCodeHandle =3D HiiAllocateOpCodeHandle (); + if (*EndOpCodeHandle =3D=3D NULL) { + goto Exit; + } + + // + // Create Hii Extend Label OpCode as the start opcode. + // + InternalStartLabel =3D (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode ( + *StartOpCodeHandle, + &gEfiIfrTianoGuid, + NULL, + sizeof (EFI_IFR_GUID_LABEL) + ); + if (InternalStartLabel =3D=3D NULL) { + goto Exit; + } + + InternalStartLabel->ExtendOpCode =3D EFI_IFR_EXTEND_OP_LABEL; + InternalStartLabel->Number =3D StartLabelNumber; + + // + // Create Hii Extend Label OpCode as the end opcode. + // + InternalEndLabel =3D (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode ( + *EndOpCodeHandle, + &gEfiIfrTianoGuid, + NULL, + sizeof (EFI_IFR_GUID_LABEL) + ); + if (InternalEndLabel =3D=3D NULL) { + goto Exit; + } + + InternalEndLabel->ExtendOpCode =3D EFI_IFR_EXTEND_OP_LABEL; + InternalEndLabel->Number =3D LABEL_END; + + *StartLabel =3D InternalStartLabel; + *EndLabel =3D InternalEndLabel; + + return EFI_SUCCESS; + +Exit: + + if (*StartOpCodeHandle !=3D NULL) { + HiiFreeOpCodeHandle (*StartOpCodeHandle); + } + + if (*EndOpCodeHandle !=3D 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 =3D IScsiCreateOpCode ( + ATTEMPT_ENTRY_LABEL, + &StartOpCodeHandle, + &StartLabel, + &EndOpCodeHandle, + &EndLabel + ); + if (EFI_ERROR (Status)) { + return ; + } + + NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) { + AttemptConfigData =3D NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFI= G_NVDATA, Link); + if (AttemptConfigData->Actived =3D=3D ISCSI_ACTIVE_ENABLED) { + // + // Update Attempt Help Info. + // + UnicodeSPrint (mPrivate->PortString, (UINTN) ISCSI_NAME_IFR_MAX_SIZE= , L"Attempt %d", (UINTN) AttemptConfigData->AttemptConfigIndex); + AttemptConfigData->AttemptTitleToken =3D HiiSetString ( + mCallbackInfo->RegisteredHa= ndle, + 0, + mPrivate->PortString, + NULL + ); + if (AttemptConfigData->AttemptTitleToken =3D=3D 0) { + return ; + } + + HiiCreateGotoOpCode ( + StartOpCodeHandle, // Container for dynami= c 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->AttemptConfi= gIndex) // 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 fin= ish this + operation. @retval EFI_SUCCESS The operation is completed successfully. =20 **/ EFI_STATUS IScsiConfigAddAttempt ( @@ -1107,80 +1993,186 @@ Exit: HiiFreeOpCodeHandle (EndOpCodeHandle); =20 return Status; } =20 - /** - 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 success= fully. + @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. =20 **/ -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; =20 - Status =3D IScsiCreateOpCode ( - ATTEMPT_ENTRY_LABEL, - &StartOpCodeHandle, - &StartLabel, - &EndOpCodeHandle, - &EndLabel - ); - if (EFI_ERROR (Status)) { - return ; + Nic =3D mPrivate->CurrentNic; + NicInfo =3D IScsiGetNicInfoByIndex (Nic); + if (NicInfo =3D=3D NULL) { + return EFI_NOT_FOUND; } =20 - NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) { - AttemptConfigData =3D NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFI= G_NVDATA, Link); + // + // The MAC info will be recorded in Config Data. + // + IScsiMacAddrToStr ( + &NicInfo->PermanentAddress, + NicInfo->HwAddressSize, + NicInfo->VlanId, + MacString + ); + + for (Index =3D 0; Index < PcdGet8 (PcdMaxIScsiAttemptNumber); Index++) { + if (AttemptList[Index] =3D=3D 0) { + continue; + } + + // + // Add the attempt. + // + Number =3D AttemptList[Index]; + + UnicodeSPrint ( + mPrivate->PortString, + (UINTN) ISCSI_NAME_IFR_MAX_SIZE, + L"Attempt %d", + Number + ); + + GetVariable2 ( + mPrivate->PortString, + &gEfiIScsiInitiatorNameProtocolGuid, + (VOID**)&AttemptConfigData, + NULL + ); + if (AttemptConfigData =3D=3D NULL || AttemptConfigData->Actived =3D=3D= ISCSI_ACTIVE_ENABLED) { + return EFI_INVALID_PARAMETER; + } + + AttemptConfigData->Actived =3D ISCSI_ACTIVE_ENABLED; + AttemptConfigData->NicIndex =3D NicInfo->NicIndex; + UnicodeStrToAsciiStrS (MacString, AttemptConfigData->MacString, ISCSI_= MAX_MAC_STRING_LEN); + + // + // Generate OUI-format ISID based on MAC address. + // + CopyMem (AttemptConfigData->SessionConfigData.IsId, &NicInfo->Permanen= tAddress, 6); + AttemptConfigData->SessionConfigData.IsId[0] =3D + (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 versio= n: %s", + MacString, + NicInfo->BusNumber, + NicInfo->DeviceNumber, + NicInfo->FunctionNumber, + IScsiMode, + IpMode + ); + + AttemptConfigData->AttemptTitleHelpToken =3D HiiSetString ( + mCallbackInfo->Registered= Handle, + 0, + mPrivate->PortString, + NULL + ); + if (AttemptConfigData->AttemptTitleHelpToken =3D=3D 0) { + return EFI_OUT_OF_RESOURCES; + } + + // + // Get current Attempt order and number. + // + AttemptConfigOrder =3D IScsiGetVariableAndSize ( + L"AttemptOrder", + &gIScsiConfigGuid, + &AttemptConfigOrderSize + ); + TotalNumber =3D AttemptConfigOrderSize / sizeof (UINT8); + TotalNumber++; + + // + // Append the new created attempt order to the end. + // + AttemptConfigOrderTmp =3D AllocateZeroPool (TotalNumber * sizeof (UINT= 8)); + if (AttemptConfigOrderTmp =3D=3D NULL) { + if (AttemptConfigOrder !=3D NULL) { + FreePool (AttemptConfigOrder); + } + return EFI_OUT_OF_RESOURCES; + } + if (AttemptConfigOrder !=3D NULL) { + CopyMem (AttemptConfigOrderTmp, AttemptConfigOrder, AttemptConfigOrd= erSize); + FreePool (AttemptConfigOrder); + } + + AttemptConfigOrderTmp[TotalNumber - 1] =3D Number; + AttemptConfigOrder =3D AttemptConfigOrderTmp; + AttemptConfigOrderSize =3D TotalNumber * sizeof (UINT8); =20 - AsciiStrToUnicodeStrS (AttemptConfigData->AttemptName, AttemptName, AR= RAY_SIZE (AttemptName)); - UnicodeSPrint (mPrivate->PortString, (UINTN) 128, L"Attempt %s", Attem= ptName); - AttemptConfigData->AttemptTitleToken =3D HiiSetString ( - mCallbackInfo->RegisteredHand= le, - 0, - mPrivate->PortString, - NULL - ); - if (AttemptConfigData->AttemptTitleToken =3D=3D 0) { - return ; + Status =3D gRT->SetVariable ( + L"AttemptOrder", + &gIScsiConfigGuid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOL= ATILE, + AttemptConfigOrderSize, + AttemptConfigOrder + ); + FreePool (AttemptConfigOrder); + if (EFI_ERROR (Status)) { + return Status; } =20 - 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->AttemptConfigI= ndex) // 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 + ); =20 - HiiUpdateForm ( - mCallbackInfo->RegisteredHandle, // HII handle - &gIScsiConfigGuid, // Formset GUID - FORMID_MAIN_FORM, // Form ID - StartOpCodeHandle, // Label for where to insert opcodes - EndOpCodeHandle // Replace data - ); =20 + } =20 - HiiFreeOpCodeHandle (StartOpCodeHandle); - HiiFreeOpCodeHandle (EndOpCodeHandle); + return EFI_SUCCESS; } =20 - /** - 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. =20 @param[in] IfrNvData The IFR NV data. =20 @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 =3D 0; =20 AttemptConfigOrder =3D IScsiGetVariableAndSize ( L"AttemptOrder", &gIScsiConfigGuid, &AttemptConfigOrderSize @@ -1224,11 +2219,10 @@ IScsiConfigDeleteAttempts ( goto Error; } =20 Total =3D AttemptConfigOrderSize / sizeof (UINT8); NewTotal =3D Total; - Index =3D 0; =20 NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &mPrivate->AttemptConfigs) { if (IfrNvData->DeleteAttemptList[Index] =3D=3D 0) { Index++; continue; @@ -1269,26 +2263,48 @@ IScsiConfigDeleteAttempts ( } =20 mPrivate->SinglePathCount--; } =20 - AsciiStrToUnicodeStrS (AttemptConfigData->MacString, MacString, ARRAY_= SIZE (MacString)); + AttemptConfigIndex =3D AttemptConfigData->AttemptConfigIndex; + FreePool (AttemptConfigData); + + // + // Create a new Attempt + // + AttemptConfigData =3D AllocateZeroPool (sizeof (ISCSI_ATTEMPT_CONFIG_N= VDATA)); + if (AttemptConfigData =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + ConfigData =3D &AttemptConfigData->SessionConfigDat= a; + ConfigData->TargetPort =3D ISCSI_WELL_KNOWN_PORT; + ConfigData->ConnectTimeout =3D CONNECT_DEFAULT_TIMEOUT; + ConfigData->ConnectRetryCount =3D CONNECT_MIN_RETRY; + + AttemptConfigData->AuthenticationType =3D ISCSI_AUTH_TYPE_CH= AP; + AttemptConfigData->AuthConfigData.CHAP.CHAPType =3D ISCSI_CHAP_UNI; + // + // Configure the Attempt index and set variable. + // + AttemptConfigData->AttemptConfigIndex =3D AttemptConfigIndex; =20 + // + // 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->Attemp= tName, ATTEMPT_NAME_SIZE); gRT->SetVariable ( mPrivate->PortString, &gEfiIScsiInitiatorNameProtocolGuid, - 0, - 0, - NULL + ISCSI_CONFIG_VAR_ATTR, + sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA), + AttemptConfigData ); =20 // // Mark the attempt order in NVR to be deleted - 0. // @@ -1298,10 +2314,13 @@ IScsiConfigDeleteAttempts ( break; } } =20 NewTotal--; + if (mCallbackInfo->Current =3D=3D AttemptConfigData) { + mCallbackInfo->Current =3D NULL; + } FreePool (AttemptConfigData); =20 // // Check next Attempt. // @@ -1337,11 +2356,11 @@ Error: } =20 if (AttemptNewOrder !=3D NULL) { FreePool (AttemptNewOrder); } - =20 + return Status; } =20 =20 /** @@ -1536,13 +2555,12 @@ Error: } =20 return Status; } =20 - /** - 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. =20 @param[in] IfrNvData The IFR nv data. =20 @retval EFI_OUT_OF_RESOURCES Does not have sufficient resources to fin= ish this operation. @@ -1654,10 +2672,11 @@ Exit: @param[in] IfrNvData The IFR nv data. =20 @retval EFI_OUT_OF_RESOURCES Does not have sufficient resources to fin= ish 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. =20 **/ 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; =20 // // Is User creating a new attempt? // NewAttempt =3D FALSE; @@ -1699,80 +2717,63 @@ IScsiConfigProcessDefault ( // // Don't process anything. // return EFI_SUCCESS; } - =20 - // - // Free any attempt that is previously created but not saved to system. - // - if (mPrivate->NewAttempt !=3D NULL) { - FreePool (mPrivate->NewAttempt); - mPrivate->NewAttempt =3D NULL; - } =20 if (NewAttempt) { // // Determine which NIC user has selected for the new created attempt. // NicIndex =3D (UINT8) (KeyValue - KEY_MAC_ENTRY_BASE); NicInfo =3D IScsiGetNicInfoByIndex (NicIndex); if (NicInfo =3D=3D NULL) { return EFI_NOT_FOUND; } - =20 - // - // Create new attempt. - // - - AttemptConfigData =3D AllocateZeroPool (sizeof (ISCSI_ATTEMPT_CONFIG_N= VDATA)); - if (AttemptConfigData =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - ConfigData =3D &AttemptConfigData->SessionConfigDat= a; - ConfigData->TargetPort =3D ISCSI_WELL_KNOWN_PORT; - ConfigData->ConnectTimeout =3D CONNECT_DEFAULT_TIMEOUT; - ConfigData->ConnectRetryCount =3D CONNECT_MIN_RETRY; - - AttemptConfigData->AuthenticationType =3D ISCSI_AUTH_TYPE_CH= AP; - AttemptConfigData->AuthConfigData.CHAP.CHAPType =3D ISCSI_CHAP_UNI; =20 // - // Get current order number for this attempt. + // Create an attempt following the initialized attempt order. // AttemptConfigOrder =3D IScsiGetVariableAndSize ( - L"AttemptOrder", + L"InitiatorAttemptOrder", &gIScsiConfigGuid, &AttemptConfigOrderSize ); =20 - TotalNumber =3D AttemptConfigOrderSize / sizeof (UINT8); + if (AttemptConfigOrder !=3D NULL) { =20 - if (AttemptConfigOrder =3D=3D NULL) { - CurrentAttemptConfigIndex =3D 1; - } else { - // - // Get the max attempt config index. - // - CurrentAttemptConfigIndex =3D AttemptConfigOrder[0]; - for (Index =3D 1; Index < TotalNumber; Index++) { - if (CurrentAttemptConfigIndex < AttemptConfigOrder[Index]) { - CurrentAttemptConfigIndex =3D AttemptConfigOrder[Index]; + for (Index =3D 0; Index < AttemptConfigOrderSize / sizeof (UINT8); I= ndex++) { + UnicodeSPrint ( + mPrivate->PortString, + (UINTN) ISCSI_NAME_IFR_MAX_SIZE, + L"Attempt %d", + (UINTN) AttemptConfigOrder[Index] + ); + GetVariable2 ( + mPrivate->PortString, + &gEfiIScsiInitiatorNameProtocolGuid, + (VOID**)&AttemptConfigData, + NULL + ); + if (AttemptConfigData =3D=3D NULL || AttemptConfigData->Actived = =3D=3D ISCSI_ACTIVE_ENABLED) { + continue; } + + break; } =20 - CurrentAttemptConfigIndex++; + if (Index > PcdGet8 (PcdMaxIScsiAttemptNumber)) { + CreatePopUp ( + EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, + &Key, + L"Can not create more attempts, Please configure the PcdMaxIScsi= AttemptNumber if needed!", + NULL + ); + return EFI_UNSUPPORTED; + } } =20 - TotalNumber++; - - // - // Record the mapping between attempt order and attempt's configdata. - // - AttemptConfigData->AttemptConfigIndex =3D CurrentAttemptConfigIndex; - if (AttemptConfigOrder !=3D NULL) { FreePool (AttemptConfigOrder); } =20 // @@ -1785,10 +2786,11 @@ IScsiConfigProcessDefault ( MacString ); =20 UnicodeStrToAsciiStrS (MacString, AttemptConfigData->MacString, sizeof= (AttemptConfigData->MacString)); AttemptConfigData->NicIndex =3D NicIndex; + AttemptConfigData->Actived =3D ISCSI_ACTIVE_ENABLED; =20 // // Generate OUI-format ISID based on MAC address. // CopyMem (AttemptConfigData->SessionConfigData.IsId, &NicInfo->Permanen= tAddress, 6); @@ -1814,31 +2816,13 @@ IScsiConfigProcessDefault ( mPrivate->PortString, NULL ); if (AttemptConfigData->AttemptTitleHelpToken =3D=3D 0) { FreePool (AttemptConfigData); - return EFI_INVALID_PARAMETER; + return EFI_OUT_OF_RESOURCES; } =20 - // - // Set the attempt name to default. - // - UnicodeSPrint ( - mPrivate->PortString, - (UINTN) 128, - L"%d", - (UINTN) AttemptConfigData->AttemptConfigIndex - ); - UnicodeStrToAsciiStrS (mPrivate->PortString, AttemptConfigData->Attemp= tName, sizeof (AttemptConfigData->AttemptName)); - - // - // Save the created Attempt temporarily. If user does not save the att= empt - // by press 'KEY_SAVE_ATTEMPT_CONFIG' later, iSCSI driver would know t= hat - // and free resources. - // - mPrivate->NewAttempt =3D (VOID *) AttemptConfigData; - } else { // // Determine which Attempt user has selected to configure. // Get the attempt configuration data. // @@ -1979,15 +2963,21 @@ IScsiFormExtractConfig ( Private =3D ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This); IfrNvData =3D AllocateZeroPool (sizeof (ISCSI_CONFIG_IFR_NVDATA)); if (IfrNvData =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; } - =20 - if (Private->Current !=3D NULL) { + + + if (Private->Current!=3D NULL) { IScsiConvertAttemptConfigDataToIfrNvData (Private->Current, IfrNvData); } =20 + // + // Extract all AttemptConfigData to Keyword stroage of IfrNvData. + // + IScsiConvertAttemptConfigDataToIfrNvDataByKeyword (IfrNvData); + BufferSize =3D ISCSI_NAME_MAX_SIZE; InitiatorName =3D (CHAR8 *) AllocateZeroPool (BufferSize); if (InitiatorName =3D=3D 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 =3D 0; + Index2 =3D 0; + NicInfo =3D NULL; + AttemptList =3D NULL; + if (This =3D=3D NULL || Configuration =3D=3D NULL || Progress =3D=3D NUL= L) { return EFI_INVALID_PARAMETER; } =20 // @@ -2118,14 +3128,184 @@ IScsiFormRouteConfig ( if (!HiiIsConfigHdrMatch (Configuration, &gIScsiConfigGuid, mVendorStora= geName)) { *Progress =3D Configuration; return EFI_NOT_FOUND; } =20 - *Progress =3D Configuration + StrLen (Configuration); - return EFI_SUCCESS; -} + IfrNvData =3D AllocateZeroPool (sizeof (ISCSI_CONFIG_IFR_NVDATA)); + if (IfrNvData =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + BufferSize =3D ISCSI_NAME_MAX_SIZE; + InitiatorName =3D (CHAR8 *) AllocateZeroPool (BufferSize); + if (InitiatorName =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto Exit; + } + + // + // Convert to buffer data by helper function ConfigToBlock(= ). + // + BufferSize =3D sizeof (ISCSI_CONFIG_IFR_NVDATA); + Status =3D gHiiConfigRouting->ConfigToBlock ( + gHiiConfigRouting, + Configuration, + (UINT8 *) IfrNvData, + &BufferSize, + Progress + ); + if (EFI_ERROR (Status)) { + goto Exit; + } + + if (IfrNvData->InitiatorName[0] !=3D L'\0') { + UnicodeStrToAsciiStrS (IfrNvData->InitiatorName, InitiatorName, ISCSI_= NAME_MAX_SIZE); + BufferSize =3D AsciiStrSize (InitiatorName); + + Status =3D gIScsiInitiatorName.Set (&gIScsiInitiatorName, &Buffer= Size, InitiatorName); + if (EFI_ERROR (Status)) { + CreatePopUp ( + EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, + &Key, + L"Invalid iSCSI Name!", + NULL + ); + goto Exit; + } + } else { + Status =3D 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] !=3D L'\0') { + Status =3DIScsiGetAttemptIndexList (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 =3D IScsiConfigAddAttemptsByKeywords (IfrNvData->AddAttemptLi= st); + if (EFI_ERROR (Status)) { + goto Exit; + } + + } else if (IfrNvData->ISCSIDeleteAttemptList[0] !=3D L'\0') { + AttemptList =3D(UINT8 *) AllocateZeroPool ((ISCSI_MAX_ATTEMPTS_NUM += 1) * sizeof (UINT8)); + if (AttemptList =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto Exit; + } + Status =3D IScsiGetAttemptIndexList (IfrNvData->ISCSIDeleteAttemptLi= st, 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 =3D NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_C= ONFIG_NVDATA, Link); + while (AttemptList[Index] !=3D 0) { + if (AttemptConfigData->AttemptConfigIndex =3D=3D AttemptList[Ind= ex]) { + IfrNvData->DeleteAttemptList[Index2] =3D 1; + break; + } + Index ++; + } + Index2 ++; + Index =3D 0; + } + + Status =3D IScsiConfigDeleteAttempts (IfrNvData); + if (EFI_ERROR (Status)) { + goto Exit; + } + + FreePool (AttemptList); + + } else if (IfrNvData->ISCSIAttemptOrder[0] !=3D L'\0') { + Status =3D IScsiGetAttemptIndexList (IfrNvData->ISCSIAttemptOrder, I= frNvData->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 =3D IScsiConfigOrderAttempts (IfrNvData); + if (EFI_ERROR (Status)) { + goto Exit; + } + + } else if (IfrNvData->ISCSIMacAddr[0] !=3D L'\0') { + NET_LIST_FOR_EACH (Entry, &mPrivate->NicInfoList) { + NicInfo =3D NET_LIST_USER_STRUCT (Entry, ISCSI_NIC_INFO, Link); + IScsiMacAddrToStr ( + &NicInfo->PermanentAddress, + NicInfo->HwAddressSize, + NicInfo->VlanId, + MacString + ); + if (!StrCmp(MacString, IfrNvData->ISCSIMacAddr)) { + mPrivate->CurrentNic =3D NicInfo->NicIndex; + break; + } + } + + if ((NicInfo =3D=3D NULL) || (NicInfo->NicIndex =3D=3D 0)) { + Status =3D EFI_NOT_FOUND; + goto Exit; + } + + } else { + Status =3D IScsiGetValue (Configuration, L"&OFFSET=3D", &OffSet); + if (EFI_ERROR (Status)) { + goto Exit; + } + Status =3D IScsiConvertlfrNvDataToAttemptConfigDataByKeyword (IfrNvD= ata, OffSet); + if (EFI_ERROR (Status)) { + goto Exit; + } + } + } + + IScsiConfigUpdateAttempt (); + + Status =3D EFI_SUCCESS; + +Exit: + if (InitiatorName !=3D NULL) { + FreePool (InitiatorName); + } =20 + if (IfrNvData !=3D NULL) { + FreePool (IfrNvData); + } + + return Status; +} =20 /** =20 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; =20 if ((Action =3D=3D EFI_BROWSER_ACTION_FORM_OPEN) || (Action =3D=3D EFI_B= ROWSER_ACTION_FORM_CLOSE)) { // // Do nothing for UEFI OPEN/CLOSE Action @@ -2286,36 +3465,18 @@ IScsiFormCallback ( ); =20 } =20 *ActionRequest =3D 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 (CHAR= 16)); - } else { - CopyMem ( - AttemptName, - IfrNvData->AttemptName, - (StrLen (IfrNvData->AttemptName) + 1) * sizeof (CHAR16) - ); - } - - UnicodeStrToAsciiStrS (IfrNvData->AttemptName, Private->Current->Att= emptName, sizeof (Private->Current->AttemptName)); - - IScsiConfigUpdateAttempt (); - - *ActionRequest =3D EFI_BROWSER_ACTION_REQUEST_FORM_APPLY; - break; =20 case KEY_SAVE_ATTEMPT_CONFIG: Status =3D IScsiConvertIfrNvDataToAttemptConfigData (IfrNvData, Priv= ate->Current); if (EFI_ERROR (Status)) { break; } =20 - *ActionRequest =3D EFI_BROWSER_ACTION_REQUEST_FORM_APPLY; + *ActionRequest =3D EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT; break; =20 case KEY_SAVE_ORDER_CHANGES: // // Sync the Attempt Order to NVR. @@ -2660,17 +3821,10 @@ IScsiConfigFormUnload ( mPrivate->NicCount--; } =20 ASSERT (mPrivate->NicCount =3D=3D 0); =20 - // - // Free attempt is created but not saved to system. - // - if (mPrivate->NewAttempt !=3D NULL) { - FreePool (mPrivate->NewAttempt); - } - FreePool (mPrivate); mPrivate =3D NULL; =20 // // Remove HII package list. diff --git a/NetworkPkg/IScsiDxe/IScsiConfig.h b/NetworkPkg/IScsiDxe/IScsiC= onfig.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. =20 -Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.
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 =20 @@ -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 (DynamicOrderedLis= t) #define DYNAMIC_ORDERED_LIST_VAR_OFFSET VAR_OFFSET (DynamicOrderedLis= t) #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) =20 // -// 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 (ISCSIAtt= emptName) +#define ATTEMPT_ATTEMPT_NAME_VAR_OFFSET VAR_OFFSET (ISCSIAtt= emptName) +#define ATTEMPT_BOOTENABLE_QUESTION_ID QUESTION_ID (ISCSIBoo= tEnableList) +#define ATTEMPT_BOOTENABLE_VAR_OFFSET VAR_OFFSET (ISCSIBoo= tEnableList) +#define ATTEMPT_ADDRESS_TYPE_QUESTION_ID QUESTION_ID (ISCSIIpA= ddressTypeList) +#define ATTEMPT_ADDRESS_TYPE_VAR_OFFSET VAR_OFFSET (ISCSIIpA= ddressTypeList) +#define ATTEMPT_CONNECT_RETRY_QUESTION_ID QUESTION_ID (ISCSICon= nectRetry) +#define ATTEMPT_CONNECT_RETRY_VAR_OFFSET VAR_OFFSET (ISCSICon= nectRetry) +#define ATTEMPT_CONNECT_TIMEOUT_QUESTION_ID QUESTION_ID (ISCSICon= nectTimeout) +#define ATTEMPT_CONNECT_TIMEOUT_VAR_OFFSET VAR_OFFSET (ISCSICon= nectTimeout) +#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 (ISCSIIni= tiatorInfoViaDHCP) +#define ATTEMPT_INITIATOR_VIA_DHCP_VAR_OFFSET VAR_OFFSET (ISCSIIni= tiatorInfoViaDHCP) +#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 (ISCSITar= getInfoViaDHCP) +#define ATTEMPT_TARGET_VIA_DHCP_VAR_OFFSET VAR_OFFSET (ISCSITar= getInfoViaDHCP) +#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 (ISCSITar= getTcpPort) +#define ATTEMPT_TARGET_TCP_PORT_VAR_OFFSET VAR_OFFSET (ISCSITar= getTcpPort) +#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 (ISCSIAut= henticationMethod) +#define ATTEMPT_AUTHENTICATION_METHOD_VAR_OFFSET VAR_OFFSET (ISCSIAut= henticationMethod) +#define ATTEMPT_CHARTYPE_QUESTION_ID QUESTION_ID (ISCSICha= pType) +#define ATTEMPT_CHARTYPE_VAR_OFFSET VAR_OFFSET (ISCSICha= pType) +#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) + =20 #define ISCSI_INITATOR_NAME_VAR_NAME L"I_NAME" =20 #define ISCSI_CONFIG_VAR_ATTR (EFI_VARIABLE_BOOTSERVICE_ACCE= SS | EFI_VARIABLE_NON_VOLATILE) =20 @@ -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; }; =20 /// /// HII specific Vendor Device Path definition. /// @@ -100,10 +145,35 @@ struct _ISCSI_FORM_CALLBACK_INFO { EFI_HII_HANDLE RegisteredHandle; ISCSI_ATTEMPT_CONFIG_NVDATA *Current; }; =20 /** + 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. =20 @param[in] DriverBindingHandle The iSCSI driverbinding handle. =20 @retval EFI_SUCCESS The iSCSI configuration form is initiali= zed. diff --git a/NetworkPkg/IScsiDxe/IScsiConfigNVDataStruc.h b/NetworkPkg/IScs= iDxe/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, EITH= ER EXPRESS OR IMPLIED. #define FORMID_MAC_FORM 2 #define FORMID_ATTEMPT_FORM 3 #define FORMID_ORDER_FORM 4 #define FORMID_DELETE_FORM 5 =20 +#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 =20 -#define ATTEMPT_NAME_MAX_SIZE 96 -#define ATTEMPT_NAME_SIZE 10 +#define ATTEMPT_NAME_LIST_SIZE 96 +#define ATTEMPT_NAME_SIZE 12 =20 #define CONNECT_MIN_RETRY 0 #define CONNECT_MAX_RETRY 16 =20 #define CONNECT_MIN_TIMEOUT 100 #define CONNECT_MAX_TIMEOUT 20000 #define CONNECT_DEFAULT_TIMEOUT 1000 =20 -#define ISCSI_MAX_ATTEMPTS_NUM 255 +#define ISCSI_ACTIVE_DISABLED 0 +#define ISCSI_ACTIVE_ENABLED 1 =20 #define ISCSI_DISABLED 0 #define ISCSI_ENABLED 1 #define ISCSI_ENABLED_FOR_MPIO 2 =20 @@ -65,10 +68,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITH= ER EXPRESS OR IMPLIED. #define IP_MAX_SIZE 39 #define IP_STR_MAX_SIZE 40 =20 #define LUN_MIN_SIZE 1 #define LUN_MAX_SIZE 20 +#define ISCSI_LUN_STR_MAX_LEN 21 =20 #define ISCSI_CHAP_UNI 0 #define ISCSI_CHAP_MUTUAL 1 =20 #define TARGET_PORT_MIN_NUM 0 @@ -110,21 +114,22 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EI= THER 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 =20 -#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 =3D 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 =20 #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, EI= THER EXPRESS OR IMPLIED. =20 #define ISID_CONFIGURABLE_MIN_LEN 6 #define ISID_CONFIGURABLE_MAX_LEN 12 #define ISID_CONFIGURABLE_STORAGE 13 =20 +// +// 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 =20 #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; =20 UINT8 ConnectRetryCount; UINT8 Padding1; @@ -181,11 +208,31 @@ typedef struct _ISCSI_CONFIG_IFR_NVDATA { CHAR16 KerberosKDCIp[IP_STR_MAX_SIZE]; UINT16 KerberosKDCPort; =20 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() =20 #endif diff --git a/NetworkPkg/IScsiDxe/IScsiConfigStrings.uni b/NetworkPkg/IScsiD= xe/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 IM= PLIED. // // Module Name: // // IScsiConfigStrings.uni -//=20 +// // Abstract: -//=20 +// // String definitions for iSCSI configuration. -//=20 +// // Revision History: -//=20 +// // --*/ =20 /=3D# =20 #langdef en-US "English" +#langdef x-UEFI-ns "UefiNameSpace" =20 #string STR_ISCSI_CONFIG_FORM_TITLE #language en-US "iSCSI Configurati= on" =20 #string STR_ISCSI_CONFIG_FORM_HELP #language en-US "Configure the iSC= SI parameters." =20 #string STR_ISCSI_MAIN_FORM_TITLE #language en-US "iSCSI Configurati= on" #string STR_ISCSI_MAC_FORM_TITLE #language en-US "MAC Selection" #string STR_ISCSI_CONFIG_INIT_NAME #language en-US "iSCSI Initiator N= ame" + #language x-UEFI-ns "iSCSIInitiato= rName" #string STR_ISCSI_CONFIG_INIT_NAME_HELP #language en-US "The worldwide uni= que name of iSCSI Initiator. Only IQN format is accepted." #string STR_ISCSI_ATTEMPT_NAME #language en-US "iSCSI Attempt Nam= e" #string STR_ISCSI_ATTEMPT_NAME_HELP #language en-US "The human name de= fined 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 addr= ess 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 repre= sentation 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" = =20 +#string STR_ISCSI_ENABLE_DHCP #language en-US "Enable DHCP" #string STR_ISCSI_ENABLE_DHCP_ON_TARGET #language en-US "Get target info v= ia DHCP" #string STR_CHAP_TYPE_PROMPT #language en-US " CHAP Type" #string STR_CHAP_TYPE_HELP #language en-US "None, One way CHA= P 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 syste= m manually for changes to take place." #string STR_NULL #language en-US "" -#string STR_SAVE_AND_EXIT #language en-US "Commit Changes an= d Exit" =20 -#string STR_NO_SAVE_AND_EXIT #language en-US "Discard Changes a= nd Exit" =20 +#string STR_SAVE_AND_EXIT #language en-US "Commit Changes an= d Exit" +#string STR_NO_SAVE_AND_EXIT #language en-US "Discard Changes a= nd Exit" #string STR_ISCSI_CONFIG_ISID #language en-US "ISID" #string STR_ISCSI_CONFIG_ISID_HELP #language en-US "OUI-format ISID i= n 6 bytes, default value are derived from MAC address. Only last 3 bytes ar= e configurable. Example: update 0ABBCCDDEEFF to 0ABBCCF07901 by input F0790= 1." - - =20 \ 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 "iSCSIAddAttem= pts" +#string STR_ISCSI_DELETE_ATTEMPTS #language en-US "Delete Attempts" + #language x-UEFI-ns "iSCSIDeleteAt= tempts" +#string STR_ISCSI_DISPLAY_ATTEMPTS #language en-US "Display Attempts" + #language x-UEFI-ns "iSCSIDisplayA= ttemptList" +#string STR_ISCSI_ATTEMPT_ORDER #language en-US "New Attempt Order" + #language x-UEFI-ns "iSCSIAttemptO= rder" diff --git a/NetworkPkg/IScsiDxe/IScsiConfigVfr.vfr b/NetworkPkg/IScsiDxe/I= ScsiConfigVfr.vfr index c469a78..d401419 100644 --- a/NetworkPkg/IScsiDxe/IScsiConfigVfr.vfr +++ b/NetworkPkg/IScsiDxe/IScsiConfigVfr.vfr @@ -119,14 +119,14 @@ formset title =3D STRING_TOKEN(STR_ISCSI_ATTEMPT_FORM_TITLE); =20 string varid =3D ISCSI_CONFIG_IFR_NVDATA.AttemptName, prompt =3D STRING_TOKEN(STR_ISCSI_ATTEMPT_NAME), help =3D STRING_TOKEN(STR_ISCSI_ATTEMPT_NAME_HELP), - flags =3D INTERACTIVE, + flags =3D READ_ONLY, key =3D KEY_ATTEMPT_NAME, minsize =3D 0, - maxsize =3D ATTEMPT_NAME_MAX_SIZE, + maxsize =3D ATTEMPT_NAME_SIZE, endstring; =20 subtitle text =3D STRING_TOKEN(STR_NULL); =20 oneof varid =3D ISCSI_CONFIG_IFR_NVDATA.Enabled, @@ -340,10 +340,52 @@ formset maxsize =3D ISCSI_CHAP_SECRET_MAX_LEN, endstring; =20 endif; =20 + suppressif TRUE; + + string varid =3D ISCSI_CONFIG_IFR_NVDATA.ISCSIMacAddr, + prompt =3D STRING_TOKEN(STR_ISCSI_MAC_PROMPT), + help =3D STRING_TOKEN(STR_ISCSI_MAC_PROMPT), + minsize =3D 0, + maxsize =3D ISCSI_MAX_MAC_STRING_LEN, + endstring; + + string varid =3D ISCSI_CONFIG_IFR_NVDATA.ISCSIAttemptOrder, + prompt =3D STRING_TOKEN(STR_ISCSI_ATTEMPT_ORDER), + help =3D STRING_TOKEN(STR_ISCSI_ATTEMPT_ORDER), + minsize =3D 0, + maxsize =3D ATTEMPT_NAME_LIST_SIZE, + endstring; + + string varid =3D ISCSI_CONFIG_IFR_NVDATA.ISCSIAddAttemptList, + prompt =3D STRING_TOKEN(STR_ISCSI_ADD_ATTEMPTS), + help =3D STRING_TOKEN(STR_ISCSI_ADD_ATTEMPTS), + minsize =3D 0, + maxsize =3D ATTEMPT_NAME_LIST_SIZE, + endstring; + + string varid =3D ISCSI_CONFIG_IFR_NVDATA.ISCSIDeleteAttemptList, + prompt =3D STRING_TOKEN(STR_ISCSI_DELETE_ATTEMPTS), + help =3D STRING_TOKEN(STR_ISCSI_DELETE_ATTEMPTS), + minsize =3D 0, + maxsize =3D ATTEMPT_NAME_LIST_SIZE, + endstring; + + string varid =3D ISCSI_CONFIG_IFR_NVDATA.ISCSIDisplayAttemptList, + prompt =3D STRING_TOKEN(STR_ISCSI_DISPLAY_ATTEMPTS), + help =3D STRING_TOKEN(STR_ISCSI_DISPLAY_ATTEMPTS), + flags =3D READ_ONLY, + minsize =3D 0, + maxsize =3D ATTEMPT_NAME_LIST_SIZE, + endstring; + + label KEYWORD_ENTRY_LABEL; + label LABEL_END; + endif; + subtitle text =3D STRING_TOKEN(STR_NULL); =20 text help =3D STRING_TOKEN (STR_SAVE_CHANGES_HELP), text =3D STRING_TOKEN (STR_SAVE_CHANGES), diff --git a/NetworkPkg/IScsiDxe/IScsiDriver.c b/NetworkPkg/IScsiDxe/IScsiD= river.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 ( =20 Session->Private =3D Private; Session->ConfigData =3D AttemptConfigData; Session->AuthType =3D AttemptConfigData->AuthenticationType; =20 - 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 ); =20 if (Session->AuthType =3D=3D ISCSI_AUTH_TYPE_CHAP) { Session->AuthData.CHAP.AuthConfig =3D &AttemptConfigData->AuthConfig= Data.CHAP; @@ -1802,10 +1799,26 @@ IScsiDriverEntryPoint ( if (EFI_ERROR (Status)) { goto Error4; } =20 // + // Create the Maxmum Attempts. + // + Status =3D IScsiCreateAttempts (PcdGet8 (PcdMaxIScsiAttemptNumber)); + if (EFI_ERROR (Status)) { + goto Error5; + } + + // + // Creat Keywords for all the Attempts. + // + Status =3D 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 =3D gBS->LocateProtocol ( &gEfiAuthenticationInfoProtocolGuid, @@ -1818,19 +1831,22 @@ IScsiDriverEntryPoint ( &gEfiAuthenticationInfoProtocolGuid, EFI_NATIVE_INTERFACE, &gIScsiAuthenticationInfo ); if (EFI_ERROR (Status)) { - goto Error5; + goto Error6; } =20 } =20 return EFI_SUCCESS; =20 -Error5: +Error6: IScsiConfigFormUnload (gIScsiIp4DriverBinding.DriverBindingHandle); =20 +Error5: + IScsiCleanAttemptVariable (); + Error4: FreePool (mPrivate); =20 Error3: gBS->UninstallMultipleProtocolInterfaces ( diff --git a/NetworkPkg/IScsiDxe/IScsiDriver.h b/NetworkPkg/IScsiDxe/IScsiD= river.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. =20 -Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.
(C) Copyright 2017 Hewlett Packard Enterprise Development LP
=20 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 save= d. } ISCSI_PRIVATE_DATA; =20 extern ISCSI_PRIVATE_DATA *mPrivate; =20 typedef struct { diff --git a/NetworkPkg/IScsiDxe/IScsiDxe.inf b/NetworkPkg/IScsiDxe/IScsiDx= e.inf index 699ffd1..922f69e 100644 --- a/NetworkPkg/IScsiDxe/IScsiDxe.inf +++ b/NetworkPkg/IScsiDxe/IScsiDxe.inf @@ -126,17 +126,20 @@ gEfiAcpi20TableGuid ## SOMETIMES_CONSUMES ## S= ystemTable gEfiAdapterInfoNetworkBootGuid ## SOMETIMES_CONSUMES ## U= NDEFINED =20 ## SOMETIMES_PRODUCES ## Variable:L"AttemptOrder" ## SOMETIMES_CONSUMES ## Variable:L"AttemptOrder" + ## SOMETIMES_PRODUCES ## Variable:L"InitiatorAttemptOrder" + ## SOMETIMES_CONSUMES ## Variable:L"InitiatorAttemptOrder" ## SOMETIMES_CONSUMES ## UNDEFINED # HiiIsConfigHdrMatch mVendorStorag= eName ## SOMETIMES_PRODUCES ## UNDEFINED # HiiConstructConfigHdr mVendorStorag= eName ## SOMETIMES_PRODUCES ## UNDEFINED # HiiGetBrowserData mVendorStorag= eName ## SOMETIMES_CONSUMES ## UNDEFINED # HiiSetBrowserData mVendorStorag= eName ## SOMETIMES_CONSUMES ## HII gIScsiConfigGuid =20 [Pcd] gEfiNetworkPkgTokenSpaceGuid.PcdIScsiAIPNetworkBootPolicy ## CONSUMES - =20 + gEfiNetworkPkgTokenSpaceGuid.PcdMaxIScsiAttemptNumber ## CONSUMES + [UserExtensions.TianoCore."ExtraFiles"] IScsiDxeExtra.uni diff --git a/NetworkPkg/IScsiDxe/IScsiMisc.c b/NetworkPkg/IScsiDxe/IScsiMis= c.c index e8e8f9c..1cdd4fe 100644 --- a/NetworkPkg/IScsiDxe/IScsiMisc.c +++ b/NetworkPkg/IScsiDxe/IScsiMisc.c @@ -641,21 +641,790 @@ IScsiRemoveNic ( =20 FreePool (AttemptConfigData); } } =20 - // - // Free attempt is created but not saved to system. - // - if (mPrivate->NewAttempt !=3D NULL) { - FreePool (mPrivate->NewAttempt); - mPrivate->NewAttempt =3D 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 successfu= lly. + @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 =3D 1; Index <=3D AttemptNum; Index ++) { + // + // Get the initialized attempt order. This is used to essure creating = attempts by order. + // + AttemptConfigOrder =3D IScsiGetVariableAndSize ( + L"InitiatorAttemptOrder", + &gIScsiConfigGuid, + &AttemptConfigOrderSize + ); + TotalNumber =3D AttemptConfigOrderSize / sizeof (UINT8); + if (TotalNumber =3D=3D AttemptNum) { + Status =3D EFI_SUCCESS; + break; + } + TotalNumber++; + + // + // Append the new created attempt to the end. + // + AttemptOrderTmp =3D AllocateZeroPool (TotalNumber * sizeof (UINT8)); + if (AttemptOrderTmp =3D=3D NULL) { + if (AttemptConfigOrder !=3D NULL) { + FreePool (AttemptConfigOrder); + } + return EFI_OUT_OF_RESOURCES; + } + + if (AttemptConfigOrder !=3D NULL) { + CopyMem (AttemptOrderTmp, AttemptConfigOrder, AttemptConfigOrderSize= ); + FreePool (AttemptConfigOrder); + } + + AttemptOrderTmp[TotalNumber - 1] =3D Index; + AttemptConfigOrder =3D AttemptOrderTmp; + AttemptConfigOrderSize =3D TotalNumber * sizeof (UINT8); + + Status =3D gRT->SetVariable ( + L"InitiatorAttemptOrder", + &gIScsiConfigGuid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOL= ATILE, + AttemptConfigOrderSize, + AttemptConfigOrder + ); + FreePool (AttemptConfigOrder); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Create new Attempt + // + AttemptConfigData =3D AllocateZeroPool (sizeof (ISCSI_ATTEMPT_CONFIG_N= VDATA)); + if (AttemptConfigData =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + ConfigData =3D &AttemptConfigData->SessionConfigDat= a; + ConfigData->TargetPort =3D ISCSI_WELL_KNOWN_PORT; + ConfigData->ConnectTimeout =3D CONNECT_DEFAULT_TIMEOUT; + ConfigData->ConnectRetryCount =3D CONNECT_MIN_RETRY; + + AttemptConfigData->AuthenticationType =3D ISCSI_AUTH_TYPE_CH= AP; + AttemptConfigData->AuthConfigData.CHAP.CHAPType =3D ISCSI_CHAP_UNI; + // + // Configure the Attempt index and set variable. + // + AttemptConfigData->AttemptConfigIndex =3D 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->Attemp= tName, ATTEMPT_NAME_SIZE); + + Status =3D gRT->SetVariable ( + mPrivate->PortString, + &gEfiIScsiInitiatorNameProtocolGuid, + ISCSI_CONFIG_VAR_ATTR, + sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA), + AttemptConfigData + ); + FreePool (AttemptConfigData); + if (EFI_ERROR (Status)) { + return Status; + } } =20 return EFI_SUCCESS; } =20 +/** + Create the iSCSI configuration Keywords for each attempt. + + @param[in] KeywordNum The number Sets of Keywords will be crea= ted. + + @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 =3D IScsiCreateOpCode ( + KEYWORD_ENTRY_LABEL, + &StartOpCodeHandle, + &StartLabel, + &EndOpCodeHandle, + &EndLabel + ); + if (EFI_ERROR (Status)) { + return EFI_OUT_OF_RESOURCES; + } + + for (Index =3D 1; Index <=3D KeywordNum; Index ++) { + // + // Create iSCSIAttemptName Keyword. + // + UnicodeSPrint (StringId, sizeof (StringId), L"STR_ISCSI_ATTEMPTT_NAME_= PROMPT%d", Index); + StringToken =3D 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 * (Ind= ex - 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 =3D HiiSetString ( + mCallbackInfo->RegisteredHandle, + 0, + StringId, + NULL + ); + UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIBootEnable:%d", I= ndex); + 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 =3D 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 =3D 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_TIMEOU= T_PROMPT%d", Index); + StringToken =3D 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 =3D 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 =3D HiiSetString ( + mCallbackInfo->RegisteredHandle, + 0, + StringId, + NULL + ); + UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIInitiatorInfoViaD= HCP:%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_A= DDRESS_PROMPT%d", Index); + StringToken =3D HiiSetString ( + mCallbackInfo->RegisteredHandle, + 0, + StringId, + NULL + ); + UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIInitiatorIpAddres= s:%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 =3D 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_ST= R) * (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 =3D 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_ST= R) * (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_DHC= P_PROMPT%d", Index); + StringToken =3D 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_POR= T_PROMPT%d", Index); + StringToken =3D 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_PR= OMPT%d", Index); + StringToken =3D HiiSetString ( + mCallbackInfo->RegisteredHandle, + 0, + StringId, + NULL + ); + UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSITargetName:%d", I= ndex); + 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) * (I= ndex - 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_ADDR= ESS_PROMPT%d", Index); + StringToken =3D 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 =3D 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 =3D HiiSetString ( + mCallbackInfo->RegisteredHandle, + 0, + StringId, + NULL + ); + UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIAuthenticationMet= hod:%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_PROMP= T%d", Index); + StringToken =3D HiiSetString ( + mCallbackInfo->RegisteredHandle, + 0, + StringId, + NULL + ); + UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIChapType:%d", Ind= ex); + 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 =3D 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_PR= OMPT%d", Index); + StringToken =3D HiiSetString ( + mCallbackInfo->RegisteredHandle, + 0, + StringId, + NULL + ); + UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIChapSecret:%d", I= ndex); + 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) * (I= ndex - 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_U= SER_NAME_PROMPT%d", Index); + StringToken =3D HiiSetString ( + mCallbackInfo->RegisteredHandle, + 0, + StringId, + NULL + ); + UnicodeSPrint (KeywordId, sizeof (KeywordId), L"iSCSIReverseChapUserna= me:%d", Index); + HiiSetString (mCallbackInfo->RegisteredHandle, StringToken, KeywordId,= "x-UEFI-ns"); + HiiCreateStringOpCode ( + StartOpCodeHandle, + (EFI_QUESTION_ID) (ATTEMPT_CHAR_REVERSE_USER_NAME_QUESTION_ID + (Ind= ex - 1)), + CONFIGURATION_VARSTORE_ID, + (UINT16) (ATTEMPT_CHAR_REVERSE_USER_NAME_VAR_OFFSET + sizeof (KEYWOR= D_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_S= ECRET_PROMPT%d", Index); + StringToken =3D 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_S= TR) * (Index - 1)), + StringToken, + StringToken, + 0, + 0, + ISCSI_CHAP_SECRET_MIN_LEN, + ISCSI_CHAP_SECRET_MAX_LEN, + NULL + ); + } + + Status =3D 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 =3D IScsiGetVariableAndSize ( + L"InitiatorAttemptOrder", + &gIScsiConfigGuid, + &AttemptConfigOrderSize + ); + if (AttemptConfigOrder =3D=3D NULL || AttemptConfigOrderSize =3D=3D 0) { + return; + } + + for (Index =3D 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 !=3D NULL) { + gRT->SetVariable ( + mPrivate->PortString, + &gEfiIScsiInitiatorNameProtocolGuid, + 0, + 0, + NULL + ); + } + } + return; +} =20 /** Get the recorded NIC info from global structure by the Index. =20 @param[in] NicIndex The index indicates the position of NIC in= fo. @@ -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]; =20 AttemptConfigOrder =3D IScsiGetVariableAndSize ( L"AttemptOrder", &gIScsiConfigGuid, @@ -957,12 +1727,11 @@ IScsiDhcpIsConfigured ( =20 for (Index =3D 0; Index < AttemptConfigOrderSize / sizeof (UINT8); Index= ++) { UnicodeSPrint ( AttemptName, (UINTN) 128, - L"%s%d", - MacString, + L"Attempt %d", (UINTN) AttemptConfigOrder[Index] ); Status =3D GetVariable2 ( AttemptName, &gEfiIScsiInitiatorNameProtocolGuid, @@ -983,11 +1752,17 @@ IScsiDhcpIsConfigured ( if (AttemptTmp->SessionConfigData.IpMode !=3D IP_MODE_AUTOCONFIG &&=20 AttemptTmp->SessionConfigData.IpMode !=3D ((IpVersion =3D=3D IP_VE= RSION_4) ? IP_MODE_IP4 : IP_MODE_IP6)) { FreePool (AttemptTmp); continue; } - =20 + + AsciiStrToUnicodeStrS (AttemptTmp->MacString, AttemptMacString, sizeof= (AttemptMacString) / sizeof (AttemptMacString[0])); + + if (AttemptTmp->Actived =3D=3D ISCSI_ACTIVE_DISABLED || StrCmp (MacStr= ing, AttemptMacString)) { + continue; + } + if(AttemptTmp->SessionConfigData.IpMode =3D=3D IP_MODE_AUTOCONFIG || AttemptTmp->SessionConfigData.InitiatorInfoFromDhcp =3D=3D TRUE || AttemptTmp->SessionConfigData.TargetInfoFromDhcp =3D=3D TRUE) {=20 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 ( } =20 // // Refresh the state of this attempt to NVR. // - AsciiStrToUnicodeStrS (AttemptTmp->MacString, MacString, ARRAY_S= IZE (MacString)); UnicodeSPrint ( mPrivate->PortString, (UINTN) ISCSI_NAME_IFR_MAX_SIZE, - L"%s%d", - MacString, + L"Attempt %d", (UINTN) AttemptTmp->AttemptConfigIndex ); =20 gRT->SetVariable ( mPrivate->PortString, @@ -1234,16 +2008,14 @@ IScsiGetConfigData ( } =20 // // Refresh the state of this attempt to NVR. // - AsciiStrToUnicodeStrS (AttemptTmp->MacString, MacString, ARRAY_SIZ= E (MacString)); UnicodeSPrint ( mPrivate->PortString, (UINTN) ISCSI_NAME_IFR_MAX_SIZE, - L"%s%d", - MacString, + L"Attempt %d", (UINTN) AttemptTmp->AttemptConfigIndex ); =20 gRT->SetVariable ( mPrivate->PortString, @@ -1267,24 +2039,25 @@ IScsiGetConfigData ( NicInfo =3D IScsiGetNicInfoByIndex (mPrivate->CurrentNic); ASSERT (NicInfo !=3D 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] ); =20 GetVariable2 ( mPrivate->PortString, &gEfiIScsiInitiatorNameProtocolGuid, (VOID**)&AttemptConfigData, NULL ); + AsciiStrToUnicodeStrS (AttemptConfigData->MacString, AttemptMacString,= sizeof (AttemptMacString) / sizeof (AttemptMacString[0])); =20 - if (AttemptConfigData =3D=3D NULL) { + if (AttemptConfigData =3D=3D NULL || AttemptConfigData->Actived =3D=3D= ISCSI_ACTIVE_DISABLED || + StrCmp (MacString, AttemptMacString)) { continue; } =20 ASSERT (AttemptConfigOrder[Index] =3D=3D AttemptConfigData->AttemptCon= figIndex); =20 @@ -1325,16 +2098,14 @@ IScsiGetConfigData ( } =20 // // Refresh the state of this attempt to NVR. // - AsciiStrToUnicodeStrS (AttemptConfigData->MacString, MacString, ARRA= Y_SIZE (MacString)); UnicodeSPrint ( mPrivate->PortString, (UINTN) ISCSI_NAME_IFR_MAX_SIZE, - L"%s%d", - MacString, + L"Attempt %d", (UINTN) AttemptConfigData->AttemptConfigIndex ); =20 gRT->SetVariable ( mPrivate->PortString, diff --git a/NetworkPkg/IScsiDxe/IScsiMisc.h b/NetworkPkg/IScsiDxe/IScsiMis= c.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 ); =20 /** + Create and initialize the Attempts. + + @param[in] AttemptNum The number of Attempts will be created. + + @retval EFI_SUCCESS The Attempts have been created successfu= lly. + @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 crea= ted. + + @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. =20 @param[in] NicIndex The index indicates the position of NIC in= fo. =20 @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 =3D { 0xb0eae4f8, 0x9a04, 0x4c6d, { 0xa7, = 0x48, 0x79, 0x3d, 0xaa, 0xf, 0x65, 0xdf }} =20 # Include/Guid/TlsAuthentication.h gEfiTlsCaCertificateGuid =3D { 0xfd2340D0, 0x3dab, 0x4349, { 0xa6, = 0xc7, 0x3b, 0x4f, 0x12, 0xb4, 0x8e, 0xae }} - =20 + +[PcdsFixedAtBuild] + ## The max attempt number will be created by iSCSI driver. + # @Prompt Max attempt number. + gEfiNetworkPkgTokenSpaceGuid.PcdMaxIScsiAttemptNumber|0x08|UINT8|0x00000= 00D =20 [PcdsFeatureFlag] ## Indicates if the IPsec IKEv2 Certificate Authentication feature is en= abled or not.

# TRUE - Certificate Authentication feature is enabled.
# FALSE - Does not support Certificate Authentication.
--=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel