2 Miscellaneous routines for iSCSI driver.
4 Copyright (c) 2004 - 2017, 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 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 IScsiHexString
[] = "0123456789ABCDEFabcdef";
20 Removes (trims) specified leading and trailing characters from a string.
22 @param[in, out] Str Pointer to the null-terminated string to be trimmed.
23 On return, Str will hold the trimmed string.
25 @param[in] CharC Character will be trimmed from str.
42 // Trim off the leading and trailing characters c
44 for (Pointer1
= Str
; (*Pointer1
!= 0) && (*Pointer1
== CharC
); Pointer1
++) {
49 if (Pointer2
== Pointer1
) {
50 while (*Pointer1
!= 0) {
55 while (*Pointer1
!= 0) {
56 *Pointer2
= *Pointer1
;
64 for (Pointer1
= Str
+ StrLen(Str
) - 1; Pointer1
>= Str
&& *Pointer1
== CharC
; Pointer1
--) {
67 if (Pointer1
!= Str
+ StrLen(Str
) - 1) {
73 Calculate the prefix length of the IPv4 subnet mask.
75 @param[in] SubnetMask The IPv4 subnet mask.
77 @return The prefix length of the subnet mask.
78 @retval 0 Other errors as indicated.
82 IScsiGetSubnetMaskPrefixLength (
83 IN EFI_IPv4_ADDRESS
*SubnetMask
90 // The SubnetMask is in network byte order.
92 ReverseMask
= (SubnetMask
->Addr
[0] << 24) | (SubnetMask
->Addr
[1] << 16) | (SubnetMask
->Addr
[2] << 8) | (SubnetMask
->Addr
[3]);
97 ReverseMask
= ~ReverseMask
;
99 if ((ReverseMask
& (ReverseMask
+ 1)) != 0) {
105 while (ReverseMask
!= 0) {
106 ReverseMask
= ReverseMask
>> 1;
110 return (UINT8
) (32 - Len
);
115 Convert the hexadecimal encoded LUN string into the 64-bit LUN.
117 @param[in] Str The hexadecimal encoded LUN string.
118 @param[out] Lun Storage to return the 64-bit LUN.
120 @retval EFI_SUCCESS The 64-bit LUN is stored in Lun.
121 @retval EFI_INVALID_PARAMETER The string is malformatted.
130 UINTN Index
, IndexValue
, IndexNum
, SizeStr
;
137 ZeroMem ((UINT8
*) Value
, sizeof (Value
));
138 SizeStr
= AsciiStrLen (Str
);
142 for (Index
= 0; Index
< SizeStr
; Index
++) {
143 TemStr
[0] = Str
[Index
];
144 TemValue
= (UINT8
) AsciiStrHexToUint64 (TemStr
);
145 if (TemValue
== 0 && TemStr
[0] != '0') {
146 if ((TemStr
[0] != '-') || (IndexNum
== 0)) {
150 return EFI_INVALID_PARAMETER
;
154 if ((TemValue
== 0) && (TemStr
[0] == '-')) {
158 if (++IndexValue
>= 4) {
162 return EFI_INVALID_PARAMETER
;
165 // Restart str index for the next lun value.
171 if (++IndexNum
> 4) {
173 // Each Lun Str can't exceed size 4, because it will be as UINT16 value.
175 return EFI_INVALID_PARAMETER
;
179 // Combine UINT16 value.
181 Value
[IndexValue
] = (UINT16
) ((Value
[IndexValue
] << 4) + TemValue
);
184 for (Index
= 0; Index
<= IndexValue
; Index
++) {
185 *((UINT16
*) &Lun
[Index
* 2]) = HTONS (Value
[Index
]);
192 Convert the 64-bit LUN into the hexadecimal encoded LUN string.
194 @param[in] Lun The 64-bit LUN.
195 @param[out] Str The storage to return the hexadecimal encoded LUN string.
199 IScsiLunToUnicodeStr (
209 for (Index
= 0; Index
< 4; Index
++) {
211 if ((Lun
[2 * Index
] | Lun
[2 * Index
+ 1]) == 0) {
212 CopyMem (TempStr
, L
"0-", sizeof (L
"0-"));
214 TempStr
[0] = (CHAR16
) IScsiHexString
[Lun
[2 * Index
] >> 4];
215 TempStr
[1] = (CHAR16
) IScsiHexString
[Lun
[2 * Index
] & 0x0F];
216 TempStr
[2] = (CHAR16
) IScsiHexString
[Lun
[2 * Index
+ 1] >> 4];
217 TempStr
[3] = (CHAR16
) IScsiHexString
[Lun
[2 * Index
+ 1] & 0x0F];
221 IScsiStrTrim (TempStr
, L
'0');
224 TempStr
+= StrLen (TempStr
);
227 // Remove the last '-'
229 ASSERT (StrLen(Str
) >= 1);
230 Str
[StrLen (Str
) - 1] = 0;
232 for (Index
= StrLen (Str
) - 1; Index
> 1; Index
= Index
- 2) {
233 if ((Str
[Index
] == L
'0') && (Str
[Index
- 1] == L
'-')) {
242 Convert the formatted IP address into the binary IP address.
244 @param[in] Str The UNICODE string.
245 @param[in] IpMode Indicates whether the IP address is v4 or v6.
246 @param[out] Ip The storage to return the ASCII string.
248 @retval EFI_SUCCESS The binary IP address is returned in Ip.
249 @retval EFI_INVALID_PARAMETER The IP string is malformatted or IpMode is
257 OUT EFI_IP_ADDRESS
*Ip
262 if (IpMode
== IP_MODE_IP4
|| IpMode
== IP_MODE_AUTOCONFIG_IP4
) {
263 return NetLibAsciiStrToIp4 (Str
, &Ip
->v4
);
265 } else if (IpMode
== IP_MODE_IP6
|| IpMode
== IP_MODE_AUTOCONFIG_IP6
) {
266 return NetLibAsciiStrToIp6 (Str
, &Ip
->v6
);
268 } else if (IpMode
== IP_MODE_AUTOCONFIG
) {
269 Status
= NetLibAsciiStrToIp4 (Str
, &Ip
->v4
);
270 if (!EFI_ERROR (Status
)) {
273 return NetLibAsciiStrToIp6 (Str
, &Ip
->v6
);
277 return EFI_INVALID_PARAMETER
;
281 Convert the mac address into a hexadecimal encoded "-" seperated string.
283 @param[in] Mac The mac address.
284 @param[in] Len Length in bytes of the mac address.
285 @param[in] VlanId VLAN ID of the network device.
286 @param[out] Str The storage to return the mac string.
291 IN EFI_MAC_ADDRESS
*Mac
,
300 for (Index
= 0; Index
< Len
; Index
++) {
301 Str
[3 * Index
] = (CHAR16
) IScsiHexString
[(Mac
->Addr
[Index
] >> 4) & 0x0F];
302 Str
[3 * Index
+ 1] = (CHAR16
) IScsiHexString
[Mac
->Addr
[Index
] & 0x0F];
303 Str
[3 * Index
+ 2] = L
':';
306 String
= &Str
[3 * Index
- 1] ;
308 String
+= UnicodeSPrint (String
, 6 * sizeof (CHAR16
), L
"\\%04x", (UINTN
) VlanId
);
315 Convert the binary encoded buffer into a hexadecimal encoded string.
317 @param[in] BinBuffer The buffer containing the binary data.
318 @param[in] BinLength Length of the binary buffer.
319 @param[in, out] HexStr Pointer to the string.
320 @param[in, out] HexLength The length of the string.
322 @retval EFI_SUCCESS The binary data is converted to the hexadecimal string
323 and the length of the string is updated.
324 @retval EFI_BUFFER_TOO_SMALL The string is too small.
325 @retval EFI_INVALID_PARAMETER The IP string is malformatted.
332 IN OUT CHAR8
*HexStr
,
333 IN OUT UINT32
*HexLength
338 if ((HexStr
== NULL
) || (BinBuffer
== NULL
) || (BinLength
== 0)) {
339 return EFI_INVALID_PARAMETER
;
342 if (((*HexLength
) - 3) < BinLength
* 2) {
343 *HexLength
= BinLength
* 2 + 3;
344 return EFI_BUFFER_TOO_SMALL
;
347 *HexLength
= BinLength
* 2 + 3;
349 // Prefix for Hex String.
354 for (Index
= 0; Index
< BinLength
; Index
++) {
355 HexStr
[Index
* 2 + 2] = IScsiHexString
[BinBuffer
[Index
] >> 4];
356 HexStr
[Index
* 2 + 3] = IScsiHexString
[BinBuffer
[Index
] & 0xf];
359 HexStr
[Index
* 2 + 2] = '\0';
366 Convert the hexadecimal string into a binary encoded buffer.
368 @param[in, out] BinBuffer The binary buffer.
369 @param[in, out] BinLength Length of the binary buffer.
370 @param[in] HexStr The hexadecimal string.
372 @retval EFI_SUCCESS The hexadecimal string is converted into a binary
374 @retval EFI_BUFFER_TOO_SMALL The binary buffer is too small to hold the converted data.
379 IN OUT UINT8
*BinBuffer
,
380 IN OUT UINT32
*BinLength
,
389 ZeroMem (TemStr
, sizeof (TemStr
));
392 // Find out how many hex characters the string has.
394 if ((HexStr
[0] == '0') && ((HexStr
[1] == 'x') || (HexStr
[1] == 'X'))) {
398 Length
= AsciiStrLen (HexStr
);
400 for (Index
= 0; Index
< Length
; Index
++) {
401 TemStr
[0] = HexStr
[Index
];
402 Digit
= (UINT8
) AsciiStrHexToUint64 (TemStr
);
403 if (Digit
== 0 && TemStr
[0] != '0') {
409 if ((Index
& 1) == 0) {
410 BinBuffer
[Index
/2] = Digit
;
412 BinBuffer
[Index
/2] = (UINT8
) ((BinBuffer
[Index
/2] << 4) + Digit
);
416 *BinLength
= (UINT32
) ((Index
+ 1)/2);
423 Convert the decimal-constant string or hex-constant string into a numerical value.
425 @param[in] Str String in decimal or hex.
427 @return The numerical value.
435 if ((Str
[0] == '0') && ((Str
[1] == 'x') || (Str
[1] == 'X'))) {
438 return AsciiStrHexToUintn (Str
);
441 return AsciiStrDecimalToUintn (Str
);
446 Generate random numbers.
448 @param[in, out] Rand The buffer to contain random numbers.
449 @param[in] RandLength The length of the Rand buffer.
460 while (RandLength
> 0) {
461 Random
= NET_RANDOM (NetRandomInitSeed ());
462 *Rand
++ = (UINT8
) (Random
);
469 Record the NIC info in global structure.
471 @param[in] Controller The handle of the controller.
473 @retval EFI_SUCCESS The operation is completed.
474 @retval EFI_OUT_OF_RESOURCES Do not have sufficient resources to finish this
480 IN EFI_HANDLE Controller
484 ISCSI_NIC_INFO
*NicInfo
;
486 EFI_MAC_ADDRESS MacAddr
;
491 // Get MAC address of this network device.
493 Status
= NetLibGetMacAddress (Controller
, &MacAddr
, &HwAddressSize
);
494 if (EFI_ERROR (Status
)) {
499 // Get VLAN ID of this network device.
501 VlanId
= NetLibGetVlanId (Controller
);
504 // Check whether the NIC info already exists. Return directly if so.
506 NET_LIST_FOR_EACH (Entry
, &mPrivate
->NicInfoList
) {
507 NicInfo
= NET_LIST_USER_STRUCT (Entry
, ISCSI_NIC_INFO
, Link
);
508 if (NicInfo
->HwAddressSize
== HwAddressSize
&&
509 CompareMem (&NicInfo
->PermanentAddress
, MacAddr
.Addr
, HwAddressSize
) == 0 &&
510 NicInfo
->VlanId
== VlanId
) {
511 mPrivate
->CurrentNic
= NicInfo
->NicIndex
;
515 if (mPrivate
->MaxNic
< NicInfo
->NicIndex
) {
516 mPrivate
->MaxNic
= NicInfo
->NicIndex
;
521 // Record the NIC info in private structure.
523 NicInfo
= AllocateZeroPool (sizeof (ISCSI_NIC_INFO
));
524 if (NicInfo
== NULL
) {
525 return EFI_OUT_OF_RESOURCES
;
528 CopyMem (&NicInfo
->PermanentAddress
, MacAddr
.Addr
, HwAddressSize
);
529 NicInfo
->HwAddressSize
= (UINT32
) HwAddressSize
;
530 NicInfo
->VlanId
= VlanId
;
531 NicInfo
->NicIndex
= (UINT8
) (mPrivate
->MaxNic
+ 1);
532 mPrivate
->MaxNic
= NicInfo
->NicIndex
;
535 // Get the PCI location.
537 IScsiGetNICPciLocation (
540 &NicInfo
->DeviceNumber
,
541 &NicInfo
->FunctionNumber
544 InsertTailList (&mPrivate
->NicInfoList
, &NicInfo
->Link
);
545 mPrivate
->NicCount
++;
547 mPrivate
->CurrentNic
= NicInfo
->NicIndex
;
553 Delete the recorded NIC info from global structure. Also delete corresponding
556 @param[in] Controller The handle of the controller.
558 @retval EFI_SUCCESS The operation is completed.
559 @retval EFI_NOT_FOUND The NIC info to be deleted is not recorded.
564 IN EFI_HANDLE Controller
568 ISCSI_NIC_INFO
*NicInfo
;
570 LIST_ENTRY
*NextEntry
;
571 ISCSI_ATTEMPT_CONFIG_NVDATA
*AttemptConfigData
;
572 ISCSI_NIC_INFO
*ThisNic
;
573 EFI_MAC_ADDRESS MacAddr
;
578 // Get MAC address of this network device.
580 Status
= NetLibGetMacAddress (Controller
, &MacAddr
, &HwAddressSize
);
581 if (EFI_ERROR (Status
)) {
586 // Get VLAN ID of this network device.
588 VlanId
= NetLibGetVlanId (Controller
);
591 // Check whether the NIC information exists.
595 NET_LIST_FOR_EACH (Entry
, &mPrivate
->NicInfoList
) {
596 NicInfo
= NET_LIST_USER_STRUCT (Entry
, ISCSI_NIC_INFO
, Link
);
597 if (NicInfo
->HwAddressSize
== HwAddressSize
&&
598 CompareMem (&NicInfo
->PermanentAddress
, MacAddr
.Addr
, HwAddressSize
) == 0 &&
599 NicInfo
->VlanId
== VlanId
) {
606 if (ThisNic
== NULL
) {
607 return EFI_NOT_FOUND
;
610 mPrivate
->CurrentNic
= ThisNic
->NicIndex
;
612 RemoveEntryList (&ThisNic
->Link
);
614 mPrivate
->NicCount
--;
617 // Remove all attempts related to this NIC.
619 NET_LIST_FOR_EACH_SAFE (Entry
, NextEntry
, &mPrivate
->AttemptConfigs
) {
620 AttemptConfigData
= NET_LIST_USER_STRUCT (Entry
, ISCSI_ATTEMPT_CONFIG_NVDATA
, Link
);
621 if (AttemptConfigData
->NicIndex
== mPrivate
->CurrentNic
) {
622 RemoveEntryList (&AttemptConfigData
->Link
);
623 mPrivate
->AttemptCount
--;
625 if (AttemptConfigData
->SessionConfigData
.Enabled
== ISCSI_ENABLED_FOR_MPIO
&& mPrivate
->MpioCount
> 0) {
626 if (--mPrivate
->MpioCount
== 0) {
627 mPrivate
->EnableMpio
= FALSE
;
630 if (AttemptConfigData
->AuthenticationType
== ISCSI_AUTH_TYPE_KRB
&& mPrivate
->Krb5MpioCount
> 0) {
631 mPrivate
->Krb5MpioCount
--;
634 } else if (AttemptConfigData
->SessionConfigData
.Enabled
== ISCSI_ENABLED
&& mPrivate
->SinglePathCount
> 0) {
635 mPrivate
->SinglePathCount
--;
637 if (mPrivate
->ValidSinglePathCount
> 0) {
638 mPrivate
->ValidSinglePathCount
--;
642 FreePool (AttemptConfigData
);
650 Create and initialize the Attempts.
652 @param[in] AttemptNum The number of Attempts will be created.
654 @retval EFI_SUCCESS The Attempts have been created successfully.
655 @retval Others Failed to create the Attempt.
659 IScsiCreateAttempts (
663 ISCSI_ATTEMPT_CONFIG_NVDATA
*AttemptConfigData
;
664 ISCSI_SESSION_CONFIG_NVDATA
*ConfigData
;
665 UINT8
*AttemptConfigOrder
;
666 UINTN AttemptConfigOrderSize
;
667 UINT8
*AttemptOrderTmp
;
672 for (Index
= 1; Index
<= AttemptNum
; Index
++) {
674 // Get the initialized attempt order. This is used to essure creating attempts by order.
676 AttemptConfigOrder
= IScsiGetVariableAndSize (
677 L
"InitialAttemptOrder",
679 &AttemptConfigOrderSize
681 TotalNumber
= AttemptConfigOrderSize
/ sizeof (UINT8
);
682 if (TotalNumber
== AttemptNum
) {
683 Status
= EFI_SUCCESS
;
689 // Append the new created attempt to the end.
691 AttemptOrderTmp
= AllocateZeroPool (TotalNumber
* sizeof (UINT8
));
692 if (AttemptOrderTmp
== NULL
) {
693 if (AttemptConfigOrder
!= NULL
) {
694 FreePool (AttemptConfigOrder
);
696 return EFI_OUT_OF_RESOURCES
;
699 if (AttemptConfigOrder
!= NULL
) {
700 CopyMem (AttemptOrderTmp
, AttemptConfigOrder
, AttemptConfigOrderSize
);
701 FreePool (AttemptConfigOrder
);
704 AttemptOrderTmp
[TotalNumber
- 1] = Index
;
705 AttemptConfigOrder
= AttemptOrderTmp
;
706 AttemptConfigOrderSize
= TotalNumber
* sizeof (UINT8
);
708 Status
= gRT
->SetVariable (
709 L
"InitialAttemptOrder",
711 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
712 AttemptConfigOrderSize
,
715 FreePool (AttemptConfigOrder
);
716 if (EFI_ERROR (Status
)) {
721 // Create new Attempt
723 AttemptConfigData
= AllocateZeroPool (sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA
));
724 if (AttemptConfigData
== NULL
) {
725 return EFI_OUT_OF_RESOURCES
;
727 ConfigData
= &AttemptConfigData
->SessionConfigData
;
728 ConfigData
->TargetPort
= ISCSI_WELL_KNOWN_PORT
;
729 ConfigData
->ConnectTimeout
= CONNECT_DEFAULT_TIMEOUT
;
730 ConfigData
->ConnectRetryCount
= CONNECT_MIN_RETRY
;
732 AttemptConfigData
->AuthenticationType
= ISCSI_AUTH_TYPE_CHAP
;
733 AttemptConfigData
->AuthConfigData
.CHAP
.CHAPType
= ISCSI_CHAP_UNI
;
735 // Configure the Attempt index and set variable.
737 AttemptConfigData
->AttemptConfigIndex
= Index
;
740 // Set the attempt name according to the order.
743 mPrivate
->PortString
,
744 (UINTN
) ISCSI_NAME_IFR_MAX_SIZE
,
746 (UINTN
) AttemptConfigData
->AttemptConfigIndex
748 UnicodeStrToAsciiStrS (mPrivate
->PortString
, AttemptConfigData
->AttemptName
, ATTEMPT_NAME_SIZE
);
750 Status
= gRT
->SetVariable (
751 mPrivate
->PortString
,
752 &gEfiIScsiInitiatorNameProtocolGuid
,
753 ISCSI_CONFIG_VAR_ATTR
,
754 sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA
),
757 FreePool (AttemptConfigData
);
758 if (EFI_ERROR (Status
)) {
767 Create the iSCSI configuration Keywords for each attempt. You can find the keywords
768 defined in the "x-UEFI-ns" namespace (http://www.uefi.org/confignamespace).
770 @param[in] KeywordNum The number Sets of Keywords will be created.
772 @retval EFI_SUCCESS The operation is completed.
773 @retval Others Failed to create the Keywords.
777 IScsiCreateKeywords (
781 VOID
*StartOpCodeHandle
;
782 EFI_IFR_GUID_LABEL
*StartLabel
;
783 VOID
*EndOpCodeHandle
;
784 EFI_IFR_GUID_LABEL
*EndLabel
;
786 EFI_STRING_ID StringToken
;
788 CHAR16 KeywordId
[32];
791 Status
= IScsiCreateOpCode (
798 if (EFI_ERROR (Status
)) {
799 return EFI_OUT_OF_RESOURCES
;
802 for (Index
= 1; Index
<= KeywordNum
; Index
++) {
804 // Create iSCSIAttemptName Keyword.
806 UnicodeSPrint (StringId
, sizeof (StringId
), L
"STR_ISCSI_ATTEMPTT_NAME_PROMPT%d", Index
);
807 StringToken
= HiiSetString (
808 mCallbackInfo
->RegisteredHandle
,
813 UnicodeSPrint (KeywordId
, sizeof (KeywordId
), L
"iSCSIAttemptName:%d", Index
);
814 HiiSetString (mCallbackInfo
->RegisteredHandle
, StringToken
, KeywordId
, "x-UEFI-ns");
815 HiiCreateStringOpCode (
817 (EFI_QUESTION_ID
) (ATTEMPT_ATTEMPT_NAME_QUESTION_ID
+ (Index
- 1)),
818 CONFIGURATION_VARSTORE_ID
,
819 (UINT16
) (ATTEMPT_ATTEMPT_NAME_VAR_OFFSET
+ ATTEMPT_NAME_SIZE
* (Index
- 1) * sizeof (CHAR16
)),
822 EFI_IFR_FLAG_READ_ONLY
,
830 // Create iSCSIBootEnable Keyword.
832 UnicodeSPrint (StringId
, sizeof (StringId
), L
"STR_ISCSI_MODE_PROMPT%d", Index
);
833 StringToken
= HiiSetString (
834 mCallbackInfo
->RegisteredHandle
,
839 UnicodeSPrint (KeywordId
, sizeof (KeywordId
), L
"iSCSIBootEnable:%d", Index
);
840 HiiSetString (mCallbackInfo
->RegisteredHandle
, StringToken
, KeywordId
, "x-UEFI-ns");
841 HiiCreateNumericOpCode (
843 (EFI_QUESTION_ID
) (ATTEMPT_BOOTENABLE_QUESTION_ID
+ (Index
- 1)),
844 CONFIGURATION_VARSTORE_ID
,
845 (UINT16
) (ATTEMPT_BOOTENABLE_VAR_OFFSET
+ (Index
- 1)),
849 EFI_IFR_NUMERIC_SIZE_1
,
857 // Create iSCSIIpAddressType Keyword.
859 UnicodeSPrint (StringId
, sizeof (StringId
), L
"STR_ISCSI_IP_MODE_PROMPT%d", Index
);
860 StringToken
= HiiSetString (
861 mCallbackInfo
->RegisteredHandle
,
866 UnicodeSPrint (KeywordId
, sizeof (KeywordId
), L
"iSCSIIpAddressType:%d", Index
);
867 HiiSetString (mCallbackInfo
->RegisteredHandle
, StringToken
, KeywordId
, "x-UEFI-ns");
868 HiiCreateNumericOpCode (
870 (EFI_QUESTION_ID
) (ATTEMPT_ADDRESS_TYPE_QUESTION_ID
+ (Index
- 1)),
871 CONFIGURATION_VARSTORE_ID
,
872 (UINT16
) (ATTEMPT_ADDRESS_TYPE_VAR_OFFSET
+ (Index
- 1)),
876 EFI_IFR_NUMERIC_SIZE_1
,
884 // Create iSCSIConnectRetry Keyword.
886 UnicodeSPrint (StringId
, sizeof (StringId
), L
"STR_ISCSI_CONNECT_RETRY_PROMPT%d", Index
);
887 StringToken
= HiiSetString (
888 mCallbackInfo
->RegisteredHandle
,
893 UnicodeSPrint (KeywordId
, sizeof (KeywordId
), L
"iSCSIConnectRetry:%d", Index
);
894 HiiSetString (mCallbackInfo
->RegisteredHandle
, StringToken
, KeywordId
, "x-UEFI-ns");
895 HiiCreateNumericOpCode (
897 (EFI_QUESTION_ID
) (ATTEMPT_CONNECT_RETRY_QUESTION_ID
+ (Index
- 1)),
898 CONFIGURATION_VARSTORE_ID
,
899 (UINT16
) (ATTEMPT_CONNECT_RETRY_VAR_OFFSET
+ (Index
- 1)),
903 EFI_IFR_NUMERIC_SIZE_1
,
911 // Create iSCSIConnectTimeout Keyword.
913 UnicodeSPrint (StringId
, sizeof (StringId
), L
"STR_ISCSI_CONNECT_TIMEOUT_PROMPT%d", Index
);
914 StringToken
= HiiSetString (
915 mCallbackInfo
->RegisteredHandle
,
920 UnicodeSPrint (KeywordId
, sizeof (KeywordId
), L
"iSCSIConnectTimeout:%d", Index
);
921 HiiSetString (mCallbackInfo
->RegisteredHandle
, StringToken
, KeywordId
, "x-UEFI-ns");
922 HiiCreateNumericOpCode (
924 (EFI_QUESTION_ID
) (ATTEMPT_CONNECT_TIMEOUT_QUESTION_ID
+ (Index
- 1)),
925 CONFIGURATION_VARSTORE_ID
,
926 (UINT16
) (ATTEMPT_CONNECT_TIMEOUT_VAR_OFFSET
+ 2 * (Index
- 1)),
930 EFI_IFR_NUMERIC_SIZE_2
,
938 // Create ISID Keyword.
940 UnicodeSPrint (StringId
, sizeof (StringId
), L
"STR_ISCSI_ISID_PROMPT%d", Index
);
941 StringToken
= HiiSetString (
942 mCallbackInfo
->RegisteredHandle
,
947 UnicodeSPrint (KeywordId
, sizeof (KeywordId
), L
"iSCSIISID:%d", Index
);
948 HiiSetString (mCallbackInfo
->RegisteredHandle
, StringToken
, KeywordId
, "x-UEFI-ns");
949 HiiCreateStringOpCode (
951 (EFI_QUESTION_ID
) (ATTEMPT_ISID_QUESTION_ID
+ (Index
- 1)),
952 CONFIGURATION_VARSTORE_ID
,
953 (UINT16
) (ATTEMPT_ISID_VAR_OFFSET
+ sizeof (KEYWORD_STR
) * (Index
- 1)),
958 ISID_CONFIGURABLE_MIN_LEN
,
959 ISID_CONFIGURABLE_STORAGE
,
964 // Create iSCSIInitiatorInfoViaDHCP Keyword.
966 UnicodeSPrint (StringId
, sizeof (StringId
), L
"STR_ISCSI_INITIATOR_VIA_DHCP_PROMPT%d", Index
);
967 StringToken
= HiiSetString (
968 mCallbackInfo
->RegisteredHandle
,
973 UnicodeSPrint (KeywordId
, sizeof (KeywordId
), L
"iSCSIInitiatorInfoViaDHCP:%d", Index
);
974 HiiSetString (mCallbackInfo
->RegisteredHandle
, StringToken
, KeywordId
, "x-UEFI-ns");
975 HiiCreateNumericOpCode (
977 (EFI_QUESTION_ID
) (ATTEMPT_INITIATOR_VIA_DHCP_QUESTION_ID
+ (Index
- 1)),
978 CONFIGURATION_VARSTORE_ID
,
979 (UINT16
) (ATTEMPT_INITIATOR_VIA_DHCP_VAR_OFFSET
+ (Index
- 1)),
991 // Create iSCSIInitiatorIpAddress Keyword.
993 UnicodeSPrint (StringId
, sizeof (StringId
), L
"STR_ISCSI_INITIATOR_IP_ADDRESS_PROMPT%d", Index
);
994 StringToken
= HiiSetString (
995 mCallbackInfo
->RegisteredHandle
,
1000 UnicodeSPrint (KeywordId
, sizeof (KeywordId
), L
"iSCSIInitiatorIpAddress:%d", Index
);
1001 HiiSetString (mCallbackInfo
->RegisteredHandle
, StringToken
, KeywordId
, "x-UEFI-ns");
1002 HiiCreateStringOpCode (
1004 (EFI_QUESTION_ID
) (ATTEMPT_INITIATOR_IP_ADDRESS_QUESTION_ID
+ (Index
- 1)),
1005 CONFIGURATION_VARSTORE_ID
,
1006 (UINT16
) (ATTEMPT_INITIATOR_IP_ADDRESS_VAR_OFFSET
+ sizeof (KEYWORD_STR
) * (Index
- 1)),
1017 // Create iSCSIInitiatorNetmask Keyword.
1019 UnicodeSPrint (StringId
, sizeof (StringId
), L
"STR_ISCSI_INITIATOR_NET_MASK_PROMPT%d", Index
);
1020 StringToken
= HiiSetString (
1021 mCallbackInfo
->RegisteredHandle
,
1026 UnicodeSPrint (KeywordId
, sizeof (KeywordId
), L
"iSCSIInitiatorNetmask:%d", Index
);
1027 HiiSetString (mCallbackInfo
->RegisteredHandle
, StringToken
, KeywordId
, "x-UEFI-ns");
1028 HiiCreateStringOpCode (
1030 (EFI_QUESTION_ID
) (ATTEMPT_INITIATOR_NET_MASK_QUESTION_ID
+ (Index
- 1)),
1031 CONFIGURATION_VARSTORE_ID
,
1032 (UINT16
) (ATTEMPT_INITIATOR_NET_MASK_VAR_OFFSET
+ sizeof (KEYWORD_STR
) * (Index
- 1)),
1043 // Create iSCSIInitiatorGateway Keyword.
1045 UnicodeSPrint (StringId
, sizeof (StringId
), L
"STR_ISCSI_INITIATOR_GATE_PROMPT%d", Index
);
1046 StringToken
= HiiSetString (
1047 mCallbackInfo
->RegisteredHandle
,
1052 UnicodeSPrint (KeywordId
, sizeof (KeywordId
), L
"iSCSIInitiatorGateway:%d", Index
);
1053 HiiSetString (mCallbackInfo
->RegisteredHandle
, StringToken
, KeywordId
, "x-UEFI-ns");
1054 HiiCreateStringOpCode (
1056 (EFI_QUESTION_ID
) (ATTEMPT_INITIATOR_GATE_WAY_QUESTION_ID
+ (Index
- 1)),
1057 CONFIGURATION_VARSTORE_ID
,
1058 (UINT16
) (ATTEMPT_INITIATOR_GATE_WAY_VAR_OFFSET
+ sizeof (KEYWORD_STR
) * (Index
- 1)),
1069 // Create iSCSITargetInfoViaDHCP Keyword.
1071 UnicodeSPrint (StringId
, sizeof (StringId
), L
"STR_ISCSI_TARGET_VIA_DHCP_PROMPT%d", Index
);
1072 StringToken
= HiiSetString (
1073 mCallbackInfo
->RegisteredHandle
,
1078 UnicodeSPrint (KeywordId
, sizeof (KeywordId
), L
"iSCSITargetInfoViaDHCP:%d", Index
);
1079 HiiSetString (mCallbackInfo
->RegisteredHandle
, StringToken
, KeywordId
, "x-UEFI-ns");
1080 HiiCreateNumericOpCode (
1082 (EFI_QUESTION_ID
) (ATTEMPT_TARGET_VIA_DHCP_QUESTION_ID
+ (Index
- 1)),
1083 CONFIGURATION_VARSTORE_ID
,
1084 (UINT16
) (ATTEMPT_TARGET_VIA_DHCP_VAR_OFFSET
+ (Index
- 1)),
1096 // Create iSCSITargetTcpPort Keyword.
1098 UnicodeSPrint (StringId
, sizeof (StringId
), L
"STR_ISCSI_TARGET_TCP_PORT_PROMPT%d", Index
);
1099 StringToken
= HiiSetString (
1100 mCallbackInfo
->RegisteredHandle
,
1105 UnicodeSPrint (KeywordId
, sizeof (KeywordId
), L
"iSCSITargetTcpPort:%d", Index
);
1106 HiiSetString (mCallbackInfo
->RegisteredHandle
, StringToken
, KeywordId
, "x-UEFI-ns");
1107 HiiCreateNumericOpCode (
1109 (EFI_QUESTION_ID
) (ATTEMPT_TARGET_TCP_PORT_QUESTION_ID
+ (Index
- 1)),
1110 CONFIGURATION_VARSTORE_ID
,
1111 (UINT16
) (ATTEMPT_TARGET_TCP_PORT_VAR_OFFSET
+ 2 * (Index
- 1)),
1115 EFI_IFR_NUMERIC_SIZE_2
,
1116 TARGET_PORT_MIN_NUM
,
1117 TARGET_PORT_MAX_NUM
,
1123 // Create iSCSITargetName Keyword.
1125 UnicodeSPrint (StringId
, sizeof (StringId
), L
"STR_ISCSI_TARGET_NAME_PROMPT%d", Index
);
1126 StringToken
= HiiSetString (
1127 mCallbackInfo
->RegisteredHandle
,
1132 UnicodeSPrint (KeywordId
, sizeof (KeywordId
), L
"iSCSITargetName:%d", Index
);
1133 HiiSetString (mCallbackInfo
->RegisteredHandle
, StringToken
, KeywordId
, "x-UEFI-ns");
1134 HiiCreateStringOpCode (
1136 (EFI_QUESTION_ID
) (ATTEMPT_TARGET_NAME_QUESTION_ID
+ (Index
- 1)),
1137 CONFIGURATION_VARSTORE_ID
,
1138 (UINT16
) (ATTEMPT_TARGET_NAME_VAR_OFFSET
+ sizeof (KEYWORD_STR
) * (Index
- 1)),
1143 ISCSI_NAME_IFR_MIN_SIZE
,
1144 ISCSI_NAME_IFR_MAX_SIZE
,
1149 // Create iSCSITargetIpAddress Keyword.
1151 UnicodeSPrint (StringId
, sizeof (StringId
), L
"STR_ISCSI_TARGET_IP_ADDRESS_PROMPT%d", Index
);
1152 StringToken
= HiiSetString (
1153 mCallbackInfo
->RegisteredHandle
,
1158 UnicodeSPrint (KeywordId
, sizeof (KeywordId
), L
"iSCSITargetIpAddress:%d", Index
);
1159 HiiSetString (mCallbackInfo
->RegisteredHandle
, StringToken
, KeywordId
, "x-UEFI-ns");
1160 HiiCreateStringOpCode (
1162 (EFI_QUESTION_ID
) (ATTEMPT_TARGET_IP_ADDRESS_QUESTION_ID
+ (Index
- 1)),
1163 CONFIGURATION_VARSTORE_ID
,
1164 (UINT16
) (ATTEMPT_TARGET_IP_ADDRESS_VAR_OFFSET
+ sizeof (KEYWORD_STR
) * (Index
- 1)),
1175 // Create iSCSILUN Keyword.
1177 UnicodeSPrint (StringId
, sizeof (StringId
), L
"STR_ISCSI_LUN_PROMPT%d", Index
);
1178 StringToken
= HiiSetString (
1179 mCallbackInfo
->RegisteredHandle
,
1184 UnicodeSPrint (KeywordId
, sizeof (KeywordId
), L
"iSCSILUN:%d", Index
);
1185 HiiSetString (mCallbackInfo
->RegisteredHandle
, StringToken
, KeywordId
, "x-UEFI-ns");
1186 HiiCreateStringOpCode (
1188 (EFI_QUESTION_ID
) (ATTEMPT_LUN_QUESTION_ID
+ (Index
- 1)),
1189 CONFIGURATION_VARSTORE_ID
,
1190 (UINT16
) (ATTEMPT_LUN_VAR_OFFSET
+ sizeof (KEYWORD_STR
) * (Index
- 1)),
1201 // Create iSCSIAuthenticationMethod Keyword.
1203 UnicodeSPrint (StringId
, sizeof (StringId
), L
"STR_ISCSI_AUTHENTICATION_METHOD_PROMPT%d", Index
);
1204 StringToken
= HiiSetString (
1205 mCallbackInfo
->RegisteredHandle
,
1210 UnicodeSPrint (KeywordId
, sizeof (KeywordId
), L
"iSCSIAuthenticationMethod:%d", Index
);
1211 HiiSetString (mCallbackInfo
->RegisteredHandle
, StringToken
, KeywordId
, "x-UEFI-ns");
1212 HiiCreateNumericOpCode (
1214 (EFI_QUESTION_ID
) (ATTEMPT_AUTHENTICATION_METHOD_QUESTION_ID
+ (Index
- 1)),
1215 CONFIGURATION_VARSTORE_ID
,
1216 (UINT16
) (ATTEMPT_AUTHENTICATION_METHOD_VAR_OFFSET
+ (Index
- 1)),
1228 // Create iSCSIChapType Keyword.
1230 UnicodeSPrint (StringId
, sizeof (StringId
), L
"STR_ISCSI_CHARTYPE_PROMPT%d", Index
);
1231 StringToken
= HiiSetString (
1232 mCallbackInfo
->RegisteredHandle
,
1237 UnicodeSPrint (KeywordId
, sizeof (KeywordId
), L
"iSCSIChapType:%d", Index
);
1238 HiiSetString (mCallbackInfo
->RegisteredHandle
, StringToken
, KeywordId
, "x-UEFI-ns");
1239 HiiCreateNumericOpCode (
1241 (EFI_QUESTION_ID
) (ATTEMPT_CHARTYPE_QUESTION_ID
+ (Index
- 1)),
1242 CONFIGURATION_VARSTORE_ID
,
1243 (UINT16
) (ATTEMPT_CHARTYPE_VAR_OFFSET
+ (Index
- 1)),
1255 // Create iSCSIChapUsername Keyword.
1257 UnicodeSPrint (StringId
, sizeof (StringId
), L
"STR_ISCSI_CHAR_USER_NAME_PROMPT%d", Index
);
1258 StringToken
= HiiSetString (
1259 mCallbackInfo
->RegisteredHandle
,
1264 UnicodeSPrint (KeywordId
, sizeof (KeywordId
), L
"iSCSIChapUsername:%d", Index
);
1265 HiiSetString (mCallbackInfo
->RegisteredHandle
, StringToken
, KeywordId
, "x-UEFI-ns");
1266 HiiCreateStringOpCode (
1268 (EFI_QUESTION_ID
) (ATTEMPT_CHAR_USER_NAME_QUESTION_ID
+ (Index
- 1)),
1269 CONFIGURATION_VARSTORE_ID
,
1270 (UINT16
) (ATTEMPT_CHAR_USER_NAME_VAR_OFFSET
+ sizeof (KEYWORD_STR
) * (Index
- 1)),
1276 ISCSI_CHAP_NAME_MAX_LEN
,
1281 // Create iSCSIChapSecret Keyword.
1283 UnicodeSPrint (StringId
, sizeof (StringId
), L
"STR_ISCSI_CHAR_SECRET_PROMPT%d", Index
);
1284 StringToken
= HiiSetString (
1285 mCallbackInfo
->RegisteredHandle
,
1290 UnicodeSPrint (KeywordId
, sizeof (KeywordId
), L
"iSCSIChapSecret:%d", Index
);
1291 HiiSetString (mCallbackInfo
->RegisteredHandle
, StringToken
, KeywordId
, "x-UEFI-ns");
1292 HiiCreateStringOpCode (
1294 (EFI_QUESTION_ID
) (ATTEMPT_CHAR_SECRET_QUESTION_ID
+ (Index
- 1)),
1295 CONFIGURATION_VARSTORE_ID
,
1296 (UINT16
) (ATTEMPT_CHAR_SECRET_VAR_OFFSET
+ sizeof (KEYWORD_STR
) * (Index
- 1)),
1301 ISCSI_CHAP_SECRET_MIN_LEN
,
1302 ISCSI_CHAP_SECRET_MAX_LEN
,
1307 // Create iSCSIReverseChapUsername Keyword.
1309 UnicodeSPrint (StringId
, sizeof (StringId
), L
"STR_ISCSI_CHAR_REVERSE_USER_NAME_PROMPT%d", Index
);
1310 StringToken
= HiiSetString (
1311 mCallbackInfo
->RegisteredHandle
,
1316 UnicodeSPrint (KeywordId
, sizeof (KeywordId
), L
"iSCSIReverseChapUsername:%d", Index
);
1317 HiiSetString (mCallbackInfo
->RegisteredHandle
, StringToken
, KeywordId
, "x-UEFI-ns");
1318 HiiCreateStringOpCode (
1320 (EFI_QUESTION_ID
) (ATTEMPT_CHAR_REVERSE_USER_NAME_QUESTION_ID
+ (Index
- 1)),
1321 CONFIGURATION_VARSTORE_ID
,
1322 (UINT16
) (ATTEMPT_CHAR_REVERSE_USER_NAME_VAR_OFFSET
+ sizeof (KEYWORD_STR
) * (Index
- 1)),
1328 ISCSI_CHAP_NAME_MAX_LEN
,
1333 // Create iSCSIReverseChapSecret Keyword.
1335 UnicodeSPrint (StringId
, sizeof (StringId
), L
"STR_ISCSI_CHAR_REVERSE_SECRET_PROMPT%d", Index
);
1336 StringToken
= HiiSetString (
1337 mCallbackInfo
->RegisteredHandle
,
1342 UnicodeSPrint (KeywordId
, sizeof (KeywordId
), L
"iSCSIReverseChapSecret:%d", Index
);
1343 HiiSetString (mCallbackInfo
->RegisteredHandle
, StringToken
, KeywordId
, "x-UEFI-ns");
1344 HiiCreateStringOpCode (
1346 (EFI_QUESTION_ID
) (ATTEMPT_CHAR_REVERSE_SECRET_QUESTION_ID
+ (Index
- 1)),
1347 CONFIGURATION_VARSTORE_ID
,
1348 (UINT16
) (ATTEMPT_CHAR_REVERSE_SECRET_VAR_OFFSET
+ sizeof (KEYWORD_STR
) * (Index
- 1)),
1353 ISCSI_CHAP_SECRET_MIN_LEN
,
1354 ISCSI_CHAP_SECRET_MAX_LEN
,
1359 Status
= HiiUpdateForm (
1360 mCallbackInfo
->RegisteredHandle
, // HII handle
1361 &gIScsiConfigGuid
, // Formset GUID
1362 FORMID_ATTEMPT_FORM
, // Form ID
1363 StartOpCodeHandle
, // Label for where to insert opcodes
1364 EndOpCodeHandle
// Replace data
1367 HiiFreeOpCodeHandle (StartOpCodeHandle
);
1368 HiiFreeOpCodeHandle (EndOpCodeHandle
);
1375 Free the attempt configure data variable.
1379 IScsiCleanAttemptVariable (
1383 ISCSI_ATTEMPT_CONFIG_NVDATA
*AttemptConfigData
;
1384 UINT8
*AttemptConfigOrder
;
1385 UINTN AttemptConfigOrderSize
;
1389 // Get the initialized attempt order.
1391 AttemptConfigOrder
= IScsiGetVariableAndSize (
1392 L
"InitialAttemptOrder",
1394 &AttemptConfigOrderSize
1396 if (AttemptConfigOrder
== NULL
|| AttemptConfigOrderSize
== 0) {
1400 for (Index
= 1; Index
< AttemptConfigOrderSize
/ sizeof (UINT8
); Index
++) {
1402 mPrivate
->PortString
,
1403 (UINTN
) ISCSI_NAME_IFR_MAX_SIZE
,
1409 mPrivate
->PortString
,
1410 &gEfiIScsiInitiatorNameProtocolGuid
,
1411 (VOID
**)&AttemptConfigData
,
1415 if (AttemptConfigData
!= NULL
) {
1417 mPrivate
->PortString
,
1418 &gEfiIScsiInitiatorNameProtocolGuid
,
1429 Get the recorded NIC info from global structure by the Index.
1431 @param[in] NicIndex The index indicates the position of NIC info.
1433 @return Pointer to the NIC info, or NULL if not found.
1437 IScsiGetNicInfoByIndex (
1442 ISCSI_NIC_INFO
*NicInfo
;
1444 NET_LIST_FOR_EACH (Entry
, &mPrivate
->NicInfoList
) {
1445 NicInfo
= NET_LIST_USER_STRUCT (Entry
, ISCSI_NIC_INFO
, Link
);
1446 if (NicInfo
->NicIndex
== NicIndex
) {
1456 Get the NIC's PCI location and return it according to the composited
1457 format defined in iSCSI Boot Firmware Table.
1459 @param[in] Controller The handle of the controller.
1460 @param[out] Bus The bus number.
1461 @param[out] Device The device number.
1462 @param[out] Function The function number.
1464 @return The composited representation of the NIC PCI location.
1468 IScsiGetNICPciLocation (
1469 IN EFI_HANDLE Controller
,
1476 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1477 EFI_HANDLE PciIoHandle
;
1478 EFI_PCI_IO_PROTOCOL
*PciIo
;
1481 Status
= gBS
->HandleProtocol (
1483 &gEfiDevicePathProtocolGuid
,
1484 (VOID
**) &DevicePath
1486 if (EFI_ERROR (Status
)) {
1490 Status
= gBS
->LocateDevicePath (
1491 &gEfiPciIoProtocolGuid
,
1495 if (EFI_ERROR (Status
)) {
1499 Status
= gBS
->HandleProtocol (PciIoHandle
, &gEfiPciIoProtocolGuid
, (VOID
**) &PciIo
);
1500 if (EFI_ERROR (Status
)) {
1504 Status
= PciIo
->GetLocation (PciIo
, &Segment
, Bus
, Device
, Function
);
1505 if (EFI_ERROR (Status
)) {
1509 return (UINT16
) ((*Bus
<< 8) | (*Device
<< 3) | *Function
);
1514 Read the EFI variable (VendorGuid/Name) and return a dynamically allocated
1515 buffer, and the size of the buffer. If failure, return NULL.
1517 @param[in] Name String part of EFI variable name.
1518 @param[in] VendorGuid GUID part of EFI variable name.
1519 @param[out] VariableSize Returns the size of the EFI variable that was read.
1521 @return Dynamically allocated memory that contains a copy of the EFI variable.
1522 @return Caller is responsible freeing the buffer.
1523 @retval NULL Variable was not read.
1527 IScsiGetVariableAndSize (
1529 IN EFI_GUID
*VendorGuid
,
1530 OUT UINTN
*VariableSize
1540 // Pass in a zero size buffer to find the required buffer size.
1543 Status
= gRT
->GetVariable (Name
, VendorGuid
, NULL
, &BufferSize
, Buffer
);
1544 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1546 // Allocate the buffer to return
1548 Buffer
= AllocateZeroPool (BufferSize
);
1549 if (Buffer
== NULL
) {
1553 // Read variable into the allocated buffer.
1555 Status
= gRT
->GetVariable (Name
, VendorGuid
, NULL
, &BufferSize
, Buffer
);
1556 if (EFI_ERROR (Status
)) {
1561 *VariableSize
= BufferSize
;
1567 Create the iSCSI driver data.
1569 @param[in] Image The handle of the driver image.
1570 @param[in] Controller The handle of the controller.
1572 @return The iSCSI driver data created.
1573 @retval NULL Other errors as indicated.
1577 IScsiCreateDriverData (
1578 IN EFI_HANDLE Image
,
1579 IN EFI_HANDLE Controller
1582 ISCSI_DRIVER_DATA
*Private
;
1585 Private
= AllocateZeroPool (sizeof (ISCSI_DRIVER_DATA
));
1586 if (Private
== NULL
) {
1590 Private
->Signature
= ISCSI_DRIVER_DATA_SIGNATURE
;
1591 Private
->Image
= Image
;
1592 Private
->Controller
= Controller
;
1593 Private
->Session
= NULL
;
1596 // Create an event to be signaled when the BS to RT transition is triggerd so
1597 // as to abort the iSCSI session.
1599 Status
= gBS
->CreateEventEx (
1602 IScsiOnExitBootService
,
1604 &gEfiEventExitBootServicesGuid
,
1605 &Private
->ExitBootServiceEvent
1607 if (EFI_ERROR (Status
)) {
1612 Private
->ExtScsiPassThruHandle
= NULL
;
1613 CopyMem(&Private
->IScsiExtScsiPassThru
, &gIScsiExtScsiPassThruProtocolTemplate
, sizeof(EFI_EXT_SCSI_PASS_THRU_PROTOCOL
));
1616 // 0 is designated to the TargetId, so use another value for the AdapterId.
1618 Private
->ExtScsiPassThruMode
.AdapterId
= 2;
1619 Private
->ExtScsiPassThruMode
.Attributes
= EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_PHYSICAL
| EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_LOGICAL
;
1620 Private
->ExtScsiPassThruMode
.IoAlign
= 4;
1621 Private
->IScsiExtScsiPassThru
.Mode
= &Private
->ExtScsiPassThruMode
;
1628 Clean the iSCSI driver data.
1630 @param[in] Private The iSCSI driver data.
1632 @retval EFI_SUCCESS The clean operation is successful.
1633 @retval Others Other errors as indicated.
1637 IScsiCleanDriverData (
1638 IN ISCSI_DRIVER_DATA
*Private
1643 Status
= EFI_SUCCESS
;
1645 if (Private
->DevicePath
!= NULL
) {
1646 Status
= gBS
->UninstallProtocolInterface (
1647 Private
->ExtScsiPassThruHandle
,
1648 &gEfiDevicePathProtocolGuid
,
1651 if (EFI_ERROR (Status
)) {
1655 FreePool (Private
->DevicePath
);
1658 if (Private
->ExtScsiPassThruHandle
!= NULL
) {
1659 Status
= gBS
->UninstallProtocolInterface (
1660 Private
->ExtScsiPassThruHandle
,
1661 &gEfiExtScsiPassThruProtocolGuid
,
1662 &Private
->IScsiExtScsiPassThru
1664 if (!EFI_ERROR (Status
)) {
1665 mPrivate
->OneSessionEstablished
= FALSE
;
1671 gBS
->CloseEvent (Private
->ExitBootServiceEvent
);
1673 mCallbackInfo
->Current
= NULL
;
1680 Check wheather the Controller handle is configured to use DHCP protocol.
1682 @param[in] Controller The handle of the controller.
1683 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
1685 @retval TRUE The handle of the controller need the Dhcp protocol.
1686 @retval FALSE The handle of the controller does not need the Dhcp protocol.
1690 IScsiDhcpIsConfigured (
1691 IN EFI_HANDLE Controller
,
1695 ISCSI_ATTEMPT_CONFIG_NVDATA
*AttemptTmp
;
1696 UINT8
*AttemptConfigOrder
;
1697 UINTN AttemptConfigOrderSize
;
1700 EFI_MAC_ADDRESS MacAddr
;
1701 UINTN HwAddressSize
;
1703 CHAR16 MacString
[ISCSI_MAX_MAC_STRING_LEN
];
1704 CHAR16 AttemptMacString
[ISCSI_MAX_MAC_STRING_LEN
];
1705 CHAR16 AttemptName
[ISCSI_NAME_IFR_MAX_SIZE
];
1707 AttemptConfigOrder
= IScsiGetVariableAndSize (
1710 &AttemptConfigOrderSize
1712 if (AttemptConfigOrder
== NULL
|| AttemptConfigOrderSize
== 0) {
1717 // Get MAC address of this network device.
1719 Status
= NetLibGetMacAddress (Controller
, &MacAddr
, &HwAddressSize
);
1720 if(EFI_ERROR (Status
)) {
1724 // Get VLAN ID of this network device.
1726 VlanId
= NetLibGetVlanId (Controller
);
1727 IScsiMacAddrToStr (&MacAddr
, (UINT32
) HwAddressSize
, VlanId
, MacString
);
1729 for (Index
= 0; Index
< AttemptConfigOrderSize
/ sizeof (UINT8
); Index
++) {
1734 (UINTN
) AttemptConfigOrder
[Index
]
1736 Status
= GetVariable2 (
1738 &gEfiIScsiInitiatorNameProtocolGuid
,
1739 (VOID
**)&AttemptTmp
,
1742 if(AttemptTmp
== NULL
|| EFI_ERROR (Status
)) {
1746 ASSERT (AttemptConfigOrder
[Index
] == AttemptTmp
->AttemptConfigIndex
);
1748 if (AttemptTmp
->SessionConfigData
.Enabled
== ISCSI_DISABLED
) {
1749 FreePool (AttemptTmp
);
1753 if (AttemptTmp
->SessionConfigData
.IpMode
!= IP_MODE_AUTOCONFIG
&&
1754 AttemptTmp
->SessionConfigData
.IpMode
!= ((IpVersion
== IP_VERSION_4
) ? IP_MODE_IP4
: IP_MODE_IP6
)) {
1755 FreePool (AttemptTmp
);
1759 AsciiStrToUnicodeStrS (AttemptTmp
->MacString
, AttemptMacString
, sizeof (AttemptMacString
) / sizeof (AttemptMacString
[0]));
1761 if (AttemptTmp
->Actived
== ISCSI_ACTIVE_DISABLED
|| StrCmp (MacString
, AttemptMacString
)) {
1765 if(AttemptTmp
->SessionConfigData
.IpMode
== IP_MODE_AUTOCONFIG
||
1766 AttemptTmp
->SessionConfigData
.InitiatorInfoFromDhcp
== TRUE
||
1767 AttemptTmp
->SessionConfigData
.TargetInfoFromDhcp
== TRUE
) {
1768 FreePool (AttemptTmp
);
1769 FreePool (AttemptConfigOrder
);
1773 FreePool (AttemptTmp
);
1776 FreePool (AttemptConfigOrder
);
1781 Check whether the Controller handle is configured to use DNS protocol.
1783 @param[in] Controller The handle of the controller.
1785 @retval TRUE The handle of the controller need the Dns protocol.
1786 @retval FALSE The handle of the controller does not need the Dns protocol.
1790 IScsiDnsIsConfigured (
1791 IN EFI_HANDLE Controller
1794 ISCSI_ATTEMPT_CONFIG_NVDATA
*AttemptTmp
;
1795 UINT8
*AttemptConfigOrder
;
1796 UINTN AttemptConfigOrderSize
;
1799 EFI_MAC_ADDRESS MacAddr
;
1800 UINTN HwAddressSize
;
1802 CHAR16 AttemptMacString
[ISCSI_MAX_MAC_STRING_LEN
];
1803 CHAR16 MacString
[ISCSI_MAX_MAC_STRING_LEN
];
1804 CHAR16 AttemptName
[ISCSI_NAME_IFR_MAX_SIZE
];
1806 AttemptConfigOrder
= IScsiGetVariableAndSize (
1809 &AttemptConfigOrderSize
1811 if (AttemptConfigOrder
== NULL
|| AttemptConfigOrderSize
== 0) {
1816 // Get MAC address of this network device.
1818 Status
= NetLibGetMacAddress (Controller
, &MacAddr
, &HwAddressSize
);
1819 if(EFI_ERROR (Status
)) {
1823 // Get VLAN ID of this network device.
1825 VlanId
= NetLibGetVlanId (Controller
);
1826 IScsiMacAddrToStr (&MacAddr
, (UINT32
) HwAddressSize
, VlanId
, MacString
);
1828 for (Index
= 0; Index
< AttemptConfigOrderSize
/ sizeof (UINT8
); Index
++) {
1833 (UINTN
) AttemptConfigOrder
[Index
]
1836 Status
= GetVariable2 (
1838 &gEfiIScsiInitiatorNameProtocolGuid
,
1839 (VOID
**)&AttemptTmp
,
1842 if(AttemptTmp
== NULL
|| EFI_ERROR (Status
)) {
1846 ASSERT (AttemptConfigOrder
[Index
] == AttemptTmp
->AttemptConfigIndex
);
1848 AsciiStrToUnicodeStrS (AttemptTmp
->MacString
, AttemptMacString
, sizeof (AttemptMacString
) / sizeof (AttemptMacString
[0]));
1850 if (AttemptTmp
->SessionConfigData
.Enabled
== ISCSI_DISABLED
|| StrCmp (MacString
, AttemptMacString
)) {
1851 FreePool (AttemptTmp
);
1855 if (AttemptTmp
->SessionConfigData
.DnsMode
) {
1856 FreePool (AttemptTmp
);
1857 FreePool (AttemptConfigOrder
);
1860 FreePool (AttemptTmp
);
1866 FreePool (AttemptConfigOrder
);
1872 Get the various configuration data.
1874 @param[in] Private The iSCSI driver data.
1876 @retval EFI_SUCCESS The configuration data is retrieved.
1877 @retval EFI_NOT_FOUND This iSCSI driver is not configured yet.
1878 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
1882 IScsiGetConfigData (
1883 IN ISCSI_DRIVER_DATA
*Private
1887 CHAR16 MacString
[ISCSI_MAX_MAC_STRING_LEN
];
1888 CHAR16 AttemptMacString
[ISCSI_MAX_MAC_STRING_LEN
];
1890 ISCSI_NIC_INFO
*NicInfo
;
1891 ISCSI_ATTEMPT_CONFIG_NVDATA
*AttemptConfigData
;
1892 ISCSI_ATTEMPT_CONFIG_NVDATA
*AttemptTmp
;
1893 UINT8
*AttemptConfigOrder
;
1894 UINTN AttemptConfigOrderSize
;
1895 CHAR16 IScsiMode
[64];
1899 // There should be at least one attempt configured.
1901 AttemptConfigOrder
= IScsiGetVariableAndSize (
1904 &AttemptConfigOrderSize
1906 if (AttemptConfigOrder
== NULL
|| AttemptConfigOrderSize
== 0) {
1907 return EFI_NOT_FOUND
;
1911 // Get the iSCSI Initiator Name.
1913 mPrivate
->InitiatorNameLength
= ISCSI_NAME_MAX_SIZE
;
1914 Status
= gIScsiInitiatorName
.Get (
1915 &gIScsiInitiatorName
,
1916 &mPrivate
->InitiatorNameLength
,
1917 mPrivate
->InitiatorName
1919 if (EFI_ERROR (Status
)) {
1924 // Get the normal configuration.
1926 for (Index
= 0; Index
< AttemptConfigOrderSize
/ sizeof (UINT8
); Index
++) {
1929 // Check whether the attempt exists in AttemptConfig.
1931 AttemptTmp
= IScsiConfigGetAttemptByConfigIndex (AttemptConfigOrder
[Index
]);
1932 if (AttemptTmp
!= NULL
&& AttemptTmp
->SessionConfigData
.Enabled
== ISCSI_DISABLED
) {
1934 } else if (AttemptTmp
!= NULL
&& AttemptTmp
->SessionConfigData
.Enabled
!= ISCSI_DISABLED
) {
1936 // Check the autoconfig path to see whether it should be retried.
1938 if (AttemptTmp
->SessionConfigData
.IpMode
== IP_MODE_AUTOCONFIG
&&
1939 !AttemptTmp
->AutoConfigureSuccess
) {
1940 if (mPrivate
->Ipv6Flag
&&
1941 AttemptTmp
->AutoConfigureMode
== IP_MODE_AUTOCONFIG_IP6
) {
1943 // Autoconfigure for IP6 already attempted but failed. Do not try again.
1946 } else if (!mPrivate
->Ipv6Flag
&&
1947 AttemptTmp
->AutoConfigureMode
== IP_MODE_AUTOCONFIG_IP4
) {
1949 // Autoconfigure for IP4 already attempted but failed. Do not try again.
1954 // Try another approach for this autoconfigure path.
1956 AttemptTmp
->AutoConfigureMode
=
1957 (UINT8
) (mPrivate
->Ipv6Flag
? IP_MODE_AUTOCONFIG_IP6
: IP_MODE_AUTOCONFIG_IP4
);
1958 AttemptTmp
->SessionConfigData
.InitiatorInfoFromDhcp
= TRUE
;
1959 AttemptTmp
->SessionConfigData
.TargetInfoFromDhcp
= TRUE
;
1960 AttemptTmp
->DhcpSuccess
= FALSE
;
1963 // Get some information from the dhcp server.
1965 if (!mPrivate
->Ipv6Flag
) {
1966 Status
= IScsiDoDhcp (Private
->Image
, Private
->Controller
, AttemptTmp
);
1967 if (!EFI_ERROR (Status
)) {
1968 AttemptTmp
->DhcpSuccess
= TRUE
;
1971 Status
= IScsiDoDhcp6 (Private
->Image
, Private
->Controller
, AttemptTmp
);
1972 if (!EFI_ERROR (Status
)) {
1973 AttemptTmp
->DhcpSuccess
= TRUE
;
1978 // Refresh the state of this attempt to NVR.
1981 mPrivate
->PortString
,
1982 (UINTN
) ISCSI_NAME_IFR_MAX_SIZE
,
1984 (UINTN
) AttemptTmp
->AttemptConfigIndex
1988 mPrivate
->PortString
,
1989 &gEfiIScsiInitiatorNameProtocolGuid
,
1990 ISCSI_CONFIG_VAR_ATTR
,
1991 sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA
),
1997 } else if (AttemptTmp
->SessionConfigData
.InitiatorInfoFromDhcp
&& !AttemptTmp
->ValidPath
) {
1999 // Get DHCP information for already added, but failed, attempt.
2001 AttemptTmp
->DhcpSuccess
= FALSE
;
2002 if (!mPrivate
->Ipv6Flag
&& (AttemptTmp
->SessionConfigData
.IpMode
== IP_MODE_IP4
)) {
2003 Status
= IScsiDoDhcp (Private
->Image
, Private
->Controller
, AttemptTmp
);
2004 if (!EFI_ERROR (Status
)) {
2005 AttemptTmp
->DhcpSuccess
= TRUE
;
2007 } else if (mPrivate
->Ipv6Flag
&& (AttemptTmp
->SessionConfigData
.IpMode
== IP_MODE_IP6
)) {
2008 Status
= IScsiDoDhcp6 (Private
->Image
, Private
->Controller
, AttemptTmp
);
2009 if (!EFI_ERROR (Status
)) {
2010 AttemptTmp
->DhcpSuccess
= TRUE
;
2015 // Refresh the state of this attempt to NVR.
2018 mPrivate
->PortString
,
2019 (UINTN
) ISCSI_NAME_IFR_MAX_SIZE
,
2021 (UINTN
) AttemptTmp
->AttemptConfigIndex
2025 mPrivate
->PortString
,
2026 &gEfiIScsiInitiatorNameProtocolGuid
,
2027 ISCSI_CONFIG_VAR_ATTR
,
2028 sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA
),
2040 // This attempt does not exist in AttemptConfig. Try to add a new one.
2043 NicInfo
= IScsiGetNicInfoByIndex (mPrivate
->CurrentNic
);
2044 ASSERT (NicInfo
!= NULL
);
2045 IScsiMacAddrToStr (&NicInfo
->PermanentAddress
, NicInfo
->HwAddressSize
, NicInfo
->VlanId
, MacString
);
2047 mPrivate
->PortString
,
2048 (UINTN
) ISCSI_NAME_IFR_MAX_SIZE
,
2050 (UINTN
) AttemptConfigOrder
[Index
]
2054 mPrivate
->PortString
,
2055 &gEfiIScsiInitiatorNameProtocolGuid
,
2056 (VOID
**)&AttemptConfigData
,
2059 AsciiStrToUnicodeStrS (AttemptConfigData
->MacString
, AttemptMacString
, sizeof (AttemptMacString
) / sizeof (AttemptMacString
[0]));
2061 if (AttemptConfigData
== NULL
|| AttemptConfigData
->Actived
== ISCSI_ACTIVE_DISABLED
||
2062 StrCmp (MacString
, AttemptMacString
)) {
2066 ASSERT (AttemptConfigOrder
[Index
] == AttemptConfigData
->AttemptConfigIndex
);
2068 AttemptConfigData
->NicIndex
= NicInfo
->NicIndex
;
2069 AttemptConfigData
->DhcpSuccess
= FALSE
;
2070 AttemptConfigData
->ValidiBFTPath
= (BOOLEAN
) (mPrivate
->EnableMpio
? TRUE
: FALSE
);
2071 AttemptConfigData
->ValidPath
= FALSE
;
2073 if (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_AUTOCONFIG
) {
2074 AttemptConfigData
->SessionConfigData
.InitiatorInfoFromDhcp
= TRUE
;
2075 AttemptConfigData
->SessionConfigData
.TargetInfoFromDhcp
= TRUE
;
2077 AttemptConfigData
->AutoConfigureMode
=
2078 (UINT8
) (mPrivate
->Ipv6Flag
? IP_MODE_AUTOCONFIG_IP6
: IP_MODE_AUTOCONFIG_IP4
);
2079 AttemptConfigData
->AutoConfigureSuccess
= FALSE
;
2083 // Get some information from dhcp server.
2085 if (AttemptConfigData
->SessionConfigData
.Enabled
!= ISCSI_DISABLED
&&
2086 AttemptConfigData
->SessionConfigData
.InitiatorInfoFromDhcp
) {
2088 if (!mPrivate
->Ipv6Flag
&&
2089 (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_IP4
||
2090 AttemptConfigData
->AutoConfigureMode
== IP_MODE_AUTOCONFIG_IP4
)) {
2091 Status
= IScsiDoDhcp (Private
->Image
, Private
->Controller
, AttemptConfigData
);
2092 if (!EFI_ERROR (Status
)) {
2093 AttemptConfigData
->DhcpSuccess
= TRUE
;
2095 } else if (mPrivate
->Ipv6Flag
&&
2096 (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_IP6
||
2097 AttemptConfigData
->AutoConfigureMode
== IP_MODE_AUTOCONFIG_IP6
)) {
2098 Status
= IScsiDoDhcp6 (Private
->Image
, Private
->Controller
, AttemptConfigData
);
2099 if (!EFI_ERROR (Status
)) {
2100 AttemptConfigData
->DhcpSuccess
= TRUE
;
2105 // Refresh the state of this attempt to NVR.
2108 mPrivate
->PortString
,
2109 (UINTN
) ISCSI_NAME_IFR_MAX_SIZE
,
2111 (UINTN
) AttemptConfigData
->AttemptConfigIndex
2115 mPrivate
->PortString
,
2116 &gEfiIScsiInitiatorNameProtocolGuid
,
2117 ISCSI_CONFIG_VAR_ATTR
,
2118 sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA
),
2124 // Update Attempt Help Info.
2127 if (AttemptConfigData
->SessionConfigData
.Enabled
== ISCSI_DISABLED
) {
2128 UnicodeSPrint (IScsiMode
, 64, L
"Disabled");
2129 } else if (AttemptConfigData
->SessionConfigData
.Enabled
== ISCSI_ENABLED
) {
2130 UnicodeSPrint (IScsiMode
, 64, L
"Enabled");
2131 } else if (AttemptConfigData
->SessionConfigData
.Enabled
== ISCSI_ENABLED_FOR_MPIO
) {
2132 UnicodeSPrint (IScsiMode
, 64, L
"Enabled for MPIO");
2135 if (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_IP4
) {
2136 UnicodeSPrint (IpMode
, 64, L
"IP4");
2137 } else if (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_IP6
) {
2138 UnicodeSPrint (IpMode
, 64, L
"IP6");
2139 } else if (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_AUTOCONFIG
) {
2140 UnicodeSPrint (IpMode
, 64, L
"Autoconfigure");
2144 mPrivate
->PortString
,
2145 (UINTN
) ISCSI_NAME_IFR_MAX_SIZE
,
2146 L
"MAC: %s, PFA: Bus %d | Dev %d | Func %d, iSCSI mode: %s, IP version: %s",
2149 NicInfo
->DeviceNumber
,
2150 NicInfo
->FunctionNumber
,
2155 AttemptConfigData
->AttemptTitleHelpToken
= HiiSetString (
2156 mCallbackInfo
->RegisteredHandle
,
2158 mPrivate
->PortString
,
2161 if (AttemptConfigData
->AttemptTitleHelpToken
== 0) {
2162 return EFI_OUT_OF_RESOURCES
;
2166 // Record the attempt in global link list.
2168 InsertTailList (&mPrivate
->AttemptConfigs
, &AttemptConfigData
->Link
);
2169 mPrivate
->AttemptCount
++;
2171 if (AttemptConfigData
->SessionConfigData
.Enabled
== ISCSI_ENABLED_FOR_MPIO
) {
2172 mPrivate
->MpioCount
++;
2173 mPrivate
->EnableMpio
= TRUE
;
2175 if (AttemptConfigData
->AuthenticationType
== ISCSI_AUTH_TYPE_KRB
) {
2176 mPrivate
->Krb5MpioCount
++;
2178 } else if (AttemptConfigData
->SessionConfigData
.Enabled
== ISCSI_ENABLED
) {
2179 mPrivate
->SinglePathCount
++;
2184 // Reorder the AttemptConfig by the configured order.
2186 for (Index
= 0; Index
< AttemptConfigOrderSize
/ sizeof (UINT8
); Index
++) {
2187 AttemptConfigData
= IScsiConfigGetAttemptByConfigIndex (AttemptConfigOrder
[Index
]);
2188 if (AttemptConfigData
== NULL
) {
2192 RemoveEntryList (&AttemptConfigData
->Link
);
2193 InsertTailList (&mPrivate
->AttemptConfigs
, &AttemptConfigData
->Link
);
2197 // Update the Main Form.
2199 IScsiConfigUpdateAttempt ();
2201 FreePool (AttemptConfigOrder
);
2204 // There should be at least one attempt configuration.
2206 if (!mPrivate
->EnableMpio
) {
2207 if (mPrivate
->SinglePathCount
== 0) {
2208 return EFI_NOT_FOUND
;
2210 mPrivate
->ValidSinglePathCount
= mPrivate
->SinglePathCount
;
2218 Get the device path of the iSCSI tcp connection and update it.
2220 @param Session The iSCSI session.
2222 @return The updated device path.
2223 @retval NULL Other errors as indicated.
2226 EFI_DEVICE_PATH_PROTOCOL
*
2227 IScsiGetTcpConnDevicePath (
2228 IN ISCSI_SESSION
*Session
2231 ISCSI_CONNECTION
*Conn
;
2232 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
2234 EFI_DEV_PATH
*DPathNode
;
2237 if (Session
->State
!= SESSION_STATE_LOGGED_IN
) {
2241 Conn
= NET_LIST_USER_STRUCT_S (
2242 Session
->Conns
.ForwardLink
,
2245 ISCSI_CONNECTION_SIGNATURE
2248 Status
= gBS
->HandleProtocol (
2250 &gEfiDevicePathProtocolGuid
,
2251 (VOID
**) &DevicePath
2253 if (EFI_ERROR (Status
)) {
2259 DevicePath
= DuplicateDevicePath (DevicePath
);
2260 if (DevicePath
== NULL
) {
2264 DPathNode
= (EFI_DEV_PATH
*) DevicePath
;
2266 while (!IsDevicePathEnd (&DPathNode
->DevPath
)) {
2267 if (DevicePathType (&DPathNode
->DevPath
) == MESSAGING_DEVICE_PATH
) {
2268 if (!Conn
->Ipv6Flag
&& DevicePathSubType (&DPathNode
->DevPath
) == MSG_IPv4_DP
) {
2269 DPathNode
->Ipv4
.LocalPort
= 0;
2271 DPathNode
->Ipv4
.StaticIpAddress
=
2272 (BOOLEAN
) (!Session
->ConfigData
->SessionConfigData
.InitiatorInfoFromDhcp
);
2275 // Add a judgement here to support previous versions of IPv4_DEVICE_PATH.
2276 // In previous versions of IPv4_DEVICE_PATH, GatewayIpAddress and SubnetMask
2278 // In new version of IPv4_DEVICE_PATH, structcure length is 27.
2281 PathLen
= DevicePathNodeLength (&DPathNode
->Ipv4
);
2283 if (PathLen
== IP4_NODE_LEN_NEW_VERSIONS
) {
2286 &DPathNode
->Ipv4
.GatewayIpAddress
,
2287 &Session
->ConfigData
->SessionConfigData
.Gateway
2291 &DPathNode
->Ipv4
.SubnetMask
,
2292 &Session
->ConfigData
->SessionConfigData
.SubnetMask
2297 } else if (Conn
->Ipv6Flag
&& DevicePathSubType (&DPathNode
->DevPath
) == MSG_IPv6_DP
) {
2298 DPathNode
->Ipv6
.LocalPort
= 0;
2301 // Add a judgement here to support previous versions of IPv6_DEVICE_PATH.
2302 // In previous versions of IPv6_DEVICE_PATH, IpAddressOrigin, PrefixLength
2303 // and GatewayIpAddress do not exist.
2304 // In new version of IPv6_DEVICE_PATH, structure length is 60, while in
2305 // old versions, the length is 43.
2308 PathLen
= DevicePathNodeLength (&DPathNode
->Ipv6
);
2310 if (PathLen
== IP6_NODE_LEN_NEW_VERSIONS
) {
2312 DPathNode
->Ipv6
.IpAddressOrigin
= 0;
2313 DPathNode
->Ipv6
.PrefixLength
= IP6_PREFIX_LENGTH
;
2314 ZeroMem (&DPathNode
->Ipv6
.GatewayIpAddress
, sizeof (EFI_IPv6_ADDRESS
));
2316 else if (PathLen
== IP6_NODE_LEN_OLD_VERSIONS
) {
2319 // StaticIPAddress is a field in old versions of IPv6_DEVICE_PATH, while ignored in new
2320 // version. Set StaticIPAddress through its' offset in old IPv6_DEVICE_PATH.
2322 *((UINT8
*)(&DPathNode
->Ipv6
) + IP6_OLD_IPADDRESS_OFFSET
) =
2323 (BOOLEAN
) (!Session
->ConfigData
->SessionConfigData
.InitiatorInfoFromDhcp
);
2330 DPathNode
= (EFI_DEV_PATH
*) NextDevicePathNode (&DPathNode
->DevPath
);
2338 Abort the session when the transition from BS to RT is initiated.
2340 @param[in] Event The event signaled.
2341 @param[in] Context The iSCSI driver data.
2346 IScsiOnExitBootService (
2351 ISCSI_DRIVER_DATA
*Private
;
2353 Private
= (ISCSI_DRIVER_DATA
*) Context
;
2354 gBS
->CloseEvent (Private
->ExitBootServiceEvent
);
2356 if (Private
->Session
!= NULL
) {
2357 IScsiSessionAbort (Private
->Session
);
2362 Tests whether a controller handle is being managed by IScsi driver.
2364 This function tests whether the driver specified by DriverBindingHandle is
2365 currently managing the controller specified by ControllerHandle. This test
2366 is performed by evaluating if the the protocol specified by ProtocolGuid is
2367 present on ControllerHandle and is was opened by DriverBindingHandle and Nic
2368 Device handle with an attribute of EFI_OPEN_PROTOCOL_BY_DRIVER.
2369 If ProtocolGuid is NULL, then ASSERT().
2371 @param ControllerHandle A handle for a controller to test.
2372 @param DriverBindingHandle Specifies the driver binding handle for the
2374 @param ProtocolGuid Specifies the protocol that the driver specified
2375 by DriverBindingHandle opens in its Start()
2378 @retval EFI_SUCCESS ControllerHandle is managed by the driver
2379 specified by DriverBindingHandle.
2380 @retval EFI_UNSUPPORTED ControllerHandle is not managed by the driver
2381 specified by DriverBindingHandle.
2386 IScsiTestManagedDevice (
2387 IN EFI_HANDLE ControllerHandle
,
2388 IN EFI_HANDLE DriverBindingHandle
,
2389 IN EFI_GUID
*ProtocolGuid
2393 VOID
*ManagedInterface
;
2394 EFI_HANDLE NicControllerHandle
;
2396 ASSERT (ProtocolGuid
!= NULL
);
2398 NicControllerHandle
= NetLibGetNicHandle (ControllerHandle
, ProtocolGuid
);
2399 if (NicControllerHandle
== NULL
) {
2400 return EFI_UNSUPPORTED
;
2403 Status
= gBS
->OpenProtocol (
2405 (EFI_GUID
*) ProtocolGuid
,
2407 DriverBindingHandle
,
2408 NicControllerHandle
,
2409 EFI_OPEN_PROTOCOL_BY_DRIVER
2411 if (!EFI_ERROR (Status
)) {
2412 gBS
->CloseProtocol (
2414 (EFI_GUID
*) ProtocolGuid
,
2415 DriverBindingHandle
,
2418 return EFI_UNSUPPORTED
;
2421 if (Status
!= EFI_ALREADY_STARTED
) {
2422 return EFI_UNSUPPORTED
;