2 Helper functions for configuring or getting the parameters relating to iSCSI.
4 Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "IScsiImpl.h"
17 CHAR16 mVendorStorageName
[] = L
"ISCSI_CONFIG_IFR_NVDATA";
18 BOOLEAN mIScsiDeviceListUpdated
= FALSE
;
19 UINTN mNumberOfIScsiDevices
= 0;
20 ISCSI_FORM_CALLBACK_INFO
*mCallbackInfo
= NULL
;
22 HII_VENDOR_DEVICE_PATH mIScsiHiiVendorDevicePath
= {
28 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
29 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
36 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
38 (UINT8
) (END_DEVICE_PATH_LENGTH
),
39 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
46 Convert the IP address into a dotted string.
48 @param[in] Ip The IP address.
49 @param[in] Ipv6Flag Indicates whether the IP address is version 4 or version 6.
50 @param[out] Str The formatted IP string.
55 IN EFI_IP_ADDRESS
*Ip
,
60 EFI_IPv4_ADDRESS
*Ip4
;
61 EFI_IPv6_ADDRESS
*Ip6
;
65 CHAR16 FormatString
[8];
72 (UINTN
) 2 * IP4_STR_MAX_SIZE
,
86 for (Index
= 0; Index
< 15; Index
= Index
+ 2) {
89 Ip6
->Addr
[Index
] == 0 &&
90 Ip6
->Addr
[Index
+ 1] == 0
93 // Deal with the case of ::.
104 while ((Index
< 15) && (Ip6
->Addr
[Index
] == 0) && (Ip6
->Addr
[Index
+ 1] == 0)) {
112 // :: is at the end of the address.
121 if (Ip6
->Addr
[Index
] == 0) {
122 Number
= UnicodeSPrint (Str
, 2 * IP_STR_MAX_SIZE
, L
"%x:", (UINTN
) Ip6
->Addr
[Index
+ 1]);
124 if (Ip6
->Addr
[Index
+ 1] < 0x10) {
125 CopyMem (FormatString
, L
"%x0%x:", StrSize (L
"%x0%x:"));
127 CopyMem (FormatString
, L
"%x%x:", StrSize (L
"%x%x:"));
130 Number
= UnicodeSPrint (
133 (CONST CHAR16
*) FormatString
,
134 (UINTN
) Ip6
->Addr
[Index
],
135 (UINTN
) Ip6
->Addr
[Index
+ 1]
141 if (Index
+ 2 == 16) {
143 if (*(Str
- 1) == L
':') {
151 Check whether the input IP address is valid.
153 @param[in] Ip The IP address.
154 @param[in] IpMode Indicates iSCSI running on IP4 or IP6 stack.
156 @retval TRUE The input IP address is valid.
157 @retval FALSE Otherwise
162 IN EFI_IP_ADDRESS
*Ip
,
166 if (IpMode
== IP_MODE_IP4
) {
167 return NetIp4IsUnicast (NTOHL (Ip
->Addr
[0]), 0);
168 } else if (IpMode
== IP_MODE_IP6
) {
169 return NetIp6IsValidUnicast (&Ip
->v6
);
171 DEBUG ((DEBUG_ERROR
, "IpMode %d is invalid when configuring the iSCSI target IP!\n", IpMode
));
177 Parse IsId in string format and convert it to binary.
179 @param[in] String The buffer of the string to be parsed.
180 @param[in, out] IsId The buffer to store IsId.
182 @retval EFI_SUCCESS The operation finished successfully.
183 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
187 IScsiParseIsIdFromString (
188 IN CONST CHAR16
*String
,
196 CHAR16 PortString
[ISCSI_NAME_IFR_MAX_SIZE
];
199 if ((String
== NULL
) || (IsId
== NULL
)) {
200 return EFI_INVALID_PARAMETER
;
203 IsIdStr
= (CHAR16
*) String
;
205 if (StrLen (IsIdStr
) != 6) {
208 (UINTN
) ISCSI_NAME_IFR_MAX_SIZE
,
209 L
"Error! Input is incorrect, please input 6 hex numbers!\n"
213 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
219 return EFI_INVALID_PARAMETER
;
222 for (Index
= 3; Index
< 6; Index
++) {
223 CopyMem (TempStr
, IsIdStr
, sizeof (TempStr
));
227 // Convert the string to IsId. StrHexToUintn stops at the first character
228 // that is not a valid hex character, '\0' here.
230 NodeVal
= StrHexToUintn (TempStr
);
232 IsId
[Index
] = (UINT8
) NodeVal
;
234 IsIdStr
= IsIdStr
+ 2;
241 Convert IsId from binary to string format.
243 @param[out] String The buffer to store the converted string.
244 @param[in] IsId The buffer to store IsId.
246 @retval EFI_SUCCESS The string converted successfully.
247 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
251 IScsiConvertIsIdToString (
259 if ((String
== NULL
) || (IsId
== NULL
)) {
260 return EFI_INVALID_PARAMETER
;
263 for (Index
= 0; Index
< 6; Index
++) {
264 if (IsId
[Index
] <= 0xF) {
265 Number
= UnicodeSPrint (
267 2 * ISID_CONFIGURABLE_STORAGE
,
272 Number
= UnicodeSPrint (
274 2 * ISID_CONFIGURABLE_STORAGE
,
281 String
= String
+ Number
;
290 Get the attempt config data from global structure by the ConfigIndex.
292 @param[in] AttemptConfigIndex The unique index indicates the attempt.
294 @return Pointer to the attempt config data.
295 @retval NULL The attempt configuration data cannot be found.
298 ISCSI_ATTEMPT_CONFIG_NVDATA
*
299 IScsiConfigGetAttemptByConfigIndex (
300 IN UINT8 AttemptConfigIndex
304 ISCSI_ATTEMPT_CONFIG_NVDATA
*Attempt
;
306 NET_LIST_FOR_EACH (Entry
, &mPrivate
->AttemptConfigs
) {
307 Attempt
= NET_LIST_USER_STRUCT (Entry
, ISCSI_ATTEMPT_CONFIG_NVDATA
, Link
);
308 if (Attempt
->AttemptConfigIndex
== AttemptConfigIndex
) {
318 Get the existing attempt config data from global structure by the NicIndex.
320 @param[in] NewAttempt The created new attempt
321 @param[in] IScsiMode The IScsi Mode of the new attempt, Enabled or
324 @return Pointer to the existing attempt config data which
325 has the same NICIndex as the new created attempt.
326 @retval NULL The attempt with NicIndex does not exist.
329 ISCSI_ATTEMPT_CONFIG_NVDATA
*
330 IScsiConfigGetAttemptByNic (
331 IN ISCSI_ATTEMPT_CONFIG_NVDATA
*NewAttempt
,
336 ISCSI_ATTEMPT_CONFIG_NVDATA
*Attempt
;
338 NET_LIST_FOR_EACH (Entry
, &mPrivate
->AttemptConfigs
) {
339 Attempt
= NET_LIST_USER_STRUCT (Entry
, ISCSI_ATTEMPT_CONFIG_NVDATA
, Link
);
340 if (Attempt
!= NewAttempt
&& Attempt
->NicIndex
== NewAttempt
->NicIndex
&&
341 Attempt
->SessionConfigData
.Enabled
== IScsiMode
) {
351 Convert the iSCSI configuration data into the IFR data.
353 @param[in] Attempt The iSCSI attempt config data.
354 @param[in, out] IfrNvData The IFR nv data.
358 IScsiConvertAttemptConfigDataToIfrNvData (
359 IN ISCSI_ATTEMPT_CONFIG_NVDATA
*Attempt
,
360 IN OUT ISCSI_CONFIG_IFR_NVDATA
*IfrNvData
363 ISCSI_SESSION_CONFIG_NVDATA
*SessionConfigData
;
364 ISCSI_CHAP_AUTH_CONFIG_NVDATA
*AuthConfigData
;
368 // Normal session configuration parameters.
370 SessionConfigData
= &Attempt
->SessionConfigData
;
371 IfrNvData
->Enabled
= SessionConfigData
->Enabled
;
372 IfrNvData
->IpMode
= SessionConfigData
->IpMode
;
374 IfrNvData
->InitiatorInfoFromDhcp
= SessionConfigData
->InitiatorInfoFromDhcp
;
375 IfrNvData
->TargetInfoFromDhcp
= SessionConfigData
->TargetInfoFromDhcp
;
376 IfrNvData
->TargetPort
= SessionConfigData
->TargetPort
;
378 if (IfrNvData
->IpMode
== IP_MODE_IP4
) {
379 CopyMem (&Ip
.v4
, &SessionConfigData
->LocalIp
, sizeof (EFI_IPv4_ADDRESS
));
380 IScsiIpToStr (&Ip
, FALSE
, IfrNvData
->LocalIp
);
381 CopyMem (&Ip
.v4
, &SessionConfigData
->SubnetMask
, sizeof (EFI_IPv4_ADDRESS
));
382 IScsiIpToStr (&Ip
, FALSE
, IfrNvData
->SubnetMask
);
383 CopyMem (&Ip
.v4
, &SessionConfigData
->Gateway
, sizeof (EFI_IPv4_ADDRESS
));
384 IScsiIpToStr (&Ip
, FALSE
, IfrNvData
->Gateway
);
385 CopyMem (&Ip
.v4
, &SessionConfigData
->TargetIp
, sizeof (EFI_IPv4_ADDRESS
));
386 IScsiIpToStr (&Ip
, FALSE
, IfrNvData
->TargetIp
);
387 } else if (IfrNvData
->IpMode
== IP_MODE_IP6
) {
388 ZeroMem (IfrNvData
->TargetIp
, sizeof (IfrNvData
->TargetIp
));
389 IP6_COPY_ADDRESS (&Ip
.v6
, &SessionConfigData
->TargetIp
);
390 IScsiIpToStr (&Ip
, TRUE
, IfrNvData
->TargetIp
);
393 AsciiStrToUnicodeStr (SessionConfigData
->TargetName
, IfrNvData
->TargetName
);
394 IScsiLunToUnicodeStr (SessionConfigData
->BootLun
, IfrNvData
->BootLun
);
395 IScsiConvertIsIdToString (IfrNvData
->IsId
, SessionConfigData
->IsId
);
397 IfrNvData
->ConnectRetryCount
= SessionConfigData
->ConnectRetryCount
;
398 IfrNvData
->ConnectTimeout
= SessionConfigData
->ConnectTimeout
;
401 // Authentication parameters.
403 IfrNvData
->AuthenticationType
= Attempt
->AuthenticationType
;
405 if (IfrNvData
->AuthenticationType
== ISCSI_AUTH_TYPE_CHAP
) {
406 AuthConfigData
= &Attempt
->AuthConfigData
.CHAP
;
407 IfrNvData
->CHAPType
= AuthConfigData
->CHAPType
;
408 AsciiStrToUnicodeStr (AuthConfigData
->CHAPName
, IfrNvData
->CHAPName
);
409 AsciiStrToUnicodeStr (AuthConfigData
->CHAPSecret
, IfrNvData
->CHAPSecret
);
410 AsciiStrToUnicodeStr (AuthConfigData
->ReverseCHAPName
, IfrNvData
->ReverseCHAPName
);
411 AsciiStrToUnicodeStr (AuthConfigData
->ReverseCHAPSecret
, IfrNvData
->ReverseCHAPSecret
);
417 AsciiStrToUnicodeStr (Attempt
->AttemptName
, IfrNvData
->AttemptName
);
421 Convert the IFR data to iSCSI configuration data.
423 @param[in] IfrNvData Point to ISCSI_CONFIG_IFR_NVDATA.
424 @param[in, out] Attempt The iSCSI attempt config data.
426 @retval EFI_INVALID_PARAMETER Any input or configured parameter is invalid.
427 @retval EFI_NOT_FOUND Cannot find the corresponding variable.
428 @retval EFI_OUT_OF_RESOURCES The operation is failed due to lack of resources.
429 @retval EFI_ABORTED The operation is aborted.
430 @retval EFI_SUCCESS The operation is completed successfully.
434 IScsiConvertIfrNvDataToAttemptConfigData (
435 IN ISCSI_CONFIG_IFR_NVDATA
*IfrNvData
,
436 IN OUT ISCSI_ATTEMPT_CONFIG_NVDATA
*Attempt
439 EFI_IP_ADDRESS HostIp
;
440 EFI_IP_ADDRESS SubnetMask
;
441 EFI_IP_ADDRESS Gateway
;
443 CHAR16
*AttemptName1
;
444 CHAR16
*AttemptName2
;
445 ISCSI_ATTEMPT_CONFIG_NVDATA
*ExistAttempt
;
446 ISCSI_ATTEMPT_CONFIG_NVDATA
*SameNicAttempt
;
447 CHAR16 IScsiMode
[64];
449 ISCSI_NIC_INFO
*NicInfo
;
451 UINT8
*AttemptConfigOrder
;
452 UINTN AttemptConfigOrderSize
;
453 UINT8
*AttemptOrderTmp
;
457 if (IfrNvData
== NULL
|| Attempt
== NULL
) {
458 return EFI_INVALID_PARAMETER
;
462 // Update those fields which don't have INTERACTIVE attribute.
464 Attempt
->SessionConfigData
.ConnectRetryCount
= IfrNvData
->ConnectRetryCount
;
465 Attempt
->SessionConfigData
.ConnectTimeout
= IfrNvData
->ConnectTimeout
;
466 Attempt
->SessionConfigData
.IpMode
= IfrNvData
->IpMode
;
468 if (IfrNvData
->IpMode
< IP_MODE_AUTOCONFIG
) {
469 Attempt
->SessionConfigData
.InitiatorInfoFromDhcp
= IfrNvData
->InitiatorInfoFromDhcp
;
470 Attempt
->SessionConfigData
.TargetPort
= IfrNvData
->TargetPort
;
472 if (Attempt
->SessionConfigData
.TargetPort
== 0) {
473 Attempt
->SessionConfigData
.TargetPort
= ISCSI_WELL_KNOWN_PORT
;
476 Attempt
->SessionConfigData
.TargetInfoFromDhcp
= IfrNvData
->TargetInfoFromDhcp
;
479 Attempt
->AuthenticationType
= IfrNvData
->AuthenticationType
;
481 if (Attempt
->AuthenticationType
== ISCSI_AUTH_TYPE_CHAP
) {
482 Attempt
->AuthConfigData
.CHAP
.CHAPType
= IfrNvData
->CHAPType
;
486 // Only do full parameter validation if iSCSI is enabled on this device.
488 if (IfrNvData
->Enabled
!= ISCSI_DISABLED
) {
489 if (Attempt
->SessionConfigData
.ConnectTimeout
< CONNECT_MIN_TIMEOUT
) {
491 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
493 L
"Connection Establishing Timeout is less than minimum value 100ms.",
497 return EFI_INVALID_PARAMETER
;
501 // Validate the address configuration of the Initiator if DHCP isn't
504 if (!Attempt
->SessionConfigData
.InitiatorInfoFromDhcp
) {
505 CopyMem (&HostIp
.v4
, &Attempt
->SessionConfigData
.LocalIp
, sizeof (HostIp
.v4
));
506 CopyMem (&SubnetMask
.v4
, &Attempt
->SessionConfigData
.SubnetMask
, sizeof (SubnetMask
.v4
));
507 CopyMem (&Gateway
.v4
, &Attempt
->SessionConfigData
.Gateway
, sizeof (Gateway
.v4
));
509 if ((Gateway
.Addr
[0] != 0)) {
510 if (SubnetMask
.Addr
[0] == 0) {
512 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
514 L
"Gateway address is set but subnet mask is zero.",
518 return EFI_INVALID_PARAMETER
;
519 } else if (!IP4_NET_EQUAL (HostIp
.Addr
[0], Gateway
.Addr
[0], SubnetMask
.Addr
[0])) {
521 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
523 L
"Local IP and Gateway are not in the same subnet.",
527 return EFI_INVALID_PARAMETER
;
532 // Validate target configuration if DHCP isn't deployed.
534 if (!Attempt
->SessionConfigData
.TargetInfoFromDhcp
&& Attempt
->SessionConfigData
.IpMode
< IP_MODE_AUTOCONFIG
) {
535 if (!IpIsUnicast (&Attempt
->SessionConfigData
.TargetIp
, IfrNvData
->IpMode
)) {
537 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
539 L
"Target IP is invalid!",
542 return EFI_INVALID_PARAMETER
;
546 // Validate the authentication info.
548 if (IfrNvData
->AuthenticationType
== ISCSI_AUTH_TYPE_CHAP
) {
549 if ((IfrNvData
->CHAPName
[0] == '\0') || (IfrNvData
->CHAPSecret
[0] == '\0')) {
551 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
553 L
"CHAP Name or CHAP Secret is invalid!",
557 return EFI_INVALID_PARAMETER
;
560 if ((IfrNvData
->CHAPType
== ISCSI_CHAP_MUTUAL
) &&
561 ((IfrNvData
->ReverseCHAPName
[0] == '\0') || (IfrNvData
->ReverseCHAPSecret
[0] == '\0'))
564 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
566 L
"Reverse CHAP Name or Reverse CHAP Secret is invalid!",
569 return EFI_INVALID_PARAMETER
;
574 // Check whether this attempt uses NIC which is already used by existing attempt.
576 SameNicAttempt
= IScsiConfigGetAttemptByNic (Attempt
, IfrNvData
->Enabled
);
577 if (SameNicAttempt
!= NULL
) {
578 AttemptName1
= (CHAR16
*) AllocateZeroPool (ATTEMPT_NAME_MAX_SIZE
* sizeof (CHAR16
));
579 if (AttemptName1
== NULL
) {
580 return EFI_OUT_OF_RESOURCES
;
583 AttemptName2
= (CHAR16
*) AllocateZeroPool (ATTEMPT_NAME_MAX_SIZE
* sizeof (CHAR16
));
584 if (AttemptName2
== NULL
) {
585 FreePool (AttemptName1
);
586 return EFI_OUT_OF_RESOURCES
;
589 AsciiStrToUnicodeStr (Attempt
->AttemptName
, AttemptName1
);
590 if (StrLen (AttemptName1
) > ATTEMPT_NAME_SIZE
) {
591 CopyMem (&AttemptName1
[ATTEMPT_NAME_SIZE
], L
"...", 4 * sizeof (CHAR16
));
594 AsciiStrToUnicodeStr (SameNicAttempt
->AttemptName
, AttemptName2
);
595 if (StrLen (AttemptName2
) > ATTEMPT_NAME_SIZE
) {
596 CopyMem (&AttemptName2
[ATTEMPT_NAME_SIZE
], L
"...", 4 * sizeof (CHAR16
));
600 mPrivate
->PortString
,
601 (UINTN
) ISCSI_NAME_IFR_MAX_SIZE
,
602 L
"Warning! Attempt \"%s\" uses same NIC as Attempt \"%s\".",
608 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
610 mPrivate
->PortString
,
614 FreePool (AttemptName1
);
615 FreePool (AttemptName2
);
620 // Update the iSCSI Mode data and record it in attempt help info.
622 Attempt
->SessionConfigData
.Enabled
= IfrNvData
->Enabled
;
623 if (IfrNvData
->Enabled
== ISCSI_DISABLED
) {
624 UnicodeSPrint (IScsiMode
, 64, L
"Disabled");
625 } else if (IfrNvData
->Enabled
== ISCSI_ENABLED
) {
626 UnicodeSPrint (IScsiMode
, 64, L
"Enabled");
627 } else if (IfrNvData
->Enabled
== ISCSI_ENABLED_FOR_MPIO
) {
628 UnicodeSPrint (IScsiMode
, 64, L
"Enabled for MPIO");
631 if (IfrNvData
->IpMode
== IP_MODE_IP4
) {
632 UnicodeSPrint (IpMode
, 64, L
"IP4");
633 } else if (IfrNvData
->IpMode
== IP_MODE_IP6
) {
634 UnicodeSPrint (IpMode
, 64, L
"IP6");
635 } else if (IfrNvData
->IpMode
== IP_MODE_AUTOCONFIG
) {
636 UnicodeSPrint (IpMode
, 64, L
"Autoconfigure");
639 NicInfo
= IScsiGetNicInfoByIndex (Attempt
->NicIndex
);
640 if (NicInfo
== NULL
) {
641 return EFI_NOT_FOUND
;
644 MacString
= (CHAR16
*) AllocateZeroPool (ISCSI_MAX_MAC_STRING_LEN
* sizeof (CHAR16
));
645 if (MacString
== NULL
) {
646 return EFI_OUT_OF_RESOURCES
;
649 AsciiStrToUnicodeStr (Attempt
->MacString
, MacString
);
652 mPrivate
->PortString
,
653 (UINTN
) ISCSI_NAME_IFR_MAX_SIZE
,
654 L
"MAC: %s, PFA: Bus %d | Dev %d | Func %d, iSCSI mode: %s, IP version: %s",
657 NicInfo
->DeviceNumber
,
658 NicInfo
->FunctionNumber
,
663 Attempt
->AttemptTitleHelpToken
= HiiSetString (
664 mCallbackInfo
->RegisteredHandle
,
665 Attempt
->AttemptTitleHelpToken
,
666 mPrivate
->PortString
,
669 if (Attempt
->AttemptTitleHelpToken
== 0) {
670 FreePool (MacString
);
671 return EFI_OUT_OF_RESOURCES
;
675 // Check whether this attempt is an existing one.
677 ExistAttempt
= IScsiConfigGetAttemptByConfigIndex (Attempt
->AttemptConfigIndex
);
678 if (ExistAttempt
!= NULL
) {
679 ASSERT (ExistAttempt
== Attempt
);
681 if (IfrNvData
->Enabled
== ISCSI_DISABLED
&&
682 Attempt
->SessionConfigData
.Enabled
!= ISCSI_DISABLED
) {
685 // User updates the Attempt from "Enabled"/"Enabled for MPIO" to "Disabled".
687 if (Attempt
->SessionConfigData
.Enabled
== ISCSI_ENABLED_FOR_MPIO
) {
688 if (mPrivate
->MpioCount
< 1) {
692 if (--mPrivate
->MpioCount
== 0) {
693 mPrivate
->EnableMpio
= FALSE
;
695 } else if (Attempt
->SessionConfigData
.Enabled
== ISCSI_ENABLED
) {
696 if (mPrivate
->SinglePathCount
< 1) {
699 mPrivate
->SinglePathCount
--;
702 } else if (IfrNvData
->Enabled
== ISCSI_ENABLED_FOR_MPIO
&&
703 Attempt
->SessionConfigData
.Enabled
== ISCSI_ENABLED
) {
705 // User updates the Attempt from "Enabled" to "Enabled for MPIO".
707 if (mPrivate
->SinglePathCount
< 1) {
711 mPrivate
->EnableMpio
= TRUE
;
712 mPrivate
->MpioCount
++;
713 mPrivate
->SinglePathCount
--;
715 } else if (IfrNvData
->Enabled
== ISCSI_ENABLED
&&
716 Attempt
->SessionConfigData
.Enabled
== ISCSI_ENABLED_FOR_MPIO
) {
718 // User updates the Attempt from "Enabled for MPIO" to "Enabled".
720 if (mPrivate
->MpioCount
< 1) {
724 if (--mPrivate
->MpioCount
== 0) {
725 mPrivate
->EnableMpio
= FALSE
;
727 mPrivate
->SinglePathCount
++;
729 } else if (IfrNvData
->Enabled
!= ISCSI_DISABLED
&&
730 Attempt
->SessionConfigData
.Enabled
== ISCSI_DISABLED
) {
732 // User updates the Attempt from "Disabled" to "Enabled"/"Enabled for MPIO".
734 if (IfrNvData
->Enabled
== ISCSI_ENABLED_FOR_MPIO
) {
735 mPrivate
->EnableMpio
= TRUE
;
736 mPrivate
->MpioCount
++;
738 } else if (IfrNvData
->Enabled
== ISCSI_ENABLED
) {
739 mPrivate
->SinglePathCount
++;
743 } else if (ExistAttempt
== NULL
) {
745 // When a new attempt is created, pointer of the attempt is saved to
746 // mPrivate->NewAttempt, and also saved to mCallbackInfo->Current in
747 // IScsiConfigProcessDefault. If input Attempt does not match any existing
748 // attempt, it should be a new created attempt. Save it to system now.
750 ASSERT (Attempt
== mPrivate
->NewAttempt
);
753 // Save current order number for this attempt.
755 AttemptConfigOrder
= IScsiGetVariableAndSize (
758 &AttemptConfigOrderSize
761 TotalNumber
= AttemptConfigOrderSize
/ sizeof (UINT8
);
765 // Append the new created attempt order to the end.
767 AttemptOrderTmp
= AllocateZeroPool (TotalNumber
* sizeof (UINT8
));
768 if (AttemptOrderTmp
== NULL
) {
769 if (AttemptConfigOrder
!= NULL
) {
770 FreePool (AttemptConfigOrder
);
772 return EFI_OUT_OF_RESOURCES
;
775 if (AttemptConfigOrder
!= NULL
) {
776 CopyMem (AttemptOrderTmp
, AttemptConfigOrder
, AttemptConfigOrderSize
);
777 FreePool (AttemptConfigOrder
);
780 AttemptOrderTmp
[TotalNumber
- 1] = Attempt
->AttemptConfigIndex
;
781 AttemptConfigOrder
= AttemptOrderTmp
;
782 AttemptConfigOrderSize
= TotalNumber
* sizeof (UINT8
);
784 Status
= gRT
->SetVariable (
787 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
788 AttemptConfigOrderSize
,
791 FreePool (AttemptConfigOrder
);
792 if (EFI_ERROR (Status
)) {
797 // Insert new created attempt to array.
799 InsertTailList (&mPrivate
->AttemptConfigs
, &Attempt
->Link
);
800 mPrivate
->AttemptCount
++;
802 // Reset mPrivate->NewAttempt to NULL, which indicates none attempt is created
803 // but not saved now.
805 mPrivate
->NewAttempt
= NULL
;
807 if (IfrNvData
->Enabled
== ISCSI_ENABLED_FOR_MPIO
) {
809 // This new Attempt is enabled for MPIO; enable the multipath mode.
811 mPrivate
->EnableMpio
= TRUE
;
812 mPrivate
->MpioCount
++;
813 } else if (IfrNvData
->Enabled
== ISCSI_ENABLED
) {
814 mPrivate
->SinglePathCount
++;
817 IScsiConfigUpdateAttempt ();
821 // Record the user configuration information in NVR.
824 mPrivate
->PortString
,
825 (UINTN
) ISCSI_NAME_IFR_MAX_SIZE
,
828 (UINTN
) Attempt
->AttemptConfigIndex
831 FreePool (MacString
);
833 return gRT
->SetVariable (
834 mPrivate
->PortString
,
835 &gEfiIScsiInitiatorNameProtocolGuid
,
836 ISCSI_CONFIG_VAR_ATTR
,
837 sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA
),
843 Create Hii Extend Label OpCode as the start opcode and end opcode. It is
846 @param[in] StartLabelNumber The number of start label.
847 @param[out] StartOpCodeHandle Points to the start opcode handle.
848 @param[out] StartLabel Points to the created start opcode.
849 @param[out] EndOpCodeHandle Points to the end opcode handle.
850 @param[out] EndLabel Points to the created end opcode.
852 @retval EFI_OUT_OF_RESOURCES Do not have sufficient resource to finish this
854 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
855 @retval EFI_SUCCESS The operation is completed successfully.
860 IN UINT16 StartLabelNumber
,
861 OUT VOID
**StartOpCodeHandle
,
862 OUT EFI_IFR_GUID_LABEL
**StartLabel
,
863 OUT VOID
**EndOpCodeHandle
,
864 OUT EFI_IFR_GUID_LABEL
**EndLabel
868 EFI_IFR_GUID_LABEL
*InternalStartLabel
;
869 EFI_IFR_GUID_LABEL
*InternalEndLabel
;
871 if (StartOpCodeHandle
== NULL
|| StartLabel
== NULL
|| EndOpCodeHandle
== NULL
|| EndLabel
== NULL
) {
872 return EFI_INVALID_PARAMETER
;
875 *StartOpCodeHandle
= NULL
;
876 *EndOpCodeHandle
= NULL
;
877 Status
= EFI_OUT_OF_RESOURCES
;
880 // Initialize the container for dynamic opcodes.
882 *StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
883 if (*StartOpCodeHandle
== NULL
) {
887 *EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
888 if (*EndOpCodeHandle
== NULL
) {
893 // Create Hii Extend Label OpCode as the start opcode.
895 InternalStartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (
899 sizeof (EFI_IFR_GUID_LABEL
)
901 if (InternalStartLabel
== NULL
) {
905 InternalStartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
906 InternalStartLabel
->Number
= StartLabelNumber
;
909 // Create Hii Extend Label OpCode as the end opcode.
911 InternalEndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (
915 sizeof (EFI_IFR_GUID_LABEL
)
917 if (InternalEndLabel
== NULL
) {
921 InternalEndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
922 InternalEndLabel
->Number
= LABEL_END
;
924 *StartLabel
= InternalStartLabel
;
925 *EndLabel
= InternalEndLabel
;
931 if (*StartOpCodeHandle
!= NULL
) {
932 HiiFreeOpCodeHandle (*StartOpCodeHandle
);
935 if (*EndOpCodeHandle
!= NULL
) {
936 HiiFreeOpCodeHandle (*EndOpCodeHandle
);
943 Callback function when user presses "Add an Attempt".
945 @retval EFI_OUT_OF_RESOURCES Does not have sufficient resources to finish this
947 @retval EFI_SUCCESS The operation is completed successfully.
951 IScsiConfigAddAttempt (
956 ISCSI_NIC_INFO
*NicInfo
;
957 EFI_STRING_ID PortTitleToken
;
958 EFI_STRING_ID PortTitleHelpToken
;
959 CHAR16 MacString
[ISCSI_MAX_MAC_STRING_LEN
];
961 VOID
*StartOpCodeHandle
;
962 EFI_IFR_GUID_LABEL
*StartLabel
;
963 VOID
*EndOpCodeHandle
;
964 EFI_IFR_GUID_LABEL
*EndLabel
;
966 Status
= IScsiCreateOpCode (
973 if (EFI_ERROR (Status
)) {
978 // Ask user to select a MAC for this attempt.
980 NET_LIST_FOR_EACH (Entry
, &mPrivate
->NicInfoList
) {
981 NicInfo
= NET_LIST_USER_STRUCT (Entry
, ISCSI_NIC_INFO
, Link
);
983 &NicInfo
->PermanentAddress
,
984 NicInfo
->HwAddressSize
,
989 UnicodeSPrint (mPrivate
->PortString
, (UINTN
) ISCSI_NAME_IFR_MAX_SIZE
, L
"MAC %s", MacString
);
990 PortTitleToken
= HiiSetString (
991 mCallbackInfo
->RegisteredHandle
,
993 mPrivate
->PortString
,
996 if (PortTitleToken
== 0) {
997 Status
= EFI_INVALID_PARAMETER
;
1002 mPrivate
->PortString
,
1003 (UINTN
) ISCSI_NAME_IFR_MAX_SIZE
,
1004 L
"PFA: Bus %d | Dev %d | Func %d",
1006 NicInfo
->DeviceNumber
,
1007 NicInfo
->FunctionNumber
1009 PortTitleHelpToken
= HiiSetString (mCallbackInfo
->RegisteredHandle
, 0, mPrivate
->PortString
, NULL
);
1010 if (PortTitleHelpToken
== 0) {
1011 Status
= EFI_INVALID_PARAMETER
;
1015 HiiCreateGotoOpCode (
1016 StartOpCodeHandle
, // Container for dynamic created opcodes
1017 FORMID_ATTEMPT_FORM
,
1020 EFI_IFR_FLAG_CALLBACK
, // Question flag
1021 (UINT16
) (KEY_MAC_ENTRY_BASE
+ NicInfo
->NicIndex
)
1025 Status
= HiiUpdateForm (
1026 mCallbackInfo
->RegisteredHandle
, // HII handle
1027 &gIScsiConfigGuid
, // Formset GUID
1028 FORMID_MAC_FORM
, // Form ID
1029 StartOpCodeHandle
, // Label for where to insert opcodes
1030 EndOpCodeHandle
// Replace data
1034 HiiFreeOpCodeHandle (StartOpCodeHandle
);
1035 HiiFreeOpCodeHandle (EndOpCodeHandle
);
1042 Update the MAIN form to display the configured attempts.
1046 IScsiConfigUpdateAttempt (
1050 CHAR16 AttemptName
[ATTEMPT_NAME_MAX_SIZE
];
1052 ISCSI_ATTEMPT_CONFIG_NVDATA
*AttemptConfigData
;
1053 VOID
*StartOpCodeHandle
;
1054 EFI_IFR_GUID_LABEL
*StartLabel
;
1055 VOID
*EndOpCodeHandle
;
1056 EFI_IFR_GUID_LABEL
*EndLabel
;
1059 Status
= IScsiCreateOpCode (
1060 ATTEMPT_ENTRY_LABEL
,
1066 if (EFI_ERROR (Status
)) {
1070 NET_LIST_FOR_EACH (Entry
, &mPrivate
->AttemptConfigs
) {
1071 AttemptConfigData
= NET_LIST_USER_STRUCT (Entry
, ISCSI_ATTEMPT_CONFIG_NVDATA
, Link
);
1073 AsciiStrToUnicodeStr (AttemptConfigData
->AttemptName
, AttemptName
);
1074 UnicodeSPrint (mPrivate
->PortString
, (UINTN
) 128, L
"Attempt %s", AttemptName
);
1075 AttemptConfigData
->AttemptTitleToken
= HiiSetString (
1076 mCallbackInfo
->RegisteredHandle
,
1078 mPrivate
->PortString
,
1081 if (AttemptConfigData
->AttemptTitleToken
== 0) {
1085 HiiCreateGotoOpCode (
1086 StartOpCodeHandle
, // Container for dynamic created opcodes
1087 FORMID_ATTEMPT_FORM
, // Form ID
1088 AttemptConfigData
->AttemptTitleToken
, // Prompt text
1089 AttemptConfigData
->AttemptTitleHelpToken
, // Help text
1090 EFI_IFR_FLAG_CALLBACK
, // Question flag
1091 (UINT16
) (KEY_ATTEMPT_ENTRY_BASE
+ AttemptConfigData
->AttemptConfigIndex
) // Question ID
1096 mCallbackInfo
->RegisteredHandle
, // HII handle
1097 &gIScsiConfigGuid
, // Formset GUID
1098 FORMID_MAIN_FORM
, // Form ID
1099 StartOpCodeHandle
, // Label for where to insert opcodes
1100 EndOpCodeHandle
// Replace data
1103 HiiFreeOpCodeHandle (StartOpCodeHandle
);
1104 HiiFreeOpCodeHandle (EndOpCodeHandle
);
1109 Callback function when user presses "Commit Changes and Exit" in Delete Attempts.
1111 @param[in] IfrNvData The IFR NV data.
1113 @retval EFI_NOT_FOUND Cannot find the corresponding variable.
1114 @retval EFI_SUCCESS The operation is completed successfully.
1115 @retval EFI_ABOTRED This operation is aborted cause of error
1117 @retval EFI_OUT_OF_RESOURCES Fail to finish the operation due to lack of
1122 IScsiConfigDeleteAttempts (
1123 IN ISCSI_CONFIG_IFR_NVDATA
*IfrNvData
1129 ISCSI_ATTEMPT_CONFIG_NVDATA
*AttemptConfigData
;
1130 UINT8
*AttemptConfigOrder
;
1131 UINTN AttemptConfigOrderSize
;
1132 UINT8
*AttemptNewOrder
;
1137 LIST_ENTRY
*NextEntry
;
1138 CHAR16 MacString
[ISCSI_MAX_MAC_STRING_LEN
];
1140 AttemptConfigOrder
= IScsiGetVariableAndSize (
1143 &AttemptConfigOrderSize
1145 if ((AttemptConfigOrder
== NULL
) || (AttemptConfigOrderSize
== 0)) {
1146 return EFI_NOT_FOUND
;
1149 AttemptNewOrder
= AllocateZeroPool (AttemptConfigOrderSize
);
1150 if (AttemptNewOrder
== NULL
) {
1151 Status
= EFI_OUT_OF_RESOURCES
;
1155 Total
= AttemptConfigOrderSize
/ sizeof (UINT8
);
1159 NET_LIST_FOR_EACH_SAFE (Entry
, NextEntry
, &mPrivate
->AttemptConfigs
) {
1160 if (IfrNvData
->DeleteAttemptList
[Index
] == 0) {
1166 // Delete the attempt.
1169 AttemptConfigData
= NET_LIST_USER_STRUCT (Entry
, ISCSI_ATTEMPT_CONFIG_NVDATA
, Link
);
1170 if (AttemptConfigData
== NULL
) {
1171 Status
= EFI_NOT_FOUND
;
1176 // Remove this attempt from UI configured attempt list.
1178 RemoveEntryList (&AttemptConfigData
->Link
);
1179 mPrivate
->AttemptCount
--;
1181 if (AttemptConfigData
->SessionConfigData
.Enabled
== ISCSI_ENABLED_FOR_MPIO
) {
1182 if (mPrivate
->MpioCount
< 1) {
1183 Status
= EFI_ABORTED
;
1188 // No more attempt is enabled for MPIO. Transit the iSCSI mode to single path.
1190 if (--mPrivate
->MpioCount
== 0) {
1191 mPrivate
->EnableMpio
= FALSE
;
1193 } else if (AttemptConfigData
->SessionConfigData
.Enabled
== ISCSI_ENABLED
) {
1194 if (mPrivate
->SinglePathCount
< 1) {
1195 Status
= EFI_ABORTED
;
1199 mPrivate
->SinglePathCount
--;
1202 AsciiStrToUnicodeStr (AttemptConfigData
->MacString
, MacString
);
1205 mPrivate
->PortString
,
1209 (UINTN
) AttemptConfigData
->AttemptConfigIndex
1213 mPrivate
->PortString
,
1214 &gEfiIScsiInitiatorNameProtocolGuid
,
1221 // Mark the attempt order in NVR to be deleted - 0.
1223 for (NewIndex
= 0; NewIndex
< Total
; NewIndex
++) {
1224 if (AttemptConfigOrder
[NewIndex
] == AttemptConfigData
->AttemptConfigIndex
) {
1225 AttemptConfigOrder
[NewIndex
] = 0;
1231 FreePool (AttemptConfigData
);
1234 // Check next Attempt.
1240 // Construct AttemptNewOrder.
1242 for (Index
= 0, NewIndex
= 0; Index
< Total
; Index
++) {
1243 if (AttemptConfigOrder
[Index
] != 0) {
1244 AttemptNewOrder
[NewIndex
] = AttemptConfigOrder
[Index
];
1249 Attribute
= EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
1250 | EFI_VARIABLE_NON_VOLATILE
;
1253 // Update AttemptOrder in NVR.
1255 Status
= gRT
->SetVariable (
1259 NewTotal
* sizeof (UINT8
),
1264 if (AttemptConfigOrder
!= NULL
) {
1265 FreePool (AttemptConfigOrder
);
1268 if (AttemptNewOrder
!= NULL
) {
1269 FreePool (AttemptNewOrder
);
1277 Callback function when user presses "Delete Attempts".
1279 @param[in] IfrNvData The IFR nv data.
1281 @retval EFI_INVALID_PARAMETER Any parameter is invalid.
1282 @retval EFI_BUFFER_TOO_SMALL The buffer in UpdateData is too small.
1283 @retval EFI_SUCCESS The operation is completed successfully.
1287 IScsiConfigDisplayDeleteAttempts (
1288 IN ISCSI_CONFIG_IFR_NVDATA
*IfrNvData
1292 UINT8
*AttemptConfigOrder
;
1293 UINTN AttemptConfigOrderSize
;
1295 ISCSI_ATTEMPT_CONFIG_NVDATA
*AttemptConfigData
;
1297 VOID
*StartOpCodeHandle
;
1298 EFI_IFR_GUID_LABEL
*StartLabel
;
1299 VOID
*EndOpCodeHandle
;
1300 EFI_IFR_GUID_LABEL
*EndLabel
;
1303 Status
= IScsiCreateOpCode (
1310 if (EFI_ERROR (Status
)) {
1314 AttemptConfigOrder
= IScsiGetVariableAndSize (
1317 &AttemptConfigOrderSize
1319 if (AttemptConfigOrder
!= NULL
) {
1321 // Create the check box opcode to be deleted.
1325 NET_LIST_FOR_EACH (Entry
, &mPrivate
->AttemptConfigs
) {
1326 AttemptConfigData
= NET_LIST_USER_STRUCT (Entry
, ISCSI_ATTEMPT_CONFIG_NVDATA
, Link
);
1327 IfrNvData
->DeleteAttemptList
[Index
] = 0x00;
1329 HiiCreateCheckBoxOpCode(
1331 (EFI_QUESTION_ID
) (ATTEMPT_DEL_QUESTION_ID
+ Index
),
1332 CONFIGURATION_VARSTORE_ID
,
1333 (UINT16
) (ATTEMPT_DEL_VAR_OFFSET
+ Index
),
1334 AttemptConfigData
->AttemptTitleToken
,
1335 AttemptConfigData
->AttemptTitleHelpToken
,
1343 if (Index
== ISCSI_MAX_ATTEMPTS_NUM
) {
1348 FreePool (AttemptConfigOrder
);
1351 Status
= HiiUpdateForm (
1352 mCallbackInfo
->RegisteredHandle
, // HII handle
1353 &gIScsiConfigGuid
, // Formset GUID
1354 FORMID_DELETE_FORM
, // Form ID
1355 StartOpCodeHandle
, // Label for where to insert opcodes
1356 EndOpCodeHandle
// Replace data
1359 HiiFreeOpCodeHandle (StartOpCodeHandle
);
1360 HiiFreeOpCodeHandle (EndOpCodeHandle
);
1367 Callback function when user presses "Change Attempt Order".
1369 @retval EFI_INVALID_PARAMETER Any parameter is invalid.
1370 @retval EFI_OUT_OF_RESOURCES Does not have sufficient resources to finish this
1372 @retval EFI_SUCCESS The operation is completed successfully.
1376 IScsiConfigDisplayOrderAttempts (
1383 ISCSI_ATTEMPT_CONFIG_NVDATA
*AttemptConfigData
;
1384 VOID
*StartOpCodeHandle
;
1385 EFI_IFR_GUID_LABEL
*StartLabel
;
1386 VOID
*EndOpCodeHandle
;
1387 EFI_IFR_GUID_LABEL
*EndLabel
;
1388 VOID
*OptionsOpCodeHandle
;
1390 Status
= IScsiCreateOpCode (
1397 if (EFI_ERROR (Status
)) {
1401 OptionsOpCodeHandle
= NULL
;
1404 // If no attempt to be ordered, update the original form and exit.
1406 if (mPrivate
->AttemptCount
== 0) {
1411 // Create Option OpCode.
1413 OptionsOpCodeHandle
= HiiAllocateOpCodeHandle ();
1414 if (OptionsOpCodeHandle
== NULL
) {
1415 Status
= EFI_OUT_OF_RESOURCES
;
1421 NET_LIST_FOR_EACH (Entry
, &mPrivate
->AttemptConfigs
) {
1422 AttemptConfigData
= NET_LIST_USER_STRUCT (Entry
, ISCSI_ATTEMPT_CONFIG_NVDATA
, Link
);
1423 HiiCreateOneOfOptionOpCode (
1424 OptionsOpCodeHandle
,
1425 AttemptConfigData
->AttemptTitleToken
,
1427 EFI_IFR_NUMERIC_SIZE_1
,
1428 AttemptConfigData
->AttemptConfigIndex
1433 ASSERT (Index
== mPrivate
->AttemptCount
);
1435 HiiCreateOrderedListOpCode (
1436 StartOpCodeHandle
, // Container for dynamic created opcodes
1437 DYNAMIC_ORDERED_LIST_QUESTION_ID
, // Question ID
1438 CONFIGURATION_VARSTORE_ID
, // VarStore ID
1439 DYNAMIC_ORDERED_LIST_VAR_OFFSET
, // Offset in Buffer Storage
1440 STRING_TOKEN (STR_ORDER_ATTEMPT_ENTRY
), // Question prompt text
1441 STRING_TOKEN (STR_ORDER_ATTEMPT_ENTRY
), // Question help text
1443 EFI_IFR_UNIQUE_SET
, // Ordered list flag, e.g. EFI_IFR_UNIQUE_SET
1444 EFI_IFR_NUMERIC_SIZE_1
, // Data type of Question value
1445 ISCSI_MAX_ATTEMPTS_NUM
, // Maximum container
1446 OptionsOpCodeHandle
, // Option Opcode list
1447 NULL
// Default Opcode is NULL
1451 Status
= HiiUpdateForm (
1452 mCallbackInfo
->RegisteredHandle
, // HII handle
1453 &gIScsiConfigGuid
, // Formset GUID
1454 FORMID_ORDER_FORM
, // Form ID
1455 StartOpCodeHandle
, // Label for where to insert opcodes
1456 EndOpCodeHandle
// Replace data
1460 HiiFreeOpCodeHandle (StartOpCodeHandle
);
1461 HiiFreeOpCodeHandle (EndOpCodeHandle
);
1462 if (OptionsOpCodeHandle
!= NULL
) {
1463 HiiFreeOpCodeHandle (OptionsOpCodeHandle
);
1471 Callback function when user presses "Commit Changes and Exit" in Change Attempt Order.
1473 @param[in] IfrNvData The IFR nv data.
1475 @retval EFI_OUT_OF_RESOURCES Does not have sufficient resources to finish this
1477 @retval EFI_NOT_FOUND Cannot find the corresponding variable.
1478 @retval EFI_SUCCESS The operation is completed successfully.
1482 IScsiConfigOrderAttempts (
1483 IN ISCSI_CONFIG_IFR_NVDATA
*IfrNvData
1489 UINT8 AttemptConfigIndex
;
1490 ISCSI_ATTEMPT_CONFIG_NVDATA
*AttemptConfigData
;
1491 UINT8
*AttemptConfigOrder
;
1492 UINT8
*AttemptConfigOrderTmp
;
1493 UINTN AttemptConfigOrderSize
;
1495 AttemptConfigOrder
= IScsiGetVariableAndSize (
1498 &AttemptConfigOrderSize
1500 if (AttemptConfigOrder
== NULL
) {
1501 return EFI_NOT_FOUND
;
1504 AttemptConfigOrderTmp
= AllocateZeroPool (AttemptConfigOrderSize
);
1505 if (AttemptConfigOrderTmp
== NULL
) {
1506 Status
= EFI_OUT_OF_RESOURCES
;
1510 for (Index
= 0; Index
< ISCSI_MAX_ATTEMPTS_NUM
; Index
++) {
1512 // The real content ends with 0.
1514 if (IfrNvData
->DynamicOrderedList
[Index
] == 0) {
1518 AttemptConfigIndex
= IfrNvData
->DynamicOrderedList
[Index
];
1519 AttemptConfigData
= IScsiConfigGetAttemptByConfigIndex (AttemptConfigIndex
);
1520 if (AttemptConfigData
== NULL
) {
1521 Status
= EFI_NOT_FOUND
;
1526 // Reorder the Attempt List.
1528 RemoveEntryList (&AttemptConfigData
->Link
);
1529 InsertTailList (&mPrivate
->AttemptConfigs
, &AttemptConfigData
->Link
);
1531 AttemptConfigOrderTmp
[Index
] = AttemptConfigIndex
;
1534 // Mark it to be deleted - 0.
1536 for (Indexj
= 0; Indexj
< AttemptConfigOrderSize
/ sizeof (UINT8
); Indexj
++) {
1537 if (AttemptConfigOrder
[Indexj
] == AttemptConfigIndex
) {
1538 AttemptConfigOrder
[Indexj
] = 0;
1545 // Adjust the attempt order in NVR.
1547 for (; Index
< AttemptConfigOrderSize
/ sizeof (UINT8
); Index
++) {
1548 for (Indexj
= 0; Indexj
< AttemptConfigOrderSize
/ sizeof (UINT8
); Indexj
++) {
1549 if (AttemptConfigOrder
[Indexj
] != 0) {
1550 AttemptConfigOrderTmp
[Index
] = AttemptConfigOrder
[Indexj
];
1551 AttemptConfigOrder
[Indexj
] = 0;
1557 Status
= gRT
->SetVariable (
1560 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
1561 AttemptConfigOrderSize
,
1562 AttemptConfigOrderTmp
1566 if (AttemptConfigOrderTmp
!= NULL
) {
1567 FreePool (AttemptConfigOrderTmp
);
1570 FreePool (AttemptConfigOrder
);
1576 Callback function when a user presses "Attempt *" or when a user selects a NIC to
1577 create the new attempt.
1579 @param[in] KeyValue A unique value which is sent to the original
1580 exporting driver so that it can identify the type
1582 @param[in] IfrNvData The IFR nv data.
1584 @retval EFI_OUT_OF_RESOURCES Does not have sufficient resources to finish this
1586 @retval EFI_NOT_FOUND Cannot find the corresponding variable.
1587 @retval EFI_SUCCESS The operation is completed successfully.
1591 IScsiConfigProcessDefault (
1592 IN EFI_QUESTION_ID KeyValue
,
1593 IN ISCSI_CONFIG_IFR_NVDATA
*IfrNvData
1597 ISCSI_ATTEMPT_CONFIG_NVDATA
*AttemptConfigData
;
1598 ISCSI_SESSION_CONFIG_NVDATA
*ConfigData
;
1599 UINT8 CurrentAttemptConfigIndex
;
1600 ISCSI_NIC_INFO
*NicInfo
;
1602 CHAR16 MacString
[ISCSI_MAX_MAC_STRING_LEN
];
1603 UINT8
*AttemptConfigOrder
;
1604 UINTN AttemptConfigOrderSize
;
1609 // Free any attempt that is previously created but not saved to system.
1611 if (mPrivate
->NewAttempt
!= NULL
) {
1612 FreePool (mPrivate
->NewAttempt
);
1613 mPrivate
->NewAttempt
= NULL
;
1617 // Is User creating a new attempt?
1621 if ((KeyValue
>= KEY_MAC_ENTRY_BASE
) &&
1622 (KeyValue
<= (UINT16
) (mPrivate
->MaxNic
+ KEY_MAC_ENTRY_BASE
))) {
1624 // User has pressed "Add an Attempt" and then selects a NIC.
1627 } else if ((KeyValue
>= KEY_ATTEMPT_ENTRY_BASE
) &&
1628 (KeyValue
< (ISCSI_MAX_ATTEMPTS_NUM
+ KEY_ATTEMPT_ENTRY_BASE
))) {
1631 // User has pressed "Attempt *".
1636 // Don't process anything.
1643 // Determine which NIC user has selected for the new created attempt.
1645 NicIndex
= (UINT8
) (KeyValue
- KEY_MAC_ENTRY_BASE
);
1646 NicInfo
= IScsiGetNicInfoByIndex (NicIndex
);
1647 if (NicInfo
== NULL
) {
1648 return EFI_NOT_FOUND
;
1652 // Create new attempt.
1655 AttemptConfigData
= AllocateZeroPool (sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA
));
1656 if (AttemptConfigData
== NULL
) {
1657 return EFI_OUT_OF_RESOURCES
;
1660 ConfigData
= &AttemptConfigData
->SessionConfigData
;
1661 ConfigData
->TargetPort
= ISCSI_WELL_KNOWN_PORT
;
1662 ConfigData
->ConnectTimeout
= CONNECT_DEFAULT_TIMEOUT
;
1663 ConfigData
->ConnectRetryCount
= CONNECT_MIN_RETRY
;
1665 AttemptConfigData
->AuthenticationType
= ISCSI_AUTH_TYPE_CHAP
;
1666 AttemptConfigData
->AuthConfigData
.CHAP
.CHAPType
= ISCSI_CHAP_UNI
;
1669 // Get current order number for this attempt.
1671 AttemptConfigOrder
= IScsiGetVariableAndSize (
1674 &AttemptConfigOrderSize
1677 TotalNumber
= AttemptConfigOrderSize
/ sizeof (UINT8
);
1679 if (AttemptConfigOrder
== NULL
) {
1680 CurrentAttemptConfigIndex
= 1;
1683 // Get the max attempt config index.
1685 CurrentAttemptConfigIndex
= AttemptConfigOrder
[0];
1686 for (Index
= 1; Index
< TotalNumber
; Index
++) {
1687 if (CurrentAttemptConfigIndex
< AttemptConfigOrder
[Index
]) {
1688 CurrentAttemptConfigIndex
= AttemptConfigOrder
[Index
];
1692 CurrentAttemptConfigIndex
++;
1698 // Record the mapping between attempt order and attempt's configdata.
1700 AttemptConfigData
->AttemptConfigIndex
= CurrentAttemptConfigIndex
;
1702 if (AttemptConfigOrder
!= NULL
) {
1703 FreePool (AttemptConfigOrder
);
1707 // Record the MAC info in Config Data.
1710 &NicInfo
->PermanentAddress
,
1711 NicInfo
->HwAddressSize
,
1716 UnicodeStrToAsciiStr (MacString
, AttemptConfigData
->MacString
);
1717 AttemptConfigData
->NicIndex
= NicIndex
;
1720 // Generate OUI-format ISID based on MAC address.
1722 CopyMem (AttemptConfigData
->SessionConfigData
.IsId
, &NicInfo
->PermanentAddress
, 6);
1723 AttemptConfigData
->SessionConfigData
.IsId
[0] =
1724 (UINT8
) (AttemptConfigData
->SessionConfigData
.IsId
[0] & 0x3F);
1727 // Add the help info for the new attempt.
1730 mPrivate
->PortString
,
1731 (UINTN
) ISCSI_NAME_IFR_MAX_SIZE
,
1732 L
"MAC: %s, PFA: Bus %d | Dev %d | Func %d",
1735 NicInfo
->DeviceNumber
,
1736 NicInfo
->FunctionNumber
1739 AttemptConfigData
->AttemptTitleHelpToken
= HiiSetString (
1740 mCallbackInfo
->RegisteredHandle
,
1742 mPrivate
->PortString
,
1745 if (AttemptConfigData
->AttemptTitleHelpToken
== 0) {
1746 FreePool (AttemptConfigData
);
1747 return EFI_INVALID_PARAMETER
;
1751 // Set the attempt name to default.
1754 mPrivate
->PortString
,
1757 (UINTN
) AttemptConfigData
->AttemptConfigIndex
1759 UnicodeStrToAsciiStr (mPrivate
->PortString
, AttemptConfigData
->AttemptName
);
1762 // Save the created Attempt temporarily. If user does not save the attempt
1763 // by press 'KEY_SAVE_ATTEMPT_CONFIG' later, iSCSI driver would know that
1764 // and free resources.
1766 mPrivate
->NewAttempt
= (VOID
*) AttemptConfigData
;
1770 // Determine which Attempt user has selected to configure.
1771 // Get the attempt configuration data.
1773 CurrentAttemptConfigIndex
= (UINT8
) (KeyValue
- KEY_ATTEMPT_ENTRY_BASE
);
1775 AttemptConfigData
= IScsiConfigGetAttemptByConfigIndex (CurrentAttemptConfigIndex
);
1776 if (AttemptConfigData
== NULL
) {
1777 DEBUG ((DEBUG_ERROR
, "Corresponding configuration data can not be retrieved!\n"));
1778 return EFI_NOT_FOUND
;
1783 // Clear the old IFR data to avoid sharing it with other attempts.
1785 if (IfrNvData
->AuthenticationType
== ISCSI_AUTH_TYPE_CHAP
) {
1786 ZeroMem (IfrNvData
->CHAPName
, sizeof (IfrNvData
->CHAPName
));
1787 ZeroMem (IfrNvData
->CHAPSecret
, sizeof (IfrNvData
->CHAPSecret
));
1788 ZeroMem (IfrNvData
->ReverseCHAPName
, sizeof (IfrNvData
->ReverseCHAPName
));
1789 ZeroMem (IfrNvData
->ReverseCHAPSecret
, sizeof (IfrNvData
->ReverseCHAPSecret
));
1792 IScsiConvertAttemptConfigDataToIfrNvData (AttemptConfigData
, IfrNvData
);
1795 // Update current attempt to be a new created attempt or an existing attempt.
1797 mCallbackInfo
->Current
= AttemptConfigData
;
1805 This function allows the caller to request the current
1806 configuration for one or more named elements. The resulting
1807 string is in <ConfigAltResp> format. Also, any and all alternative
1808 configuration strings shall be appended to the end of the
1809 current configuration string. If they are, they must appear
1810 after the current configuration. They must contain the same
1811 routing (GUID, NAME, PATH) as the current configuration string.
1812 They must have an additional description indicating the type of
1813 alternative configuration the string represents,
1814 "ALTCFG=<StringToken>". That <StringToken> (when
1815 converted from Hex UNICODE to binary) is a reference to a
1816 string in the associated string pack.
1818 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1820 @param[in] Request A null-terminated Unicode string in
1821 <ConfigRequest> format. Note that this
1822 includes the routing information as well as
1823 the configurable name / value pairs. It is
1824 invalid for this string to be in
1825 <MultiConfigRequest> format.
1827 @param[out] Progress On return, points to a character in the
1828 Request string. Points to the string's null
1829 terminator if request was successful. Points
1830 to the most recent "&" before the first
1831 failing name / value pair (or the beginning
1832 of the string if the failure is in the first
1833 name / value pair) if the request was not successful.
1835 @param[out] Results A null-terminated Unicode string in
1836 <ConfigAltResp> format which has all values
1837 filled in for the names in the Request string.
1838 String to be allocated by the called function.
1840 @retval EFI_SUCCESS The Results string is filled with the
1841 values corresponding to all requested
1844 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
1845 parts of the results that must be
1846 stored awaiting possible future
1849 @retval EFI_INVALID_PARAMETER For example, passing in a NULL
1850 for the Request parameter
1851 would result in this type of
1852 error. In this case, the
1853 Progress parameter would be
1856 @retval EFI_NOT_FOUND Routing data doesn't match any
1857 known driver. Progress set to the
1858 first character in the routing header.
1859 Note: There is no requirement that the
1860 driver validate the routing data. It
1861 must skip the <ConfigHdr> in order to
1864 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set
1865 to most recent "&" before the
1866 error or the beginning of the
1869 @retval EFI_INVALID_PARAMETER Unknown name. Progress points
1870 to the & before the name in
1876 IScsiFormExtractConfig (
1877 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1878 IN CONST EFI_STRING Request
,
1879 OUT EFI_STRING
*Progress
,
1880 OUT EFI_STRING
*Results
1884 CHAR8
*InitiatorName
;
1886 ISCSI_CONFIG_IFR_NVDATA
*IfrNvData
;
1887 ISCSI_FORM_CALLBACK_INFO
*Private
;
1888 EFI_STRING ConfigRequestHdr
;
1889 EFI_STRING ConfigRequest
;
1890 BOOLEAN AllocatedRequest
;
1893 if (This
== NULL
|| Progress
== NULL
|| Results
== NULL
) {
1894 return EFI_INVALID_PARAMETER
;
1897 *Progress
= Request
;
1898 if ((Request
!= NULL
) && !HiiIsConfigHdrMatch (Request
, &gIScsiConfigGuid
, mVendorStorageName
)) {
1899 return EFI_NOT_FOUND
;
1902 ConfigRequestHdr
= NULL
;
1903 ConfigRequest
= NULL
;
1904 AllocatedRequest
= FALSE
;
1907 Private
= ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This
);
1908 IfrNvData
= AllocateZeroPool (sizeof (ISCSI_CONFIG_IFR_NVDATA
));
1909 if (IfrNvData
== NULL
) {
1910 return EFI_OUT_OF_RESOURCES
;
1913 if (Private
->Current
!= NULL
) {
1914 IScsiConvertAttemptConfigDataToIfrNvData (Private
->Current
, IfrNvData
);
1917 BufferSize
= ISCSI_NAME_MAX_SIZE
;
1918 InitiatorName
= (CHAR8
*) AllocateZeroPool (BufferSize
);
1919 if (InitiatorName
== NULL
) {
1920 FreePool (IfrNvData
);
1921 return EFI_OUT_OF_RESOURCES
;
1924 Status
= gIScsiInitiatorName
.Get (&gIScsiInitiatorName
, &BufferSize
, InitiatorName
);
1925 if (EFI_ERROR (Status
)) {
1926 IfrNvData
->InitiatorName
[0] = L
'\0';
1928 AsciiStrToUnicodeStr (InitiatorName
, IfrNvData
->InitiatorName
);
1932 // Convert buffer data to <ConfigResp> by helper function BlockToConfig().
1934 BufferSize
= sizeof (ISCSI_CONFIG_IFR_NVDATA
);
1935 ConfigRequest
= Request
;
1936 if ((Request
== NULL
) || (StrStr (Request
, L
"OFFSET") == NULL
)) {
1938 // Request has no request element, construct full request string.
1939 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
1940 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
1942 ConfigRequestHdr
= HiiConstructConfigHdr (&gIScsiConfigGuid
, mVendorStorageName
, Private
->DriverHandle
);
1943 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
1944 ConfigRequest
= AllocateZeroPool (Size
);
1945 ASSERT (ConfigRequest
!= NULL
);
1946 AllocatedRequest
= TRUE
;
1947 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, (UINT64
)BufferSize
);
1948 FreePool (ConfigRequestHdr
);
1951 Status
= gHiiConfigRouting
->BlockToConfig (
1954 (UINT8
*) IfrNvData
,
1959 FreePool (IfrNvData
);
1960 FreePool (InitiatorName
);
1963 // Free the allocated config request string.
1965 if (AllocatedRequest
) {
1966 FreePool (ConfigRequest
);
1967 ConfigRequest
= NULL
;
1970 // Set Progress string to the original request string.
1972 if (Request
== NULL
) {
1974 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
1975 *Progress
= Request
+ StrLen (Request
);
1984 This function applies changes in a driver's configuration.
1985 Input is a Configuration, which has the routing data for this
1986 driver followed by name / value configuration pairs. The driver
1987 must apply those pairs to its configurable storage. If the
1988 driver's configuration is stored in a linear block of data
1989 and the driver's name / value pairs are in <BlockConfig>
1990 format, it may use the ConfigToBlock helper function (above) to
1993 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1995 @param[in] Configuration A null-terminated Unicode string in
1996 <ConfigString> format.
1998 @param[out] Progress A pointer to a string filled in with the
1999 offset of the most recent '&' before the
2000 first failing name / value pair (or the
2001 beginning of the string if the failure
2002 is in the first name / value pair) or
2003 the terminating NULL if all was
2006 @retval EFI_SUCCESS The results have been distributed or are
2007 awaiting distribution.
2009 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
2010 parts of the results that must be
2011 stored awaiting possible future
2014 @retval EFI_INVALID_PARAMETERS Passing in a NULL for the
2015 Results parameter would result
2016 in this type of error.
2018 @retval EFI_NOT_FOUND Target for the specified routing data
2024 IScsiFormRouteConfig (
2025 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
2026 IN CONST EFI_STRING Configuration
,
2027 OUT EFI_STRING
*Progress
2030 if (This
== NULL
|| Configuration
== NULL
|| Progress
== NULL
) {
2031 return EFI_INVALID_PARAMETER
;
2035 // Check routing data in <ConfigHdr>.
2036 // Note: if only one Storage is used, then this checking could be skipped.
2038 if (!HiiIsConfigHdrMatch (Configuration
, &gIScsiConfigGuid
, mVendorStorageName
)) {
2039 *Progress
= Configuration
;
2040 return EFI_NOT_FOUND
;
2043 *Progress
= Configuration
+ StrLen (Configuration
);
2050 This function is called to provide results data to the driver.
2051 This data consists of a unique key that is used to identify
2052 which data is either being passed back or being asked for.
2054 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
2055 @param[in] Action Specifies the type of action taken by the browser.
2056 @param[in] QuestionId A unique value which is sent to the original
2057 exporting driver so that it can identify the type
2058 of data to expect. The format of the data tends to
2059 vary based on the opcode that generated the callback.
2060 @param[in] Type The type of value for the question.
2061 @param[in, out] Value A pointer to the data being sent to the original
2063 @param[out] ActionRequest On return, points to the action requested by the
2066 @retval EFI_SUCCESS The callback successfully handled the action.
2067 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
2068 variable and its data.
2069 @retval EFI_DEVICE_ERROR The variable could not be saved.
2070 @retval EFI_UNSUPPORTED The specified Action is not supported by the
2076 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
2077 IN EFI_BROWSER_ACTION Action
,
2078 IN EFI_QUESTION_ID QuestionId
,
2080 IN OUT EFI_IFR_TYPE_VALUE
*Value
,
2081 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
2084 ISCSI_FORM_CALLBACK_INFO
*Private
;
2087 CHAR8 IpString
[IP_STR_MAX_SIZE
];
2088 CHAR8 LunString
[ISCSI_LUN_STR_MAX_LEN
];
2090 EFI_IP_ADDRESS HostIp
;
2091 EFI_IP_ADDRESS SubnetMask
;
2092 EFI_IP_ADDRESS Gateway
;
2093 ISCSI_CONFIG_IFR_NVDATA
*IfrNvData
;
2094 ISCSI_CONFIG_IFR_NVDATA OldIfrNvData
;
2096 CHAR16 AttemptName
[ATTEMPT_NAME_SIZE
+ 4];
2099 if ((Action
== EFI_BROWSER_ACTION_FORM_OPEN
) || (Action
== EFI_BROWSER_ACTION_FORM_CLOSE
)) {
2101 // Do nothing for UEFI OPEN/CLOSE Action
2106 if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
2107 if (This
== NULL
|| Value
== NULL
|| ActionRequest
== NULL
) {
2108 return EFI_INVALID_PARAMETER
;
2111 Private
= ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This
);
2114 // Retrieve uncommitted data from Browser
2117 BufferSize
= sizeof (ISCSI_CONFIG_IFR_NVDATA
);
2118 IfrNvData
= AllocateZeroPool (BufferSize
);
2119 if (IfrNvData
== NULL
) {
2120 return EFI_OUT_OF_RESOURCES
;
2123 IScsiName
= (CHAR8
*) AllocateZeroPool (ISCSI_NAME_MAX_SIZE
);
2124 if (IScsiName
== NULL
) {
2125 FreePool (IfrNvData
);
2126 return EFI_OUT_OF_RESOURCES
;
2129 Status
= EFI_SUCCESS
;
2131 ZeroMem (&OldIfrNvData
, BufferSize
);
2133 HiiGetBrowserData (NULL
, NULL
, BufferSize
, (UINT8
*) IfrNvData
);
2135 CopyMem (&OldIfrNvData
, IfrNvData
, BufferSize
);
2137 switch (QuestionId
) {
2138 case KEY_INITIATOR_NAME
:
2139 UnicodeStrToAsciiStr (IfrNvData
->InitiatorName
, IScsiName
);
2140 BufferSize
= AsciiStrSize (IScsiName
);
2142 Status
= gIScsiInitiatorName
.Set (&gIScsiInitiatorName
, &BufferSize
, IScsiName
);
2143 if (EFI_ERROR (Status
)) {
2145 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
2147 L
"Invalid iSCSI Name!",
2152 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
2155 case KEY_ADD_ATTEMPT
:
2156 Status
= IScsiConfigAddAttempt ();
2159 case KEY_DELETE_ATTEMPT
:
2161 OldIfrNvData
.DeleteAttemptList
,
2162 IfrNvData
->DeleteAttemptList
,
2163 sizeof (IfrNvData
->DeleteAttemptList
)
2165 Status
= IScsiConfigDisplayDeleteAttempts (IfrNvData
);
2168 case KEY_SAVE_DELETE_ATTEMPT
:
2170 // Delete the Attempt Order from NVR
2172 Status
= IScsiConfigDeleteAttempts (IfrNvData
);
2173 if (EFI_ERROR (Status
)) {
2177 IScsiConfigUpdateAttempt ();
2178 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
2181 case KEY_IGNORE_DELETE_ATTEMPT
:
2183 IfrNvData
->DeleteAttemptList
,
2184 OldIfrNvData
.DeleteAttemptList
,
2185 sizeof (IfrNvData
->DeleteAttemptList
)
2187 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD
;
2190 case KEY_ORDER_ATTEMPT_CONFIG
:
2192 // Order the attempt according to user input.
2195 OldIfrNvData
.DynamicOrderedList
,
2196 IfrNvData
->DynamicOrderedList
,
2197 sizeof (IfrNvData
->DynamicOrderedList
)
2199 IScsiConfigDisplayOrderAttempts ();
2202 case KEY_SAVE_ORDER_CHANGES
:
2204 // Sync the Attempt Order to NVR.
2206 Status
= IScsiConfigOrderAttempts (IfrNvData
);
2207 if (EFI_ERROR (Status
)) {
2211 IScsiConfigUpdateAttempt ();
2212 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
2215 case KEY_IGNORE_ORDER_CHANGES
:
2217 IfrNvData
->DynamicOrderedList
,
2218 OldIfrNvData
.DynamicOrderedList
,
2219 sizeof (IfrNvData
->DynamicOrderedList
)
2221 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD
;
2224 case KEY_ATTEMPT_NAME
:
2225 if (StrLen (IfrNvData
->AttemptName
) > ATTEMPT_NAME_SIZE
) {
2226 CopyMem (AttemptName
, IfrNvData
->AttemptName
, ATTEMPT_NAME_SIZE
* sizeof (CHAR16
));
2227 CopyMem (&AttemptName
[ATTEMPT_NAME_SIZE
], L
"...", 4 * sizeof (CHAR16
));
2231 IfrNvData
->AttemptName
,
2232 (StrLen (IfrNvData
->AttemptName
) + 1) * sizeof (CHAR16
)
2236 UnicodeStrToAsciiStr (IfrNvData
->AttemptName
, Private
->Current
->AttemptName
);
2238 IScsiConfigUpdateAttempt ();
2240 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
2244 switch (Value
->u8
) {
2246 ZeroMem (IfrNvData
->TargetIp
, sizeof (IfrNvData
->TargetIp
));
2247 IScsiIpToStr (&Private
->Current
->SessionConfigData
.TargetIp
, TRUE
, IfrNvData
->TargetIp
);
2248 Private
->Current
->AutoConfigureMode
= 0;
2252 ZeroMem (IfrNvData
->TargetIp
, sizeof (IfrNvData
->TargetIp
));
2253 IScsiIpToStr (&Private
->Current
->SessionConfigData
.TargetIp
, FALSE
, IfrNvData
->TargetIp
);
2254 Private
->Current
->AutoConfigureMode
= 0;
2262 Status
= NetLibStrToIp4 (IfrNvData
->LocalIp
, &HostIp
.v4
);
2263 if (EFI_ERROR (Status
) || !NetIp4IsUnicast (NTOHL (HostIp
.Addr
[0]), 0)) {
2265 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
2267 L
"Invalid IP address!",
2271 Status
= EFI_INVALID_PARAMETER
;
2273 CopyMem (&Private
->Current
->SessionConfigData
.LocalIp
, &HostIp
.v4
, sizeof (HostIp
.v4
));
2278 case KEY_SUBNET_MASK
:
2279 Status
= NetLibStrToIp4 (IfrNvData
->SubnetMask
, &SubnetMask
.v4
);
2280 if (EFI_ERROR (Status
) || ((SubnetMask
.Addr
[0] != 0) && (IScsiGetSubnetMaskPrefixLength (&SubnetMask
.v4
) == 0))) {
2282 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
2284 L
"Invalid Subnet Mask!",
2288 Status
= EFI_INVALID_PARAMETER
;
2290 CopyMem (&Private
->Current
->SessionConfigData
.SubnetMask
, &SubnetMask
.v4
, sizeof (SubnetMask
.v4
));
2296 Status
= NetLibStrToIp4 (IfrNvData
->Gateway
, &Gateway
.v4
);
2297 if (EFI_ERROR (Status
) || ((Gateway
.Addr
[0] != 0) && !NetIp4IsUnicast (NTOHL (Gateway
.Addr
[0]), 0))) {
2299 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
2301 L
"Invalid Gateway!",
2304 Status
= EFI_INVALID_PARAMETER
;
2306 CopyMem (&Private
->Current
->SessionConfigData
.Gateway
, &Gateway
.v4
, sizeof (Gateway
.v4
));
2312 UnicodeStrToAsciiStr (IfrNvData
->TargetIp
, IpString
);
2313 Status
= IScsiAsciiStrToIp (IpString
, IfrNvData
->IpMode
, &HostIp
);
2314 if (EFI_ERROR (Status
) || !IpIsUnicast (&HostIp
, IfrNvData
->IpMode
)) {
2316 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
2318 L
"Invalid IP address!",
2321 Status
= EFI_INVALID_PARAMETER
;
2323 CopyMem (&Private
->Current
->SessionConfigData
.TargetIp
, &HostIp
, sizeof (HostIp
));
2328 case KEY_TARGET_NAME
:
2329 UnicodeStrToAsciiStr (IfrNvData
->TargetName
, IScsiName
);
2330 Status
= IScsiNormalizeName (IScsiName
, AsciiStrLen (IScsiName
));
2331 if (EFI_ERROR (Status
)) {
2333 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
2335 L
"Invalid iSCSI Name!",
2339 AsciiStrCpy (Private
->Current
->SessionConfigData
.TargetName
, IScsiName
);
2344 case KEY_DHCP_ENABLE
:
2345 if (IfrNvData
->InitiatorInfoFromDhcp
== 0) {
2346 IfrNvData
->TargetInfoFromDhcp
= 0;
2352 UnicodeStrToAsciiStr (IfrNvData
->BootLun
, LunString
);
2353 Status
= IScsiAsciiStrToLun (LunString
, (UINT8
*) &Lun
);
2354 if (EFI_ERROR (Status
)) {
2356 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
2358 L
"Invalid LUN string!",
2362 CopyMem (Private
->Current
->SessionConfigData
.BootLun
, &Lun
, sizeof (Lun
));
2368 switch (Value
->u8
) {
2369 case ISCSI_AUTH_TYPE_CHAP
:
2370 IfrNvData
->CHAPType
= ISCSI_CHAP_UNI
;
2379 UnicodeStrToAsciiStr (
2380 IfrNvData
->CHAPName
,
2381 Private
->Current
->AuthConfigData
.CHAP
.CHAPName
2385 case KEY_CHAP_SECRET
:
2386 UnicodeStrToAsciiStr (
2387 IfrNvData
->CHAPSecret
,
2388 Private
->Current
->AuthConfigData
.CHAP
.CHAPSecret
2392 case KEY_REVERSE_CHAP_NAME
:
2393 UnicodeStrToAsciiStr (
2394 IfrNvData
->ReverseCHAPName
,
2395 Private
->Current
->AuthConfigData
.CHAP
.ReverseCHAPName
2399 case KEY_REVERSE_CHAP_SECRET
:
2400 UnicodeStrToAsciiStr (
2401 IfrNvData
->ReverseCHAPSecret
,
2402 Private
->Current
->AuthConfigData
.CHAP
.ReverseCHAPSecret
2406 case KEY_CONFIG_ISID
:
2407 IScsiParseIsIdFromString (IfrNvData
->IsId
, Private
->Current
->SessionConfigData
.IsId
);
2408 IScsiConvertIsIdToString (IfrNvData
->IsId
, Private
->Current
->SessionConfigData
.IsId
);
2412 case KEY_SAVE_ATTEMPT_CONFIG
:
2413 Status
= IScsiConvertIfrNvDataToAttemptConfigData (IfrNvData
, Private
->Current
);
2414 if (EFI_ERROR (Status
)) {
2418 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
2422 Status
= IScsiConfigProcessDefault (QuestionId
, IfrNvData
);
2426 if (!EFI_ERROR (Status
)) {
2428 // Pass changed uncommitted data back to Form Browser.
2430 BufferSize
= sizeof (ISCSI_CONFIG_IFR_NVDATA
);
2431 HiiSetBrowserData (NULL
, NULL
, BufferSize
, (UINT8
*) IfrNvData
, NULL
);
2434 FreePool (IfrNvData
);
2435 FreePool (IScsiName
);
2441 // All other action return unsupported.
2443 return EFI_UNSUPPORTED
;
2448 Initialize the iSCSI configuration form.
2450 @param[in] DriverBindingHandle The iSCSI driverbinding handle.
2452 @retval EFI_SUCCESS The iSCSI configuration form is initialized.
2453 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
2457 IScsiConfigFormInit (
2458 IN EFI_HANDLE DriverBindingHandle
2462 ISCSI_FORM_CALLBACK_INFO
*CallbackInfo
;
2464 CallbackInfo
= (ISCSI_FORM_CALLBACK_INFO
*) AllocateZeroPool (sizeof (ISCSI_FORM_CALLBACK_INFO
));
2465 if (CallbackInfo
== NULL
) {
2466 return EFI_OUT_OF_RESOURCES
;
2469 CallbackInfo
->Signature
= ISCSI_FORM_CALLBACK_INFO_SIGNATURE
;
2470 CallbackInfo
->Current
= NULL
;
2472 CallbackInfo
->ConfigAccess
.ExtractConfig
= IScsiFormExtractConfig
;
2473 CallbackInfo
->ConfigAccess
.RouteConfig
= IScsiFormRouteConfig
;
2474 CallbackInfo
->ConfigAccess
.Callback
= IScsiFormCallback
;
2477 // Install Device Path Protocol and Config Access protocol to driver handle.
2479 Status
= gBS
->InstallMultipleProtocolInterfaces (
2480 &CallbackInfo
->DriverHandle
,
2481 &gEfiDevicePathProtocolGuid
,
2482 &mIScsiHiiVendorDevicePath
,
2483 &gEfiHiiConfigAccessProtocolGuid
,
2484 &CallbackInfo
->ConfigAccess
,
2487 ASSERT_EFI_ERROR (Status
);
2490 // Publish our HII data.
2492 CallbackInfo
->RegisteredHandle
= HiiAddPackages (
2494 CallbackInfo
->DriverHandle
,
2499 if (CallbackInfo
->RegisteredHandle
== NULL
) {
2500 gBS
->UninstallMultipleProtocolInterfaces (
2501 &CallbackInfo
->DriverHandle
,
2502 &gEfiDevicePathProtocolGuid
,
2503 &mIScsiHiiVendorDevicePath
,
2504 &gEfiHiiConfigAccessProtocolGuid
,
2505 &CallbackInfo
->ConfigAccess
,
2508 FreePool(CallbackInfo
);
2509 return EFI_OUT_OF_RESOURCES
;
2512 mCallbackInfo
= CallbackInfo
;
2519 Unload the iSCSI configuration form, this includes: delete all the iSCSI
2520 configuration entries, uninstall the form callback protocol, and
2521 free the resources used.
2523 @param[in] DriverBindingHandle The iSCSI driverbinding handle.
2525 @retval EFI_SUCCESS The iSCSI configuration form is unloaded.
2526 @retval Others Failed to unload the form.
2530 IScsiConfigFormUnload (
2531 IN EFI_HANDLE DriverBindingHandle
2534 ISCSI_ATTEMPT_CONFIG_NVDATA
*AttemptConfigData
;
2535 ISCSI_NIC_INFO
*NicInfo
;
2539 while (!IsListEmpty (&mPrivate
->AttemptConfigs
)) {
2540 Entry
= NetListRemoveHead (&mPrivate
->AttemptConfigs
);
2541 AttemptConfigData
= NET_LIST_USER_STRUCT (Entry
, ISCSI_ATTEMPT_CONFIG_NVDATA
, Link
);
2542 FreePool (AttemptConfigData
);
2543 mPrivate
->AttemptCount
--;
2546 ASSERT (mPrivate
->AttemptCount
== 0);
2548 while (!IsListEmpty (&mPrivate
->NicInfoList
)) {
2549 Entry
= NetListRemoveHead (&mPrivate
->NicInfoList
);
2550 NicInfo
= NET_LIST_USER_STRUCT (Entry
, ISCSI_NIC_INFO
, Link
);
2552 mPrivate
->NicCount
--;
2555 ASSERT (mPrivate
->NicCount
== 0);
2558 // Free attempt is created but not saved to system.
2560 if (mPrivate
->NewAttempt
!= NULL
) {
2561 FreePool (mPrivate
->NewAttempt
);
2564 FreePool (mPrivate
);
2568 // Remove HII package list.
2570 HiiRemovePackages (mCallbackInfo
->RegisteredHandle
);
2573 // Uninstall Device Path Protocol and Config Access protocol.
2575 Status
= gBS
->UninstallMultipleProtocolInterfaces (
2576 mCallbackInfo
->DriverHandle
,
2577 &gEfiDevicePathProtocolGuid
,
2578 &mIScsiHiiVendorDevicePath
,
2579 &gEfiHiiConfigAccessProtocolGuid
,
2580 &mCallbackInfo
->ConfigAccess
,
2584 FreePool (mCallbackInfo
);