2 The implementation of iSCSI protocol based on RFC3720.
4 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 UINT32 mDataSegPad
= 0;
14 Attach the iSCSI connection to the iSCSI session.
16 @param[in, out] Session The iSCSI session.
17 @param[in, out] Conn The iSCSI connection.
21 IScsiAttatchConnection (
22 IN OUT ISCSI_SESSION
*Session
,
23 IN OUT ISCSI_CONNECTION
*Conn
26 InsertTailList (&Session
->Conns
, &Conn
->Link
);
27 Conn
->Session
= Session
;
32 Detach the iSCSI connection from the session it belongs to.
34 @param[in, out] Conn The iSCSI connection.
38 IScsiDetatchConnection (
39 IN OUT ISCSI_CONNECTION
*Conn
42 RemoveEntryList (&Conn
->Link
);
43 Conn
->Session
->NumConns
--;
49 Check the sequence number according to RFC3720.
51 @param[in, out] ExpSN The currently expected sequence number.
52 @param[in] NewSN The sequence number to check.
54 @retval EFI_SUCCESS The check passed and the ExpSN is increased.
55 @retval EFI_NOT_READY Response was sent due to a retransmission request.
56 @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error occurred.
65 if (!ISCSI_SEQ_EQ (NewSN
, *ExpSN
)) {
66 if (ISCSI_SEQ_LT (NewSN
, *ExpSN
)) {
72 return EFI_PROTOCOL_ERROR
;
85 Update the sequence numbers for the iSCSI command.
87 @param[in, out] Session The iSCSI session.
88 @param[in] MaxCmdSN Maximum CmdSN from the target.
89 @param[in] ExpCmdSN Next expected CmdSN from the target.
94 IN OUT ISCSI_SESSION
*Session
,
99 if (ISCSI_SEQ_LT (MaxCmdSN
, ExpCmdSN
- 1)) {
103 if (ISCSI_SEQ_GT (MaxCmdSN
, Session
->MaxCmdSN
)) {
104 Session
->MaxCmdSN
= MaxCmdSN
;
107 if (ISCSI_SEQ_GT (ExpCmdSN
, Session
->ExpCmdSN
)) {
108 Session
->ExpCmdSN
= ExpCmdSN
;
114 This function does the iSCSI connection login.
116 @param[in, out] Conn The iSCSI connection to login.
117 @param Timeout The timeout value in millisecond.
119 @retval EFI_SUCCESS The iSCSI connection is logged into the iSCSI target.
120 @retval EFI_TIMEOUT Timeout occurred during the login procedure.
121 @retval Others Other errors as indicated.
126 IN OUT ISCSI_CONNECTION
*Conn
,
133 // Start the timer, and wait Timeout seconds to establish the TCP connection.
135 Status
= gBS
->SetTimer (
138 MultU64x32 (Timeout
, TICKS_PER_MS
)
140 if (EFI_ERROR (Status
)) {
145 // Try to establish the tcp connection.
147 Status
= TcpIoConnect (&Conn
->TcpIo
, Conn
->TimeoutEvent
);
148 gBS
->SetTimer (Conn
->TimeoutEvent
, TimerCancel
, 0);
150 if (EFI_ERROR (Status
)) {
154 Conn
->State
= CONN_STATE_IN_LOGIN
;
157 // Connection is established, start the iSCSI Login.
160 Status
= IScsiSendLoginReq (Conn
);
161 if (EFI_ERROR (Status
)) {
165 Status
= IScsiReceiveLoginRsp (Conn
);
166 if (EFI_ERROR (Status
)) {
169 } while (Conn
->CurrentStage
!= ISCSI_FULL_FEATURE_PHASE
);
176 Reset the iSCSI connection.
178 @param[in, out] Conn The iSCSI connection to reset.
183 IN OUT ISCSI_CONNECTION
*Conn
186 TcpIoReset (&Conn
->TcpIo
);
191 Create a TCP connection for the iSCSI session.
193 @param[in] Session Points to the iSCSI session.
195 @return The newly created iSCSI connection.
199 IScsiCreateConnection (
200 IN ISCSI_SESSION
*Session
203 ISCSI_DRIVER_DATA
*Private
;
204 ISCSI_SESSION_CONFIG_NVDATA
*NvData
;
205 ISCSI_CONNECTION
*Conn
;
206 TCP_IO_CONFIG_DATA TcpIoConfig
;
207 TCP4_IO_CONFIG_DATA
*Tcp4IoConfig
;
208 TCP6_IO_CONFIG_DATA
*Tcp6IoConfig
;
211 Private
= Session
->Private
;
212 NvData
= &Session
->ConfigData
->SessionConfigData
;
214 Conn
= AllocateZeroPool (sizeof (ISCSI_CONNECTION
));
219 Conn
->Signature
= ISCSI_CONNECTION_SIGNATURE
;
220 Conn
->State
= CONN_STATE_FREE
;
221 Conn
->CurrentStage
= ISCSI_SECURITY_NEGOTIATION
;
222 Conn
->NextStage
= ISCSI_LOGIN_OPERATIONAL_NEGOTIATION
;
223 Conn
->AuthStep
= ISCSI_AUTH_INITIAL
;
225 Conn
->PartialReqSent
= FALSE
;
226 Conn
->PartialRspRcvd
= FALSE
;
227 Conn
->ParamNegotiated
= FALSE
;
228 Conn
->Cid
= Session
->NextCid
++;
229 Conn
->Ipv6Flag
= NvData
->IpMode
== IP_MODE_IP6
|| Session
->ConfigData
->AutoConfigureMode
== IP_MODE_AUTOCONFIG_IP6
;
231 Status
= gBS
->CreateEvent (
238 if (EFI_ERROR (Status
)) {
243 NetbufQueInit (&Conn
->RspQue
);
246 // Set the default connection-only parameters.
248 Conn
->MaxRecvDataSegmentLength
= DEFAULT_MAX_RECV_DATA_SEG_LEN
;
249 Conn
->HeaderDigest
= IScsiDigestNone
;
250 Conn
->DataDigest
= IScsiDigestNone
;
252 if (NvData
->DnsMode
) {
254 // perform dns process if target address expressed by domain name.
256 if (!Conn
->Ipv6Flag
) {
257 Status
= IScsiDns4 (Private
->Image
, Private
->Controller
, NvData
);
259 Status
= IScsiDns6 (Private
->Image
, Private
->Controller
, NvData
);
262 if (EFI_ERROR(Status
)) {
263 DEBUG ((EFI_D_ERROR
, "The configuration of Target address or DNS server address is invalid!\n"));
269 if (!Conn
->Ipv6Flag
) {
270 Tcp4IoConfig
= &TcpIoConfig
.Tcp4IoConfigData
;
272 CopyMem (&Tcp4IoConfig
->LocalIp
, &NvData
->LocalIp
, sizeof (EFI_IPv4_ADDRESS
));
273 CopyMem (&Tcp4IoConfig
->SubnetMask
, &NvData
->SubnetMask
, sizeof (EFI_IPv4_ADDRESS
));
274 CopyMem (&Tcp4IoConfig
->Gateway
, &NvData
->Gateway
, sizeof (EFI_IPv4_ADDRESS
));
275 CopyMem (&Tcp4IoConfig
->RemoteIp
, &NvData
->TargetIp
, sizeof (EFI_IPv4_ADDRESS
));
277 Tcp4IoConfig
->RemotePort
= NvData
->TargetPort
;
278 Tcp4IoConfig
->ActiveFlag
= TRUE
;
279 Tcp4IoConfig
->StationPort
= 0;
281 Tcp6IoConfig
= &TcpIoConfig
.Tcp6IoConfigData
;
283 CopyMem (&Tcp6IoConfig
->RemoteIp
, &NvData
->TargetIp
, sizeof (EFI_IPv6_ADDRESS
));
284 Tcp6IoConfig
->RemotePort
= NvData
->TargetPort
;
285 Tcp6IoConfig
->ActiveFlag
= TRUE
;
286 Tcp6IoConfig
->StationPort
= 0;
290 // Create the TCP IO for this connection.
292 Status
= TcpIoCreateSocket (
295 (UINT8
) (!Conn
->Ipv6Flag
? TCP_VERSION_4
: TCP_VERSION_6
),
299 if (EFI_ERROR (Status
)) {
300 gBS
->CloseEvent (Conn
->TimeoutEvent
);
310 Destroy an iSCSI connection.
312 @param[in] Conn The connection to destroy.
316 IScsiDestroyConnection (
317 IN ISCSI_CONNECTION
*Conn
320 TcpIoDestroySocket (&Conn
->TcpIo
);
322 NetbufQueFlush (&Conn
->RspQue
);
323 gBS
->CloseEvent (Conn
->TimeoutEvent
);
328 Retrieve the IPv6 Address/Prefix/Gateway from the established TCP connection, these informations
329 will be filled in the iSCSI Boot Firmware Table.
331 @param[in] Conn The connection used in the iSCSI login phase.
333 @retval EFI_SUCCESS Get the NIC information successfully.
334 @retval Others Other errors as indicated.
339 IN ISCSI_CONNECTION
*Conn
342 ISCSI_SESSION_CONFIG_NVDATA
*NvData
;
343 EFI_TCP6_PROTOCOL
*Tcp6
;
344 EFI_IP6_MODE_DATA Ip6ModeData
;
346 EFI_IPv6_ADDRESS
*TargetIp
;
348 UINT8 SubnetPrefixLength
;
351 NvData
= &Conn
->Session
->ConfigData
->SessionConfigData
;
352 TargetIp
= &NvData
->TargetIp
.v6
;
353 Tcp6
= Conn
->TcpIo
.Tcp
.Tcp6
;
355 ZeroMem (&Ip6ModeData
, sizeof (EFI_IP6_MODE_DATA
));
356 Status
= Tcp6
->GetModeData (
364 if (EFI_ERROR (Status
)) {
368 if (!Ip6ModeData
.IsConfigured
) {
369 Status
= EFI_ABORTED
;
373 IP6_COPY_ADDRESS (&NvData
->LocalIp
, &Ip6ModeData
.ConfigData
.StationAddress
);
375 NvData
->PrefixLength
= 0;
376 for (Index
= 0; Index
< Ip6ModeData
.AddressCount
; Index
++) {
377 if (EFI_IP6_EQUAL (&NvData
->LocalIp
.v6
, &Ip6ModeData
.AddressList
[Index
].Address
)) {
378 NvData
->PrefixLength
= Ip6ModeData
.AddressList
[Index
].PrefixLength
;
383 SubnetPrefixLength
= 0;
384 RouteEntry
= Ip6ModeData
.RouteCount
;
385 for (Index
= 0; Index
< Ip6ModeData
.RouteCount
; Index
++) {
386 if (NetIp6IsNetEqual (TargetIp
, &Ip6ModeData
.RouteTable
[Index
].Destination
, Ip6ModeData
.RouteTable
[Index
].PrefixLength
)) {
387 if (SubnetPrefixLength
< Ip6ModeData
.RouteTable
[Index
].PrefixLength
) {
388 SubnetPrefixLength
= Ip6ModeData
.RouteTable
[Index
].PrefixLength
;
393 if (RouteEntry
!= Ip6ModeData
.RouteCount
) {
394 IP6_COPY_ADDRESS (&NvData
->Gateway
, &Ip6ModeData
.RouteTable
[RouteEntry
].Gateway
);
398 if (Ip6ModeData
.AddressList
!= NULL
) {
399 FreePool (Ip6ModeData
.AddressList
);
401 if (Ip6ModeData
.GroupTable
!= NULL
) {
402 FreePool (Ip6ModeData
.GroupTable
);
404 if (Ip6ModeData
.RouteTable
!= NULL
) {
405 FreePool (Ip6ModeData
.RouteTable
);
407 if (Ip6ModeData
.NeighborCache
!= NULL
) {
408 FreePool (Ip6ModeData
.NeighborCache
);
410 if (Ip6ModeData
.PrefixTable
!= NULL
) {
411 FreePool (Ip6ModeData
.PrefixTable
);
413 if (Ip6ModeData
.IcmpTypeList
!= NULL
) {
414 FreePool (Ip6ModeData
.IcmpTypeList
);
421 Re-set any stateful session-level authentication information that is used by
422 the leading login / leading connection.
424 (Note that this driver only supports a single connection per session -- see
425 ISCSI_MAX_CONNS_PER_SESSION.)
427 @param[in,out] Session The iSCSI session.
431 IScsiSessionResetAuthData (
432 IN OUT ISCSI_SESSION
*Session
438 Login the iSCSI session.
440 @param[in] Session The iSCSI session.
442 @retval EFI_SUCCESS The iSCSI session login procedure finished.
443 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
444 @retval EFI_NO_MEDIA There was a media error.
445 @retval Others Other errors as indicated.
450 IN ISCSI_SESSION
*Session
454 ISCSI_CONNECTION
*Conn
;
456 EFI_GUID
*ProtocolGuid
;
458 EFI_STATUS MediaStatus
;
461 // Check media status before session login.
463 MediaStatus
= EFI_SUCCESS
;
464 NetLibDetectMediaWaitTimeout (Session
->Private
->Controller
, ISCSI_CHECK_MEDIA_LOGIN_WAITING_TIME
, &MediaStatus
);
465 if (MediaStatus
!= EFI_SUCCESS
) {
470 // Set session identifier
472 CopyMem (Session
->Isid
, Session
->ConfigData
->SessionConfigData
.IsId
, 6);
478 // Create a connection for the session.
480 Conn
= IScsiCreateConnection (Session
);
482 return EFI_OUT_OF_RESOURCES
;
485 IScsiAttatchConnection (Session
, Conn
);
488 // Login through the newly created connection.
490 IScsiSessionResetAuthData (Session
);
491 Status
= IScsiConnLogin (Conn
, Session
->ConfigData
->SessionConfigData
.ConnectTimeout
);
492 if (EFI_ERROR (Status
)) {
493 IScsiConnReset (Conn
);
494 IScsiDetatchConnection (Conn
);
495 IScsiDestroyConnection (Conn
);
498 if (Status
!= EFI_TIMEOUT
) {
503 } while (RetryCount
<= Session
->ConfigData
->SessionConfigData
.ConnectRetryCount
);
505 if (!EFI_ERROR (Status
)) {
506 Session
->State
= SESSION_STATE_LOGGED_IN
;
508 if (!Conn
->Ipv6Flag
) {
509 ProtocolGuid
= &gEfiTcp4ProtocolGuid
;
511 ProtocolGuid
= &gEfiTcp6ProtocolGuid
;
514 Status
= gBS
->OpenProtocol (
518 Session
->Private
->Image
,
519 Session
->Private
->ExtScsiPassThruHandle
,
520 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
523 ASSERT_EFI_ERROR (Status
);
525 if (Conn
->Ipv6Flag
) {
526 Status
= IScsiGetIp6NicInfo (Conn
);
535 Wait for IPsec negotiation, then try to login the iSCSI session again.
537 @param[in] Session The iSCSI session.
539 @retval EFI_SUCCESS The iSCSI session login procedure finished.
540 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
541 @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error occurred.
545 IScsiSessionReLogin (
546 IN ISCSI_SESSION
*Session
551 EFI_STATUS TimerStatus
;
554 Status
= gBS
->CreateEvent (EVT_TIMER
, TPL_CALLBACK
, NULL
, NULL
, &Timer
);
555 if (EFI_ERROR (Status
)) {
559 Status
= gBS
->SetTimer (
562 ISCSI_WAIT_IPSEC_TIMEOUT
565 if (EFI_ERROR (Status
)) {
566 gBS
->CloseEvent (Timer
);
572 TimerStatus
= gBS
->CheckEvent (Timer
);
574 if (!EFI_ERROR (TimerStatus
)) {
575 Status
= IScsiSessionLogin (Session
);
578 } while (TimerStatus
== EFI_NOT_READY
);
580 gBS
->CloseEvent (Timer
);
586 Build and send the iSCSI login request to the iSCSI target according to
587 the current login stage.
589 @param[in] Conn The connection in the iSCSI login phase.
591 @retval EFI_SUCCESS The iSCSI login request PDU is built and sent on this
593 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
594 @retval EFI_DEVICE_ERROR Some kind of device error occurred.
599 IN ISCSI_CONNECTION
*Conn
606 // Build the Login Request PDU.
608 Pdu
= IScsiPrepareLoginReq (Conn
);
610 return EFI_DEVICE_ERROR
;
613 // Send it to the iSCSI target.
615 Status
= TcpIoTransmit (&Conn
->TcpIo
, Pdu
);
624 Receive and process the iSCSI login response.
626 @param[in] Conn The connection in the iSCSI login phase.
628 @retval EFI_SUCCESS The iSCSI login response PDU is received and processed.
629 @retval Others Other errors as indicated.
633 IScsiReceiveLoginRsp (
634 IN ISCSI_CONNECTION
*Conn
643 // Receive the iSCSI login response.
645 Status
= IScsiReceivePdu (Conn
, &Pdu
, NULL
, FALSE
, FALSE
, NULL
);
646 if (EFI_ERROR (Status
)) {
649 ASSERT (Pdu
!= NULL
);
652 // A Login Response is received; process it.
654 Status
= IScsiProcessLoginRsp (Conn
, Pdu
);
663 Add an iSCSI key-value pair as a string into the data segment of the Login Request PDU.
664 The DataSegmentLength and the actual size of the net buffer containing this PDU will be
667 @param[in, out] Pdu The iSCSI PDU whose data segment the key-value pair will
669 @param[in] Key The key name string.
670 @param[in] Value The value string.
672 @retval EFI_SUCCESS The key-value pair is added to the PDU's data segment and
673 the correspondence length fields are updated.
674 @retval EFI_OUT_OF_RESOURCES There is not enough space in the PDU to add the key-value
676 @retval EFI_PROTOCOL_ERROR There is no such data in the net buffer.
679 IScsiAddKeyValuePair (
689 ISCSI_LOGIN_REQUEST
*LoginReq
;
692 LoginReq
= (ISCSI_LOGIN_REQUEST
*) NetbufGetByte (Pdu
, 0, NULL
);
693 if (LoginReq
== NULL
) {
694 return EFI_PROTOCOL_ERROR
;
696 DataSegLen
= NTOH24 (LoginReq
->DataSegmentLength
);
698 KeyLen
= (UINT32
) AsciiStrLen (Key
);
699 ValueLen
= (UINT32
) AsciiStrLen (Value
);
702 // 1 byte for the key value separator '=' and 1 byte for the null
703 // delimiter after the value.
705 TotalLen
= KeyLen
+ 1 + ValueLen
+ 1;
708 // Allocate the space for the key-value pair.
710 Data
= (CHAR8
*) NetbufAllocSpace (Pdu
, TotalLen
, NET_BUF_TAIL
);
712 return EFI_OUT_OF_RESOURCES
;
717 CopyMem (Data
, Key
, KeyLen
);
726 CopyMem (Data
, Value
, ValueLen
);
732 // Update the DataSegmentLength
734 ISCSI_SET_DATASEG_LEN (LoginReq
, DataSegLen
+ TotalLen
);
741 Prepare the iSCSI login request to be sent according to the current login status.
743 @param[in, out] Conn The connection in the iSCSI login phase.
745 @return The pointer to the net buffer containing the iSCSI login request built.
746 @retval NULL Other errors as indicated.
750 IScsiPrepareLoginReq (
751 IN OUT ISCSI_CONNECTION
*Conn
754 ISCSI_SESSION
*Session
;
756 ISCSI_LOGIN_REQUEST
*LoginReq
;
759 Session
= Conn
->Session
;
761 Nbuf
= NetbufAlloc (sizeof (ISCSI_LOGIN_REQUEST
) + DEFAULT_MAX_RECV_DATA_SEG_LEN
);
766 LoginReq
= (ISCSI_LOGIN_REQUEST
*) NetbufAllocSpace (Nbuf
, sizeof (ISCSI_LOGIN_REQUEST
), NET_BUF_TAIL
);
767 if (LoginReq
== NULL
) {
771 ZeroMem (LoginReq
, sizeof (ISCSI_LOGIN_REQUEST
));
774 // Init the login request pdu
776 ISCSI_SET_OPCODE (LoginReq
, ISCSI_OPCODE_LOGIN_REQ
, ISCSI_REQ_IMMEDIATE
);
777 ISCSI_SET_STAGES (LoginReq
, Conn
->CurrentStage
, Conn
->NextStage
);
778 LoginReq
->VersionMax
= ISCSI_VERSION_MAX
;
779 LoginReq
->VersionMin
= ISCSI_VERSION_MIN
;
780 LoginReq
->Tsih
= HTONS (Session
->Tsih
);
781 LoginReq
->InitiatorTaskTag
= HTONL (Session
->InitiatorTaskTag
);
782 LoginReq
->Cid
= HTONS (Conn
->Cid
);
783 LoginReq
->CmdSN
= HTONL (Session
->CmdSN
);
786 // For the first Login Request on a connection this is ExpStatSN for the
787 // old connection, and this field is only valid if the Login Request restarts
789 // For subsequent Login Requests it is used to acknowledge the Login Responses
790 // with their increasing StatSN values.
792 LoginReq
->ExpStatSN
= HTONL (Conn
->ExpStatSN
);
793 CopyMem (LoginReq
->Isid
, Session
->Isid
, sizeof (LoginReq
->Isid
));
795 if (Conn
->PartialRspRcvd
) {
797 // A partial response. The initiator must send an empty Login Request.
802 Status
= EFI_SUCCESS
;
804 switch (Conn
->CurrentStage
) {
805 case ISCSI_SECURITY_NEGOTIATION
:
807 // Both none authentication and CHAP authentication share the CHAP path.
810 if (Session
->AuthType
!= ISCSI_AUTH_TYPE_KRB
) {
811 Status
= IScsiCHAPToSendReq (Conn
, Nbuf
);
816 case ISCSI_LOGIN_OPERATIONAL_NEGOTIATION
:
818 // Only negotiate the parameter once.
820 if (!Conn
->ParamNegotiated
) {
821 IScsiFillOpParams (Conn
, Nbuf
);
824 ISCSI_SET_FLAG (LoginReq
, ISCSI_LOGIN_REQ_PDU_FLAG_TRANSIT
);
829 // An error occurs...
831 Status
= EFI_DEVICE_ERROR
;
835 if (EFI_ERROR (Status
)) {
840 // Pad the data segment if needed.
842 IScsiPadSegment (Nbuf
, ISCSI_GET_DATASEG_LEN (LoginReq
));
844 // Check whether we will issue the stage transition signal?
846 Conn
->TransitInitiated
= ISCSI_FLAG_ON (LoginReq
, ISCSI_LOGIN_REQ_PDU_FLAG_TRANSIT
);
854 Process the iSCSI Login Response.
856 @param[in, out] Conn The connection on which the iSCSI login response is received.
857 @param[in, out] Pdu The iSCSI login response PDU.
859 @retval EFI_SUCCESS The iSCSI login response PDU is processed, and all checks are passed.
860 @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error occurred.
861 @retval EFI_MEDIA_CHANGED Target is redirected.
862 @retval Others Other errors as indicated.
866 IScsiProcessLoginRsp (
867 IN OUT ISCSI_CONNECTION
*Conn
,
872 ISCSI_SESSION
*Session
;
873 ISCSI_LOGIN_RESPONSE
*LoginRsp
;
881 Status
= EFI_SUCCESS
;
882 Session
= Conn
->Session
;
884 LoginRsp
= (ISCSI_LOGIN_RESPONSE
*) NetbufGetByte (Pdu
, 0, NULL
);
885 if (LoginRsp
== NULL
) {
886 return EFI_PROTOCOL_ERROR
;
888 if (!ISCSI_CHECK_OPCODE (LoginRsp
, ISCSI_OPCODE_LOGIN_RSP
)) {
890 // It is not a Login Response.
892 return EFI_PROTOCOL_ERROR
;
895 // Get the data segment, if any.
897 DataSegLen
= ISCSI_GET_DATASEG_LEN (LoginRsp
);
898 if (DataSegLen
!= 0) {
899 DataSeg
= NetbufGetByte (Pdu
, sizeof (ISCSI_LOGIN_RESPONSE
), NULL
);
904 // Check the status class in the login response PDU.
906 switch (LoginRsp
->StatusClass
) {
907 case ISCSI_LOGIN_STATUS_SUCCESS
:
909 // Just break here; the response and the data segment will be processed later.
913 case ISCSI_LOGIN_STATUS_REDIRECTION
:
915 // The target may be moved to a different address.
917 if (DataSeg
== NULL
) {
918 return EFI_PROTOCOL_ERROR
;
921 // Process the TargetAddress key-value strings in the data segment to update the
922 // target address info.
924 Status
= IScsiUpdateTargetAddress (Session
, (CHAR8
*) DataSeg
, DataSegLen
);
925 if (EFI_ERROR (Status
)) {
929 // Session will be restarted on this error status because the Target is
930 // redirected by this Login Response.
932 return EFI_MEDIA_CHANGED
;
936 // Initiator Error, Target Error, or any other undefined error code.
938 return EFI_PROTOCOL_ERROR
;
941 // The status is success; extract the wanted fields from the header segment.
943 Transit
= ISCSI_FLAG_ON (LoginRsp
, ISCSI_LOGIN_RSP_PDU_FLAG_TRANSIT
);
944 Continue
= ISCSI_FLAG_ON (LoginRsp
, ISCSI_LOGIN_RSP_PDU_FLAG_CONTINUE
);
946 CurrentStage
= ISCSI_GET_CURRENT_STAGE (LoginRsp
);
947 NextStage
= ISCSI_GET_NEXT_STAGE (LoginRsp
);
949 LoginRsp
->InitiatorTaskTag
= NTOHL (LoginRsp
->InitiatorTaskTag
);
951 if ((Transit
&& Continue
) ||
952 (CurrentStage
!= Conn
->CurrentStage
) ||
953 (!Conn
->TransitInitiated
&& Transit
) ||
954 (Transit
&& (NextStage
!= Conn
->NextStage
)) ||
955 (CompareMem (Session
->Isid
, LoginRsp
->Isid
, sizeof (LoginRsp
->Isid
)) != 0) ||
956 (LoginRsp
->InitiatorTaskTag
!= Session
->InitiatorTaskTag
)
959 // A Login Response with the C bit set to 1 MUST have the T bit set to 0.
960 // The CSG in the Login Response MUST be the same with the I-end of this connection.
961 // The T bit can't be 1 if the last Login Response sent by the initiator doesn't
962 // initiate the transition.
963 // The NSG MUST be the same with the I-end of this connection if Transit is required.
964 // The ISID in the Login Response MUST be the same with this session.
966 return EFI_PROTOCOL_ERROR
;
969 LoginRsp
->StatSN
= NTOHL (LoginRsp
->StatSN
);
970 LoginRsp
->ExpCmdSN
= NTOHL (LoginRsp
->ExpCmdSN
);
971 LoginRsp
->MaxCmdSN
= NTOHL (LoginRsp
->MaxCmdSN
);
973 if ((Conn
->CurrentStage
== ISCSI_SECURITY_NEGOTIATION
) && (Conn
->AuthStep
== ISCSI_AUTH_INITIAL
)) {
975 // If the Login Request is a leading Login Request, the target MUST use
976 // the value presented in CmdSN as the target value for ExpCmdSN.
978 if ((Session
->State
== SESSION_STATE_FREE
) && (Session
->CmdSN
!= LoginRsp
->ExpCmdSN
)) {
979 return EFI_PROTOCOL_ERROR
;
983 // It's the initial Login Response, initialize the local ExpStatSN, MaxCmdSN
986 Conn
->ExpStatSN
= LoginRsp
->StatSN
+ 1;
987 Session
->MaxCmdSN
= LoginRsp
->MaxCmdSN
;
988 Session
->ExpCmdSN
= LoginRsp
->ExpCmdSN
;
991 // Check the StatSN of this PDU.
993 Status
= IScsiCheckSN (&Conn
->ExpStatSN
, LoginRsp
->StatSN
);
994 if (!EFI_ERROR (Status
)) {
996 // Update the MaxCmdSN and ExpCmdSN.
998 IScsiUpdateCmdSN (Session
, LoginRsp
->MaxCmdSN
, LoginRsp
->ExpCmdSN
);
1004 // Trim off the header segment.
1006 NetbufTrim (Pdu
, sizeof (ISCSI_LOGIN_RESPONSE
), NET_BUF_HEAD
);
1009 // Queue this login response first in case it's a partial response so that
1010 // later when the full response list is received we can combine these scattered
1011 // responses' data segment and then process it.
1014 NetbufQueAppend (&Conn
->RspQue
, Pdu
);
1016 Conn
->PartialRspRcvd
= Continue
;
1019 // It is a partial response; must wait for another or more Request/Response
1020 // conversations to get the full response.
1025 switch (CurrentStage
) {
1026 case ISCSI_SECURITY_NEGOTIATION
:
1028 // In security negotiation stage, let CHAP module handle it.
1030 if (Session
->AuthType
!= ISCSI_AUTH_TYPE_KRB
) {
1031 Status
= IScsiCHAPOnRspReceived (Conn
);
1035 case ISCSI_LOGIN_OPERATIONAL_NEGOTIATION
:
1037 // Response received with negotiation response on iSCSI parameters: check them.
1039 Status
= IScsiCheckOpParams (Conn
);
1040 if (!EFI_ERROR (Status
)) {
1041 Conn
->ParamNegotiated
= TRUE
;
1048 // Should never get here.
1050 Status
= EFI_PROTOCOL_ERROR
;
1054 if (Transit
&& (Status
== EFI_SUCCESS
)) {
1056 // Do the state transition.
1058 Conn
->CurrentStage
= Conn
->NextStage
;
1060 if (Conn
->CurrentStage
== ISCSI_LOGIN_OPERATIONAL_NEGOTIATION
) {
1061 Conn
->NextStage
= ISCSI_FULL_FEATURE_PHASE
;
1064 // CurrentStage is iSCSI Full Feature. It is the Login-Final Response;
1065 // get the TSIH from the Login Response.
1067 Session
->Tsih
= NTOHS (LoginRsp
->Tsih
);
1071 // Flush the response(s) received.
1073 NetbufQueFlush (&Conn
->RspQue
);
1080 Updated the target information according the data received in the iSCSI
1081 login response with an target redirection status.
1083 @param[in, out] Session The iSCSI session.
1084 @param[in] Data The data segment that should contain the
1085 TargetAddress key-value list.
1086 @param[in] Len Length of the data.
1088 @retval EFI_SUCCESS The target address is updated.
1089 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
1090 @retval EFI_NOT_FOUND The TargetAddress key is not found.
1091 @retval Others Other errors as indicated.
1095 IScsiUpdateTargetAddress (
1096 IN OUT ISCSI_SESSION
*Session
,
1101 LIST_ENTRY
*KeyValueList
;
1102 CHAR8
*TargetAddress
;
1107 ISCSI_SESSION_CONFIG_NVDATA
*NvData
;
1109 KeyValueList
= IScsiBuildKeyValueList (Data
, Len
);
1110 if (KeyValueList
== NULL
) {
1111 return EFI_OUT_OF_RESOURCES
;
1114 Status
= EFI_NOT_FOUND
;
1115 NvData
= &Session
->ConfigData
->SessionConfigData
;
1118 TargetAddress
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_TARGET_ADDRESS
);
1119 if (TargetAddress
== NULL
) {
1124 // RFC 3720 defines format of the TargetAddress=domainname[:port][,portal-group-tag]
1125 // The domainname can be specified as either a DNS host name, adotted-decimal IPv4 address,
1126 // or a bracketed IPv6 address as specified in [RFC2732].
1128 if (NET_IS_DIGIT (TargetAddress
[0])) {
1130 // The domainname of the target is presented in a dotted-decimal IPv4 address format.
1132 IpStr
= TargetAddress
;
1134 while ((*TargetAddress
!= '\0') && (*TargetAddress
!= ':') && (*TargetAddress
!= ',')) {
1136 // NULL, ':', or ',' ends the IPv4 string.
1140 } else if (*TargetAddress
== ISCSI_REDIRECT_ADDR_START_DELIMITER
){
1142 // The domainname of the target is presented in a bracketed IPv6 address format.
1145 IpStr
= TargetAddress
;
1146 while ((*TargetAddress
!= '\0') && (*TargetAddress
!= ISCSI_REDIRECT_ADDR_END_DELIMITER
)) {
1148 // ']' ends the IPv6 string.
1153 if (*TargetAddress
!= ISCSI_REDIRECT_ADDR_END_DELIMITER
) {
1157 *TargetAddress
= '\0';
1162 // The domainname of the target is presented in the format of a DNS host name.
1164 IpStr
= TargetAddress
;
1166 while ((*TargetAddress
!= '\0') && (*TargetAddress
!= ':') && (*TargetAddress
!= ',')) {
1169 NvData
->DnsMode
= TRUE
;
1173 // Save the original user setting which specifies the proxy/virtual iSCSI target.
1175 NvData
->OriginalTargetPort
= NvData
->TargetPort
;
1177 if (*TargetAddress
== ',') {
1179 // Comma and the portal group tag MUST be omitted if the TargetAddress is sent
1180 // as the result of a redirection.
1183 } else if (*TargetAddress
== ':') {
1184 *TargetAddress
= '\0';
1188 Number
= AsciiStrDecimalToUintn (TargetAddress
);
1189 if (Number
> 0xFFFF) {
1192 NvData
->TargetPort
= (UINT16
) Number
;
1196 // The string only contains the Target address. Use the well-known port.
1198 NvData
->TargetPort
= ISCSI_WELL_KNOWN_PORT
;
1202 // Save the original user setting which specifies the proxy/virtual iSCSI target.
1204 CopyMem (&NvData
->OriginalTargetIp
, &NvData
->TargetIp
, sizeof (EFI_IP_ADDRESS
));
1207 // Update the target IP address.
1209 if (NvData
->IpMode
< IP_MODE_AUTOCONFIG
) {
1210 IpMode
= NvData
->IpMode
;
1212 IpMode
= Session
->ConfigData
->AutoConfigureMode
;
1215 if (NvData
->DnsMode
) {
1217 // Target address is expressed as URL format, just save it and
1218 // do DNS resolution when creating a TCP connection.
1220 if (AsciiStrSize (IpStr
) > sizeof (Session
->ConfigData
->SessionConfigData
.TargetUrl
)){
1221 return EFI_INVALID_PARAMETER
;
1223 CopyMem (&Session
->ConfigData
->SessionConfigData
.TargetUrl
, IpStr
, AsciiStrSize (IpStr
));
1225 Status
= IScsiAsciiStrToIp (
1228 &Session
->ConfigData
->SessionConfigData
.TargetIp
1231 if (EFI_ERROR (Status
)) {
1234 NvData
->RedirectFlag
= TRUE
;
1240 IScsiFreeKeyValueList (KeyValueList
);
1247 The callback function to free the net buffer list.
1249 @param[in] Arg The opaque parameter.
1258 ASSERT (Arg
!= NULL
);
1260 NetbufFreeList ((LIST_ENTRY
*) Arg
);
1266 The callback function called in NetBufFree; it does nothing.
1268 @param[in] Arg The opaque parameter.
1281 Receive an iSCSI response PDU. An iSCSI response PDU contains an iSCSI PDU header and
1282 an optional data segment. The two parts will be put into two blocks of buffers in the
1283 net buffer. The digest check will be conducted in this function if needed and the digests
1284 will be trimmed from the PDU buffer.
1286 @param[in] Conn The iSCSI connection to receive data from.
1287 @param[out] Pdu The received iSCSI pdu.
1288 @param[in] Context The context used to describe information on the caller provided
1289 buffer to receive data segment of the iSCSI pdu. It is optional.
1290 @param[in] HeaderDigest Whether there will be header digest received.
1291 @param[in] DataDigest Whether there will be data digest.
1292 @param[in] TimeoutEvent The timeout event. It is optional.
1294 @retval EFI_SUCCESS An iSCSI pdu is received.
1295 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
1296 @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error occurred.
1297 @retval Others Other errors as indicated.
1302 IN ISCSI_CONNECTION
*Conn
,
1304 IN ISCSI_IN_BUFFER_CONTEXT
*Context
, OPTIONAL
1305 IN BOOLEAN HeaderDigest
,
1306 IN BOOLEAN DataDigest
,
1307 IN EFI_EVENT TimeoutEvent OPTIONAL
1310 LIST_ENTRY
*NbufList
;
1316 UINT32 InDataOffset
;
1317 NET_FRAGMENT Fragment
[2];
1318 UINT32 FragmentCount
;
1320 UINT32 PadAndCRC32
[2];
1322 NbufList
= AllocatePool (sizeof (LIST_ENTRY
));
1323 if (NbufList
== NULL
) {
1324 return EFI_OUT_OF_RESOURCES
;
1327 InitializeListHead (NbufList
);
1330 // The header digest will be received together with the PDU header, if exists.
1332 Len
= sizeof (ISCSI_BASIC_HEADER
) + (HeaderDigest
? sizeof (UINT32
) : 0);
1333 PduHdr
= NetbufAlloc (Len
);
1334 if (PduHdr
== NULL
) {
1335 Status
= EFI_OUT_OF_RESOURCES
;
1339 Header
= NetbufAllocSpace (PduHdr
, Len
, NET_BUF_TAIL
);
1340 if (Header
== NULL
) {
1341 Status
= EFI_OUT_OF_RESOURCES
;
1344 InsertTailList (NbufList
, &PduHdr
->List
);
1347 // First step, receive the BHS of the PDU.
1349 Status
= TcpIoReceive (&Conn
->TcpIo
, PduHdr
, FALSE
, TimeoutEvent
);
1351 if (EFI_ERROR (Status
)) {
1357 // TODO: check the header-digest.
1360 // Trim off the digest.
1362 NetbufTrim (PduHdr
, sizeof (UINT32
), NET_BUF_TAIL
);
1365 Len
= ISCSI_GET_DATASEG_LEN (Header
);
1373 // Get the length of the padding bytes of the data segment.
1375 PadLen
= ISCSI_GET_PAD_LEN (Len
);
1377 switch (ISCSI_GET_OPCODE (Header
)) {
1378 case ISCSI_OPCODE_SCSI_DATA_IN
:
1380 // To reduce memory copy overhead, try to use the buffer described by Context
1381 // if the PDU is an iSCSI SCSI data.
1383 InDataOffset
= ISCSI_GET_BUFFER_OFFSET (Header
);
1384 if ((Context
== NULL
) || ((InDataOffset
+ Len
) > Context
->InDataLen
)) {
1385 Status
= EFI_PROTOCOL_ERROR
;
1389 Fragment
[0].Len
= Len
;
1390 Fragment
[0].Bulk
= Context
->InData
+ InDataOffset
;
1392 if (DataDigest
|| (PadLen
!= 0)) {
1394 // The data segment is padded. Use two fragments to receive it:
1395 // the first to receive the useful data; the second to receive the padding.
1397 Fragment
[1].Len
= PadLen
+ (DataDigest
? sizeof (UINT32
) : 0);
1398 Fragment
[1].Bulk
= (UINT8
*)PadAndCRC32
+ (4 - PadLen
);
1405 DataSeg
= NetbufFromExt (&Fragment
[0], FragmentCount
, 0, 0, IScsiNbufExtFree
, NULL
);
1406 if (DataSeg
== NULL
) {
1407 Status
= EFI_OUT_OF_RESOURCES
;
1413 case ISCSI_OPCODE_SCSI_RSP
:
1414 case ISCSI_OPCODE_NOP_IN
:
1415 case ISCSI_OPCODE_LOGIN_RSP
:
1416 case ISCSI_OPCODE_TEXT_RSP
:
1417 case ISCSI_OPCODE_ASYNC_MSG
:
1418 case ISCSI_OPCODE_REJECT
:
1419 case ISCSI_OPCODE_VENDOR_T0
:
1420 case ISCSI_OPCODE_VENDOR_T1
:
1421 case ISCSI_OPCODE_VENDOR_T2
:
1423 // Allocate buffer to receive the data segment.
1425 Len
+= PadLen
+ (DataDigest
? sizeof (UINT32
) : 0);
1426 DataSeg
= NetbufAlloc (Len
);
1427 if (DataSeg
== NULL
) {
1428 Status
= EFI_OUT_OF_RESOURCES
;
1432 NetbufAllocSpace (DataSeg
, Len
, NET_BUF_TAIL
);
1436 Status
= EFI_PROTOCOL_ERROR
;
1440 InsertTailList (NbufList
, &DataSeg
->List
);
1443 // Receive the data segment with the data digest, if any.
1445 Status
= TcpIoReceive (&Conn
->TcpIo
, DataSeg
, FALSE
, TimeoutEvent
);
1447 if (EFI_ERROR (Status
)) {
1453 // TODO: Check the data digest.
1455 NetbufTrim (DataSeg
, sizeof (UINT32
), NET_BUF_TAIL
);
1460 // Trim off the padding bytes in the data segment.
1462 NetbufTrim (DataSeg
, PadLen
, NET_BUF_TAIL
);
1467 // Form the pdu from a list of pdu segments.
1469 *Pdu
= NetbufFromBufList (NbufList
, 0, 0, IScsiFreeNbufList
, NbufList
);
1471 Status
= EFI_OUT_OF_RESOURCES
;
1476 if (EFI_ERROR (Status
)) {
1478 // Free the Nbufs in this NbufList and the NbufList itself.
1480 IScsiFreeNbufList (NbufList
);
1488 Check and get the result of the parameter negotiation.
1490 @param[in, out] Conn The connection in iSCSI login.
1492 @retval EFI_SUCCESS The parameter check is passed and negotiation is finished.
1493 @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error occurred.
1494 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
1498 IScsiCheckOpParams (
1499 IN OUT ISCSI_CONNECTION
*Conn
1503 LIST_ENTRY
*KeyValueList
;
1506 ISCSI_SESSION
*Session
;
1510 ASSERT (Conn
->RspQue
.BufNum
!= 0);
1512 Session
= Conn
->Session
;
1514 Len
= Conn
->RspQue
.BufSize
;
1515 Data
= AllocatePool (Len
);
1517 return EFI_OUT_OF_RESOURCES
;
1520 NetbufQueCopy (&Conn
->RspQue
, 0, Len
, (UINT8
*) Data
);
1522 Status
= EFI_PROTOCOL_ERROR
;
1525 // Extract the Key-Value pairs into a list.
1527 KeyValueList
= IScsiBuildKeyValueList (Data
, Len
);
1528 if (KeyValueList
== NULL
) {
1535 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_HEADER_DIGEST
);
1536 if (Value
== NULL
) {
1540 if (AsciiStrCmp (Value
, "CRC32") == 0) {
1541 if (Conn
->HeaderDigest
!= IScsiDigestCRC32
) {
1544 } else if (AsciiStrCmp (Value
, ISCSI_KEY_VALUE_NONE
) == 0) {
1545 Conn
->HeaderDigest
= IScsiDigestNone
;
1552 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_DATA_DIGEST
);
1553 if (Value
== NULL
) {
1557 if (AsciiStrCmp (Value
, "CRC32") == 0) {
1558 if (Conn
->DataDigest
!= IScsiDigestCRC32
) {
1561 } else if (AsciiStrCmp (Value
, ISCSI_KEY_VALUE_NONE
) == 0) {
1562 Conn
->DataDigest
= IScsiDigestNone
;
1567 // ErrorRecoveryLevel: result function is Minimum.
1569 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_ERROR_RECOVERY_LEVEL
);
1570 if (Value
== NULL
) {
1574 NumericValue
= IScsiNetNtoi (Value
);
1575 if (NumericValue
> 2) {
1579 Session
->ErrorRecoveryLevel
= (UINT8
) MIN (Session
->ErrorRecoveryLevel
, NumericValue
);
1582 // InitialR2T: result function is OR.
1584 if (!Session
->InitialR2T
) {
1585 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_INITIAL_R2T
);
1586 if (Value
== NULL
) {
1590 Session
->InitialR2T
= (BOOLEAN
) (AsciiStrCmp (Value
, "Yes") == 0);
1594 // ImmediateData: result function is AND.
1596 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_IMMEDIATE_DATA
);
1597 if (Value
== NULL
) {
1601 Session
->ImmediateData
= (BOOLEAN
) (Session
->ImmediateData
&& (BOOLEAN
) (AsciiStrCmp (Value
, "Yes") == 0));
1604 // MaxRecvDataSegmentLength is declarative.
1606 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_MAX_RECV_DATA_SEGMENT_LENGTH
);
1607 if (Value
!= NULL
) {
1608 Conn
->MaxRecvDataSegmentLength
= (UINT32
) IScsiNetNtoi (Value
);
1611 // MaxBurstLength: result function is Minimum.
1613 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_MAX_BURST_LENGTH
);
1614 if (Value
== NULL
) {
1618 NumericValue
= IScsiNetNtoi (Value
);
1619 Session
->MaxBurstLength
= (UINT32
) MIN (Session
->MaxBurstLength
, NumericValue
);
1622 // FirstBurstLength: result function is Minimum. Irrelevant when InitialR2T=Yes and
1623 // ImmediateData=No.
1625 if (!(Session
->InitialR2T
&& !Session
->ImmediateData
)) {
1626 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_FIRST_BURST_LENGTH
);
1627 if (Value
== NULL
) {
1631 NumericValue
= IScsiNetNtoi (Value
);
1632 Session
->FirstBurstLength
= (UINT32
) MIN (Session
->FirstBurstLength
, NumericValue
);
1636 // MaxConnections: result function is Minimum.
1638 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_MAX_CONNECTIONS
);
1639 if (Value
== NULL
) {
1643 NumericValue
= IScsiNetNtoi (Value
);
1644 if ((NumericValue
== 0) || (NumericValue
> 65535)) {
1648 Session
->MaxConnections
= (UINT32
) MIN (Session
->MaxConnections
, NumericValue
);
1651 // DataPDUInOrder: result function is OR.
1653 if (!Session
->DataPDUInOrder
) {
1654 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_DATA_PDU_IN_ORDER
);
1655 if (Value
== NULL
) {
1659 Session
->DataPDUInOrder
= (BOOLEAN
) (AsciiStrCmp (Value
, "Yes") == 0);
1663 // DataSequenceInorder: result function is OR.
1665 if (!Session
->DataSequenceInOrder
) {
1666 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_DATA_SEQUENCE_IN_ORDER
);
1667 if (Value
== NULL
) {
1671 Session
->DataSequenceInOrder
= (BOOLEAN
) (AsciiStrCmp (Value
, "Yes") == 0);
1675 // DefaultTime2Wait: result function is Maximum.
1677 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_DEFAULT_TIME2WAIT
);
1678 if (Value
== NULL
) {
1682 NumericValue
= IScsiNetNtoi (Value
);
1683 if (NumericValue
== 0) {
1684 Session
->DefaultTime2Wait
= 0;
1685 } else if (NumericValue
> 3600) {
1688 Session
->DefaultTime2Wait
= (UINT32
) MAX (Session
->DefaultTime2Wait
, NumericValue
);
1691 // DefaultTime2Retain: result function is Minimum.
1693 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_DEFAULT_TIME2RETAIN
);
1694 if (Value
== NULL
) {
1698 NumericValue
= IScsiNetNtoi (Value
);
1699 if (NumericValue
== 0) {
1700 Session
->DefaultTime2Retain
= 0;
1701 } else if (NumericValue
> 3600) {
1704 Session
->DefaultTime2Retain
= (UINT32
) MIN (Session
->DefaultTime2Retain
, NumericValue
);
1707 // MaxOutstandingR2T: result function is Minimum.
1709 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_MAX_OUTSTANDING_R2T
);
1710 if (Value
== NULL
) {
1714 NumericValue
= IScsiNetNtoi (Value
);
1715 if ((NumericValue
== 0) || (NumericValue
> 65535)) {
1719 Session
->MaxOutstandingR2T
= (UINT16
) MIN (Session
->MaxOutstandingR2T
, NumericValue
);
1722 // Remove declarative key-value pairs, if any.
1724 IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_SESSION_TYPE
);
1725 IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_TARGET_ALIAS
);
1726 IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_TARGET_PORTAL_GROUP_TAG
);
1730 // Remove the key-value that may not needed for result function is OR.
1732 IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_INITIAL_R2T
);
1733 IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_DATA_PDU_IN_ORDER
);
1734 IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_DATA_SEQUENCE_IN_ORDER
);
1737 // Remove irrelevant parameter, if any.
1739 if (Session
->InitialR2T
&& !Session
->ImmediateData
) {
1740 IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_FIRST_BURST_LENGTH
);
1743 if (IsListEmpty (KeyValueList
)) {
1745 // Succeed if no more keys in the list.
1747 Status
= EFI_SUCCESS
;
1752 IScsiFreeKeyValueList (KeyValueList
);
1761 Fill the operational parameters.
1763 @param[in] Conn The connection in iSCSI login.
1764 @param[in, out] Pdu The iSCSI login request PDU to fill the parameters.
1769 IN ISCSI_CONNECTION
*Conn
,
1773 ISCSI_SESSION
*Session
;
1776 Session
= Conn
->Session
;
1778 AsciiSPrint (Value
, sizeof (Value
), "%a", (Conn
->HeaderDigest
== IScsiDigestCRC32
) ? "None,CRC32" : "None");
1779 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_HEADER_DIGEST
, Value
);
1781 AsciiSPrint (Value
, sizeof (Value
), "%a", (Conn
->DataDigest
== IScsiDigestCRC32
) ? "None,CRC32" : "None");
1782 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_DATA_DIGEST
, Value
);
1784 AsciiSPrint (Value
, sizeof (Value
), "%d", Session
->ErrorRecoveryLevel
);
1785 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_ERROR_RECOVERY_LEVEL
, Value
);
1787 AsciiSPrint (Value
, sizeof (Value
), "%a", Session
->InitialR2T
? "Yes" : "No");
1788 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_INITIAL_R2T
, Value
);
1790 AsciiSPrint (Value
, sizeof (Value
), "%a", Session
->ImmediateData
? "Yes" : "No");
1791 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_IMMEDIATE_DATA
, Value
);
1793 AsciiSPrint (Value
, sizeof (Value
), "%d", MAX_RECV_DATA_SEG_LEN_IN_FFP
);
1794 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_MAX_RECV_DATA_SEGMENT_LENGTH
, Value
);
1796 AsciiSPrint (Value
, sizeof (Value
), "%d", Session
->MaxBurstLength
);
1797 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_MAX_BURST_LENGTH
, Value
);
1799 AsciiSPrint (Value
, sizeof (Value
), "%d", Session
->FirstBurstLength
);
1800 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_FIRST_BURST_LENGTH
, Value
);
1802 AsciiSPrint (Value
, sizeof (Value
), "%d", Session
->MaxConnections
);
1803 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_MAX_CONNECTIONS
, Value
);
1805 AsciiSPrint (Value
, sizeof (Value
), "%a", Session
->DataPDUInOrder
? "Yes" : "No");
1806 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_DATA_PDU_IN_ORDER
, Value
);
1808 AsciiSPrint (Value
, sizeof (Value
), "%a", Session
->DataSequenceInOrder
? "Yes" : "No");
1809 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_DATA_SEQUENCE_IN_ORDER
, Value
);
1811 AsciiSPrint (Value
, sizeof (Value
), "%d", Session
->DefaultTime2Wait
);
1812 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_DEFAULT_TIME2WAIT
, Value
);
1814 AsciiSPrint (Value
, sizeof (Value
), "%d", Session
->DefaultTime2Retain
);
1815 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_DEFAULT_TIME2RETAIN
, Value
);
1817 AsciiSPrint (Value
, sizeof (Value
), "%d", Session
->MaxOutstandingR2T
);
1818 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_MAX_OUTSTANDING_R2T
, Value
);
1823 Pad the iSCSI AHS or data segment to an integer number of 4 byte words.
1825 @param[in, out] Pdu The iSCSI pdu which contains segments to pad.
1826 @param[in] Len The length of the last segment in the PDU.
1828 @retval EFI_SUCCESS The segment is padded or there is no need to pad it.
1829 @retval EFI_OUT_OF_RESOURCES There is not enough remaining free space to add the
1834 IN OUT NET_BUF
*Pdu
,
1841 PadLen
= ISCSI_GET_PAD_LEN (Len
);
1844 Data
= NetbufAllocSpace (Pdu
, PadLen
, NET_BUF_TAIL
);
1846 return EFI_OUT_OF_RESOURCES
;
1849 ZeroMem (Data
, PadLen
);
1857 Build a key-value list from the data segment.
1859 @param[in] Data The data segment containing the key-value pairs.
1860 @param[in] Len Length of the data segment.
1862 @return The key-value list.
1863 @retval NULL Other errors as indicated.
1867 IScsiBuildKeyValueList (
1872 LIST_ENTRY
*ListHead
;
1873 ISCSI_KEY_VALUE_PAIR
*KeyValuePair
;
1875 ListHead
= AllocatePool (sizeof (LIST_ENTRY
));
1876 if (ListHead
== NULL
) {
1880 InitializeListHead (ListHead
);
1883 KeyValuePair
= AllocatePool (sizeof (ISCSI_KEY_VALUE_PAIR
));
1884 if (KeyValuePair
== NULL
) {
1888 InitializeListHead (&KeyValuePair
->List
);
1890 KeyValuePair
->Key
= Data
;
1892 while ((Len
> 0) && (*Data
!= '=')) {
1903 FreePool (KeyValuePair
);
1907 KeyValuePair
->Value
= Data
;
1909 InsertTailList (ListHead
, &KeyValuePair
->List
);;
1911 Data
+= AsciiStrLen (KeyValuePair
->Value
) + 1;
1912 Len
-= (UINT32
) AsciiStrLen (KeyValuePair
->Value
) + 1;
1919 IScsiFreeKeyValueList (ListHead
);
1926 Get the value string by the key name from the key-value list. If found,
1927 the key-value entry will be removed from the list.
1929 @param[in, out] KeyValueList The key-value list.
1930 @param[in] Key The key name to find.
1932 @return The value string.
1933 @retval NULL The key value pair cannot be found.
1937 IScsiGetValueByKeyFromList (
1938 IN OUT LIST_ENTRY
*KeyValueList
,
1943 ISCSI_KEY_VALUE_PAIR
*KeyValuePair
;
1948 NET_LIST_FOR_EACH (Entry
, KeyValueList
) {
1949 KeyValuePair
= NET_LIST_USER_STRUCT (Entry
, ISCSI_KEY_VALUE_PAIR
, List
);
1951 if (AsciiStrCmp (KeyValuePair
->Key
, Key
) == 0) {
1952 Value
= KeyValuePair
->Value
;
1954 RemoveEntryList (&KeyValuePair
->List
);
1955 FreePool (KeyValuePair
);
1965 Free the key-value list.
1967 @param[in] KeyValueList The key-value list.
1971 IScsiFreeKeyValueList (
1972 IN LIST_ENTRY
*KeyValueList
1976 ISCSI_KEY_VALUE_PAIR
*KeyValuePair
;
1978 while (!IsListEmpty (KeyValueList
)) {
1979 Entry
= NetListRemoveHead (KeyValueList
);
1980 KeyValuePair
= NET_LIST_USER_STRUCT (Entry
, ISCSI_KEY_VALUE_PAIR
, List
);
1982 FreePool (KeyValuePair
);
1985 FreePool (KeyValueList
);
1990 Normalize the iSCSI name according to RFC.
1992 @param[in, out] Name The iSCSI name.
1993 @param[in] Len Length of the iSCSI name.
1995 @retval EFI_SUCCESS The iSCSI name is valid and normalized.
1996 @retval EFI_PROTOCOL_ERROR The iSCSI name is malformatted or not in the IQN format.
2000 IScsiNormalizeName (
2007 for (Index
= 0; Index
< Len
; Index
++) {
2008 if (NET_IS_UPPER_CASE_CHAR (Name
[Index
])) {
2010 // Convert the upper-case characters to lower-case ones.
2012 Name
[Index
] = (CHAR8
) (Name
[Index
] - 'A' + 'a');
2015 if (!NET_IS_LOWER_CASE_CHAR (Name
[Index
]) &&
2016 !NET_IS_DIGIT (Name
[Index
]) &&
2017 (Name
[Index
] != '-') &&
2018 (Name
[Index
] != '.') &&
2019 (Name
[Index
] != ':')
2022 // ASCII dash, dot, colon lower-case characters and digit characters
2025 return EFI_PROTOCOL_ERROR
;
2029 if ((Len
< 4) || (CompareMem (Name
, "iqn.", 4) != 0)) {
2031 // Only IQN format is accepted now.
2033 return EFI_PROTOCOL_ERROR
;
2041 Create an iSCSI task control block.
2043 @param[in] Conn The connection on which the task control block will be created.
2044 @param[out] Tcb The newly created task control block.
2046 @retval EFI_SUCCESS The task control block is created.
2047 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
2048 @retval EFI_NOT_READY The target cannot accept new commands.
2053 IN ISCSI_CONNECTION
*Conn
,
2057 ISCSI_SESSION
*Session
;
2060 ASSERT (Tcb
!= NULL
);
2062 Session
= Conn
->Session
;
2064 if (ISCSI_SEQ_GT (Session
->CmdSN
, Session
->MaxCmdSN
)) {
2065 return EFI_NOT_READY
;
2068 NewTcb
= AllocateZeroPool (sizeof (ISCSI_TCB
));
2069 if (NewTcb
== NULL
) {
2070 return EFI_OUT_OF_RESOURCES
;
2073 InitializeListHead (&NewTcb
->Link
);
2075 NewTcb
->SoFarInOrder
= TRUE
;
2076 NewTcb
->InitiatorTaskTag
= Session
->InitiatorTaskTag
;
2077 NewTcb
->CmdSN
= Session
->CmdSN
;
2078 NewTcb
->Conn
= Conn
;
2080 InsertTailList (&Session
->TcbList
, &NewTcb
->Link
);
2083 // Advance the initiator task tag.
2085 Session
->InitiatorTaskTag
++;
2095 Delete the tcb from the connection and destroy it.
2097 @param[in] Tcb The tcb to delete.
2105 RemoveEntryList (&Tcb
->Link
);
2112 Create a data segment, pad it, and calculate the CRC if needed.
2114 @param[in] Data The data to fill into the data segment.
2115 @param[in] Len Length of the data.
2116 @param[in] DataDigest Whether to calculate CRC for this data segment.
2118 @return The net buffer wrapping the data segment.
2122 IScsiNewDataSegment (
2125 IN BOOLEAN DataDigest
2128 NET_FRAGMENT Fragment
[2];
2129 UINT32 FragmentCount
;
2133 Fragment
[0].Len
= Len
;
2134 Fragment
[0].Bulk
= Data
;
2136 PadLen
= ISCSI_GET_PAD_LEN (Len
);
2138 Fragment
[1].Len
= PadLen
;
2139 Fragment
[1].Bulk
= (UINT8
*) &mDataSegPad
;
2146 DataSeg
= NetbufFromExt (&Fragment
[0], FragmentCount
, 0, 0, IScsiNbufExtFree
, NULL
);
2153 Create a iSCSI SCSI command PDU to encapsulate the command issued
2154 by SCSI through the EXT SCSI PASS THRU Protocol.
2156 @param[in] Packet The EXT SCSI PASS THRU request packet containing the SCSI command.
2157 @param[in] Lun The LUN.
2158 @param[in] Tcb The tcb associated with this SCSI command.
2160 @return The created iSCSI SCSI command PDU.
2161 @retval NULL Other errors as indicated.
2165 IScsiNewScsiCmdPdu (
2166 IN EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
*Packet
,
2171 LIST_ENTRY
*NbufList
;
2175 SCSI_COMMAND
*ScsiCmd
;
2178 ISCSI_ADDITIONAL_HEADER
*Header
;
2179 ISCSI_BI_EXP_READ_DATA_LEN_AHS
*BiExpReadDataLenAHS
;
2180 ISCSI_SESSION
*Session
;
2181 UINT32 ImmediateDataLen
;
2185 if (Packet
->DataDirection
== DataBi
) {
2187 // Bidirectional Read/Write command, the bidirectional expected
2188 // read data length AHS is required.
2190 AHSLength
+= sizeof (ISCSI_BI_EXP_READ_DATA_LEN_AHS
);
2193 if (Packet
->CdbLength
> 16) {
2195 // The CDB exceeds 16 bytes. An extended CDB AHS is required.
2197 AHSLength
= (UINT8
) (AHSLength
+ ISCSI_ROUNDUP (Packet
->CdbLength
- 16) + sizeof (ISCSI_ADDITIONAL_HEADER
));
2200 Length
= sizeof (SCSI_COMMAND
) + AHSLength
;
2201 PduHeader
= NetbufAlloc (Length
);
2202 if (PduHeader
== NULL
) {
2206 ScsiCmd
= (SCSI_COMMAND
*) NetbufAllocSpace (PduHeader
, Length
, NET_BUF_TAIL
);
2207 if (ScsiCmd
== NULL
) {
2208 NetbufFree (PduHeader
);
2211 Header
= (ISCSI_ADDITIONAL_HEADER
*) (ScsiCmd
+ 1);
2213 ZeroMem (ScsiCmd
, Length
);
2215 ISCSI_SET_OPCODE (ScsiCmd
, ISCSI_OPCODE_SCSI_CMD
, 0);
2216 ISCSI_SET_FLAG (ScsiCmd
, ISCSI_TASK_ATTR_SIMPLE
);
2219 // Set the READ/WRITE flags according to the IO type of this request.
2221 switch (Packet
->DataDirection
) {
2223 ISCSI_SET_FLAG (ScsiCmd
, SCSI_CMD_PDU_FLAG_READ
);
2224 ScsiCmd
->ExpDataXferLength
= NTOHL (Packet
->InTransferLength
);
2228 ISCSI_SET_FLAG (ScsiCmd
, SCSI_CMD_PDU_FLAG_WRITE
);
2229 ScsiCmd
->ExpDataXferLength
= NTOHL (Packet
->OutTransferLength
);
2233 ISCSI_SET_FLAG (ScsiCmd
, SCSI_CMD_PDU_FLAG_READ
| SCSI_CMD_PDU_FLAG_WRITE
);
2234 ScsiCmd
->ExpDataXferLength
= NTOHL (Packet
->OutTransferLength
);
2237 // Fill the bidirectional expected read data length AHS.
2239 BiExpReadDataLenAHS
= (ISCSI_BI_EXP_READ_DATA_LEN_AHS
*) Header
;
2240 Header
= (ISCSI_ADDITIONAL_HEADER
*) (BiExpReadDataLenAHS
+ 1);
2242 BiExpReadDataLenAHS
->Length
= NTOHS (5);
2243 BiExpReadDataLenAHS
->Type
= ISCSI_AHS_TYPE_BI_EXP_READ_DATA_LEN
;
2244 BiExpReadDataLenAHS
->ExpReadDataLength
= NTOHL (Packet
->InTransferLength
);
2249 ScsiCmd
->TotalAHSLength
= AHSLength
;
2250 CopyMem (ScsiCmd
->Lun
, &Lun
, sizeof (ScsiCmd
->Lun
));
2251 ScsiCmd
->InitiatorTaskTag
= NTOHL (Tcb
->InitiatorTaskTag
);
2252 ScsiCmd
->CmdSN
= NTOHL (Tcb
->CmdSN
);
2253 ScsiCmd
->ExpStatSN
= NTOHL (Tcb
->Conn
->ExpStatSN
);
2255 CopyMem (ScsiCmd
->Cdb
, Packet
->Cdb
, sizeof (ScsiCmd
->Cdb
));
2257 if (Packet
->CdbLength
> 16) {
2258 Header
->Length
= NTOHS ((UINT16
) (Packet
->CdbLength
- 15));
2259 Header
->Type
= ISCSI_AHS_TYPE_EXT_CDB
;
2261 CopyMem (Header
+ 1, (UINT8
*) Packet
->Cdb
+ 16, Packet
->CdbLength
- 16);
2265 Session
= Tcb
->Conn
->Session
;
2266 ImmediateDataLen
= 0;
2268 if (Session
->ImmediateData
&& (Packet
->OutTransferLength
!= 0)) {
2270 // Send immediate data in this SCSI Command PDU. The length of the immediate
2271 // data is the minimum of FirstBurstLength, the data length to be xfered, and
2272 // the MaxRecvdataSegmentLength on this connection.
2274 ImmediateDataLen
= MIN (Session
->FirstBurstLength
, Packet
->OutTransferLength
);
2275 ImmediateDataLen
= MIN (ImmediateDataLen
, Tcb
->Conn
->MaxRecvDataSegmentLength
);
2278 // Update the data segment length in the PDU header.
2280 ISCSI_SET_DATASEG_LEN (ScsiCmd
, ImmediateDataLen
);
2283 // Create the data segment.
2285 DataSeg
= IScsiNewDataSegment ((UINT8
*) Packet
->OutDataBuffer
, ImmediateDataLen
, FALSE
);
2286 if (DataSeg
== NULL
) {
2287 NetbufFree (PduHeader
);
2292 NbufList
= AllocatePool (sizeof (LIST_ENTRY
));
2293 if (NbufList
== NULL
) {
2294 NetbufFree (PduHeader
);
2295 NetbufFree (DataSeg
);
2301 InitializeListHead (NbufList
);
2302 InsertTailList (NbufList
, &PduHeader
->List
);
2303 InsertTailList (NbufList
, &DataSeg
->List
);
2305 Pdu
= NetbufFromBufList (NbufList
, 0, 0, IScsiFreeNbufList
, NbufList
);
2307 IScsiFreeNbufList (NbufList
);
2311 if (Session
->InitialR2T
||
2312 (ImmediateDataLen
== Session
->FirstBurstLength
) ||
2313 (ImmediateDataLen
== Packet
->OutTransferLength
)
2316 // Unsolicited data out sequence is not allowed,
2317 // or FirstBustLength data is already sent out by immediate data,
2318 // or all the OUT data accompany this SCSI packet are sent as
2319 // immediate data. The final flag should be set on this SCSI Command
2322 ISCSI_SET_FLAG (ScsiCmd
, ISCSI_BHS_FLAG_FINAL
);
2332 Create a new iSCSI SCSI Data Out PDU.
2334 @param[in] Data The data to put into the Data Out PDU.
2335 @param[in] Len Length of the data.
2336 @param[in] DataSN The DataSN of the Data Out PDU.
2337 @param[in] Tcb The task control block of this Data Out PDU.
2338 @param[in] Lun The LUN.
2340 @return The net buffer wrapping the Data Out PDU.
2341 @retval NULL Other errors as indicated.
2345 IScsiNewDataOutPdu (
2353 LIST_ENTRY
*NbufList
;
2357 ISCSI_SCSI_DATA_OUT
*DataOutHdr
;
2358 ISCSI_XFER_CONTEXT
*XferContext
;
2360 NbufList
= AllocatePool (sizeof (LIST_ENTRY
));
2361 if (NbufList
== NULL
) {
2365 InitializeListHead (NbufList
);
2368 // Allocate memory for the BHS.
2370 PduHdr
= NetbufAlloc (sizeof (ISCSI_SCSI_DATA_OUT
));
2371 if (PduHdr
== NULL
) {
2372 FreePool (NbufList
);
2376 // Insert the BHS into the buffer list.
2378 InsertTailList (NbufList
, &PduHdr
->List
);
2380 DataOutHdr
= (ISCSI_SCSI_DATA_OUT
*) NetbufAllocSpace (PduHdr
, sizeof (ISCSI_SCSI_DATA_OUT
), NET_BUF_TAIL
);
2381 if (DataOutHdr
== NULL
) {
2382 IScsiFreeNbufList (NbufList
);
2385 XferContext
= &Tcb
->XferContext
;
2387 ZeroMem (DataOutHdr
, sizeof (ISCSI_SCSI_DATA_OUT
));
2390 // Set the flags and fields of the Data Out PDU BHS.
2392 ISCSI_SET_OPCODE (DataOutHdr
, ISCSI_OPCODE_SCSI_DATA_OUT
, 0);
2393 ISCSI_SET_DATASEG_LEN (DataOutHdr
, Len
);
2395 DataOutHdr
->InitiatorTaskTag
= HTONL (Tcb
->InitiatorTaskTag
);
2396 DataOutHdr
->TargetTransferTag
= HTONL (XferContext
->TargetTransferTag
);
2397 DataOutHdr
->ExpStatSN
= HTONL (Tcb
->Conn
->ExpStatSN
);
2398 DataOutHdr
->DataSN
= HTONL (DataSN
);
2399 DataOutHdr
->BufferOffset
= HTONL (XferContext
->Offset
);
2401 if (XferContext
->TargetTransferTag
!= ISCSI_RESERVED_TAG
) {
2402 CopyMem (&DataOutHdr
->Lun
, &Lun
, sizeof (DataOutHdr
->Lun
));
2405 // Build the data segment for this Data Out PDU.
2407 DataSeg
= IScsiNewDataSegment (Data
, Len
, FALSE
);
2408 if (DataSeg
== NULL
) {
2409 IScsiFreeNbufList (NbufList
);
2413 // Put the data segment into the buffer list and combine it with the BHS
2414 // into a full Data Out PDU.
2416 InsertTailList (NbufList
, &DataSeg
->List
);
2417 Pdu
= NetbufFromBufList (NbufList
, 0, 0, IScsiFreeNbufList
, NbufList
);
2419 IScsiFreeNbufList (NbufList
);
2427 Generate a consecutive sequence of iSCSI SCSI Data Out PDUs.
2429 @param[in] Data The data which will be carried by the sequence of iSCSI SCSI Data Out PDUs.
2430 @param[in] Tcb The task control block of the data to send out.
2431 @param[in] Lun The LUN the data will be sent to.
2433 @return A list of net buffers with each of them wrapping an iSCSI SCSI Data Out PDU.
2434 @retval NULL Other errors as indicated.
2438 IScsiGenerateDataOutPduSequence (
2444 LIST_ENTRY
*PduList
;
2447 NET_BUF
*DataOutPdu
;
2448 ISCSI_CONNECTION
*Conn
;
2449 ISCSI_XFER_CONTEXT
*XferContext
;
2450 UINT8
*DataOutPacket
;
2452 PduList
= AllocatePool (sizeof (LIST_ENTRY
));
2453 if (PduList
== NULL
) {
2457 InitializeListHead (PduList
);
2462 XferContext
= &Tcb
->XferContext
;
2464 while (XferContext
->DesiredLength
> 0) {
2466 // Determine the length of data this Data Out PDU can carry.
2468 DataLen
= MIN (XferContext
->DesiredLength
, Conn
->MaxRecvDataSegmentLength
);
2471 // Create a Data Out PDU.
2473 DataOutPdu
= IScsiNewDataOutPdu (Data
, DataLen
, DataSN
, Tcb
, Lun
);
2474 if (DataOutPdu
== NULL
) {
2475 IScsiFreeNbufList (PduList
);
2481 InsertTailList (PduList
, &DataOutPdu
->List
);
2484 // Update the context and DataSN.
2487 XferContext
->Offset
+= DataLen
;
2488 XferContext
->DesiredLength
-= DataLen
;
2492 // Set the F bit for the last data out PDU in this sequence.
2494 DataOutPacket
= NetbufGetByte (DataOutPdu
, 0, NULL
);
2495 if (DataOutPacket
== NULL
) {
2496 IScsiFreeNbufList (PduList
);
2501 ISCSI_SET_FLAG (DataOutPacket
, ISCSI_BHS_FLAG_FINAL
);
2509 Send the Data in a sequence of Data Out PDUs one by one.
2511 @param[in] Data The data to carry by Data Out PDUs.
2512 @param[in] Lun The LUN the data will be sent to.
2513 @param[in] Tcb The task control block.
2515 @retval EFI_SUCCESS The data is sent out to the LUN.
2516 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
2517 @retval Others Other errors as indicated.
2521 IScsiSendDataOutPduSequence (
2527 LIST_ENTRY
*DataOutPduList
;
2533 // Generate the Data Out PDU sequence.
2535 DataOutPduList
= IScsiGenerateDataOutPduSequence (Data
, Tcb
, Lun
);
2536 if (DataOutPduList
== NULL
) {
2537 return EFI_OUT_OF_RESOURCES
;
2540 Status
= EFI_SUCCESS
;
2543 // Send the Data Out PDU's one by one.
2545 NET_LIST_FOR_EACH (Entry
, DataOutPduList
) {
2546 Pdu
= NET_LIST_USER_STRUCT (Entry
, NET_BUF
, List
);
2548 Status
= TcpIoTransmit (&Tcb
->Conn
->TcpIo
, Pdu
);
2550 if (EFI_ERROR (Status
)) {
2555 IScsiFreeNbufList (DataOutPduList
);
2562 Process the received iSCSI SCSI Data In PDU.
2564 @param[in] Pdu The Data In PDU received.
2565 @param[in] Tcb The task control block.
2566 @param[in, out] Packet The EXT SCSI PASS THRU request packet.
2568 @retval EFI_SUCCESS The check on the Data IN PDU is passed and some update
2570 @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error occurred.
2571 @retval EFI_BAD_BUFFER_SIZEE The buffer was not the proper size for the request.
2572 @retval Others Other errors as indicated.
2579 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
*Packet
2582 ISCSI_SCSI_DATA_IN
*DataInHdr
;
2585 DataInHdr
= (ISCSI_SCSI_DATA_IN
*) NetbufGetByte (Pdu
, 0, NULL
);
2586 if (DataInHdr
== NULL
) {
2587 return EFI_PROTOCOL_ERROR
;
2590 DataInHdr
->InitiatorTaskTag
= NTOHL (DataInHdr
->InitiatorTaskTag
);
2591 DataInHdr
->ExpCmdSN
= NTOHL (DataInHdr
->ExpCmdSN
);
2592 DataInHdr
->MaxCmdSN
= NTOHL (DataInHdr
->MaxCmdSN
);
2593 DataInHdr
->DataSN
= NTOHL (DataInHdr
->DataSN
);
2596 // Check the DataSN.
2598 Status
= IScsiCheckSN (&Tcb
->ExpDataSN
, DataInHdr
->DataSN
);
2599 if (EFI_ERROR (Status
)) {
2603 if (DataInHdr
->InitiatorTaskTag
!= Tcb
->InitiatorTaskTag
) {
2604 return EFI_PROTOCOL_ERROR
;
2607 // Update the command related sequence numbers.
2609 IScsiUpdateCmdSN (Tcb
->Conn
->Session
, DataInHdr
->MaxCmdSN
, DataInHdr
->ExpCmdSN
);
2611 if (ISCSI_FLAG_ON (DataInHdr
, SCSI_DATA_IN_PDU_FLAG_STATUS_VALID
)) {
2612 if (!ISCSI_FLAG_ON (DataInHdr
, ISCSI_BHS_FLAG_FINAL
)) {
2614 // The S bit is on but the F bit is off.
2616 return EFI_PROTOCOL_ERROR
;
2619 Tcb
->StatusXferd
= TRUE
;
2621 if (ISCSI_FLAG_ON (DataInHdr
, SCSI_DATA_IN_PDU_FLAG_OVERFLOW
| SCSI_DATA_IN_PDU_FLAG_UNDERFLOW
)) {
2623 // Underflow and Overflow are mutual flags.
2625 return EFI_PROTOCOL_ERROR
;
2628 // S bit is on, the StatSN is valid.
2630 Status
= IScsiCheckSN (&Tcb
->Conn
->ExpStatSN
, NTOHL (DataInHdr
->StatSN
));
2631 if (EFI_ERROR (Status
)) {
2635 Packet
->HostAdapterStatus
= 0;
2636 Packet
->TargetStatus
= DataInHdr
->Status
;
2638 if (ISCSI_FLAG_ON (DataInHdr
, SCSI_RSP_PDU_FLAG_OVERFLOW
)) {
2639 Packet
->InTransferLength
+= NTOHL (DataInHdr
->ResidualCount
);
2640 Status
= EFI_BAD_BUFFER_SIZE
;
2643 if (ISCSI_FLAG_ON (DataInHdr
, SCSI_RSP_PDU_FLAG_UNDERFLOW
)) {
2644 Packet
->InTransferLength
-= NTOHL (DataInHdr
->ResidualCount
);
2653 Process the received iSCSI R2T PDU.
2655 @param[in] Pdu The R2T PDU received.
2656 @param[in] Tcb The task control block.
2657 @param[in] Lun The Lun.
2658 @param[in, out] Packet The EXT SCSI PASS THRU request packet.
2660 @retval EFI_SUCCESS The R2T PDU is valid and the solicited data is sent out.
2661 @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error occurred.
2662 @retval Others Other errors as indicated.
2670 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
*Packet
2673 ISCSI_READY_TO_TRANSFER
*R2THdr
;
2675 ISCSI_XFER_CONTEXT
*XferContext
;
2678 R2THdr
= (ISCSI_READY_TO_TRANSFER
*) NetbufGetByte (Pdu
, 0, NULL
);
2679 if (R2THdr
== NULL
) {
2680 return EFI_PROTOCOL_ERROR
;
2683 R2THdr
->InitiatorTaskTag
= NTOHL (R2THdr
->InitiatorTaskTag
);
2684 R2THdr
->TargetTransferTag
= NTOHL (R2THdr
->TargetTransferTag
);
2685 R2THdr
->StatSN
= NTOHL (R2THdr
->StatSN
);
2686 R2THdr
->R2TSeqNum
= NTOHL (R2THdr
->R2TSeqNum
);
2687 R2THdr
->BufferOffset
= NTOHL (R2THdr
->BufferOffset
);
2688 R2THdr
->DesiredDataTransferLength
= NTOHL (R2THdr
->DesiredDataTransferLength
);
2690 if ((R2THdr
->InitiatorTaskTag
!= Tcb
->InitiatorTaskTag
) || !ISCSI_SEQ_EQ (R2THdr
->StatSN
, Tcb
->Conn
->ExpStatSN
)) {
2691 return EFI_PROTOCOL_ERROR
;;
2694 // Check the sequence number.
2696 Status
= IScsiCheckSN (&Tcb
->ExpDataSN
, R2THdr
->R2TSeqNum
);
2697 if (EFI_ERROR (Status
)) {
2701 XferContext
= &Tcb
->XferContext
;
2702 XferContext
->TargetTransferTag
= R2THdr
->TargetTransferTag
;
2703 XferContext
->Offset
= R2THdr
->BufferOffset
;
2704 XferContext
->DesiredLength
= R2THdr
->DesiredDataTransferLength
;
2706 if (((XferContext
->Offset
+ XferContext
->DesiredLength
) > Packet
->OutTransferLength
) ||
2707 (XferContext
->DesiredLength
> Tcb
->Conn
->Session
->MaxBurstLength
)
2709 return EFI_PROTOCOL_ERROR
;
2712 // Send the data solicited by this R2T.
2714 Data
= (UINT8
*) Packet
->OutDataBuffer
+ XferContext
->Offset
;
2715 Status
= IScsiSendDataOutPduSequence (Data
, Lun
, Tcb
);
2722 Process the received iSCSI SCSI Response PDU.
2724 @param[in] Pdu The Response PDU received.
2725 @param[in] Tcb The task control block.
2726 @param[in, out] Packet The EXT SCSI PASS THRU request packet.
2728 @retval EFI_SUCCESS The Response PDU is processed.
2729 @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error occurred.
2730 @retval EFI_BAD_BUFFER_SIZEE The buffer was not the proper size for the request.
2731 @retval Others Other errors as indicated.
2735 IScsiOnScsiRspRcvd (
2738 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
*Packet
2741 SCSI_RESPONSE
*ScsiRspHdr
;
2742 ISCSI_SENSE_DATA
*SenseData
;
2746 ScsiRspHdr
= (SCSI_RESPONSE
*) NetbufGetByte (Pdu
, 0, NULL
);
2747 if (ScsiRspHdr
== NULL
) {
2748 return EFI_PROTOCOL_ERROR
;
2751 ScsiRspHdr
->InitiatorTaskTag
= NTOHL (ScsiRspHdr
->InitiatorTaskTag
);
2752 if (ScsiRspHdr
->InitiatorTaskTag
!= Tcb
->InitiatorTaskTag
) {
2753 return EFI_PROTOCOL_ERROR
;
2756 ScsiRspHdr
->StatSN
= NTOHL (ScsiRspHdr
->StatSN
);
2758 Status
= IScsiCheckSN (&Tcb
->Conn
->ExpStatSN
, ScsiRspHdr
->StatSN
);
2759 if (EFI_ERROR (Status
)) {
2763 ScsiRspHdr
->MaxCmdSN
= NTOHL (ScsiRspHdr
->MaxCmdSN
);
2764 ScsiRspHdr
->ExpCmdSN
= NTOHL (ScsiRspHdr
->ExpCmdSN
);
2765 IScsiUpdateCmdSN (Tcb
->Conn
->Session
, ScsiRspHdr
->MaxCmdSN
, ScsiRspHdr
->ExpCmdSN
);
2767 Tcb
->StatusXferd
= TRUE
;
2769 Packet
->HostAdapterStatus
= ScsiRspHdr
->Response
;
2770 if (Packet
->HostAdapterStatus
!= ISCSI_SERVICE_RSP_COMMAND_COMPLETE_AT_TARGET
) {
2774 Packet
->TargetStatus
= ScsiRspHdr
->Status
;
2776 if (ISCSI_FLAG_ON (ScsiRspHdr
, SCSI_RSP_PDU_FLAG_BI_READ_OVERFLOW
| SCSI_RSP_PDU_FLAG_BI_READ_UNDERFLOW
) ||
2777 ISCSI_FLAG_ON (ScsiRspHdr
, SCSI_RSP_PDU_FLAG_OVERFLOW
| SCSI_RSP_PDU_FLAG_UNDERFLOW
)
2779 return EFI_PROTOCOL_ERROR
;
2782 if (ISCSI_FLAG_ON (ScsiRspHdr
, SCSI_RSP_PDU_FLAG_BI_READ_OVERFLOW
)) {
2783 Packet
->InTransferLength
+= NTOHL (ScsiRspHdr
->BiReadResidualCount
);
2784 Status
= EFI_BAD_BUFFER_SIZE
;
2787 if (ISCSI_FLAG_ON (ScsiRspHdr
, SCSI_RSP_PDU_FLAG_BI_READ_UNDERFLOW
)) {
2788 Packet
->InTransferLength
-= NTOHL (ScsiRspHdr
->BiReadResidualCount
);
2791 if (ISCSI_FLAG_ON (ScsiRspHdr
, SCSI_RSP_PDU_FLAG_OVERFLOW
)) {
2792 if (Packet
->DataDirection
== DataIn
) {
2793 Packet
->InTransferLength
+= NTOHL (ScsiRspHdr
->ResidualCount
);
2795 Packet
->OutTransferLength
+= NTOHL (ScsiRspHdr
->ResidualCount
);
2798 Status
= EFI_BAD_BUFFER_SIZE
;
2801 if (ISCSI_FLAG_ON (ScsiRspHdr
, SCSI_RSP_PDU_FLAG_UNDERFLOW
)) {
2802 if (Packet
->DataDirection
== DataIn
) {
2803 Packet
->InTransferLength
-= NTOHL (ScsiRspHdr
->ResidualCount
);
2805 Packet
->OutTransferLength
-= NTOHL (ScsiRspHdr
->ResidualCount
);
2809 DataSegLen
= ISCSI_GET_DATASEG_LEN (ScsiRspHdr
);
2810 if (DataSegLen
!= 0) {
2811 SenseData
= (ISCSI_SENSE_DATA
*) NetbufGetByte (Pdu
, sizeof (SCSI_RESPONSE
), NULL
);
2812 if (SenseData
== NULL
) {
2813 return EFI_PROTOCOL_ERROR
;
2816 SenseData
->Length
= NTOHS (SenseData
->Length
);
2818 Packet
->SenseDataLength
= (UINT8
) MIN (SenseData
->Length
, Packet
->SenseDataLength
);
2819 if (Packet
->SenseDataLength
!= 0) {
2820 CopyMem (Packet
->SenseData
, &SenseData
->Data
[0], Packet
->SenseDataLength
);
2823 Packet
->SenseDataLength
= 0;
2831 Process the received NOP In PDU.
2833 @param[in] Pdu The NOP In PDU received.
2834 @param[in] Tcb The task control block.
2836 @retval EFI_SUCCESS The NOP In PDU is processed and the related sequence
2837 numbers are updated.
2838 @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error occurred.
2847 ISCSI_NOP_IN
*NopInHdr
;
2850 NopInHdr
= (ISCSI_NOP_IN
*) NetbufGetByte (Pdu
, 0, NULL
);
2851 if (NopInHdr
== NULL
) {
2852 return EFI_PROTOCOL_ERROR
;
2855 NopInHdr
->StatSN
= NTOHL (NopInHdr
->StatSN
);
2856 NopInHdr
->ExpCmdSN
= NTOHL (NopInHdr
->ExpCmdSN
);
2857 NopInHdr
->MaxCmdSN
= NTOHL (NopInHdr
->MaxCmdSN
);
2859 if (NopInHdr
->InitiatorTaskTag
== ISCSI_RESERVED_TAG
) {
2860 if (NopInHdr
->StatSN
!= Tcb
->Conn
->ExpStatSN
) {
2861 return EFI_PROTOCOL_ERROR
;
2864 Status
= IScsiCheckSN (&Tcb
->Conn
->ExpStatSN
, NopInHdr
->StatSN
);
2865 if (EFI_ERROR (Status
)) {
2870 IScsiUpdateCmdSN (Tcb
->Conn
->Session
, NopInHdr
->MaxCmdSN
, NopInHdr
->ExpCmdSN
);
2877 Execute the SCSI command issued through the EXT SCSI PASS THRU protocol.
2879 @param[in] PassThru The EXT SCSI PASS THRU protocol.
2880 @param[in] Target The target ID.
2881 @param[in] Lun The LUN.
2882 @param[in, out] Packet The request packet containing IO request, SCSI command
2883 buffer and buffers to read/write.
2885 @retval EFI_SUCCESS The SCSI command is executed and the result is updated to
2887 @retval EFI_DEVICE_ERROR Session state was not as required.
2888 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
2889 @retval EFI_PROTOCOL_ERROR There is no such data in the net buffer.
2890 @retval EFI_NOT_READY The target can not accept new commands.
2891 @retval Others Other errors as indicated.
2895 IScsiExecuteScsiCommand (
2896 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*PassThru
,
2899 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
*Packet
2903 ISCSI_DRIVER_DATA
*Private
;
2904 ISCSI_SESSION
*Session
;
2905 EFI_EVENT TimeoutEvent
;
2906 ISCSI_CONNECTION
*Conn
;
2909 ISCSI_XFER_CONTEXT
*XferContext
;
2911 ISCSI_IN_BUFFER_CONTEXT InBufferContext
;
2915 Private
= ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (PassThru
);
2916 Session
= Private
->Session
;
2917 Status
= EFI_SUCCESS
;
2919 TimeoutEvent
= NULL
;
2922 if (Session
->State
!= SESSION_STATE_LOGGED_IN
) {
2923 Status
= EFI_DEVICE_ERROR
;
2927 Conn
= NET_LIST_USER_STRUCT_S (
2928 Session
->Conns
.ForwardLink
,
2931 ISCSI_CONNECTION_SIGNATURE
2934 if (Packet
->Timeout
!= 0) {
2935 Timeout
= MultU64x32 (Packet
->Timeout
, 4);
2938 Status
= IScsiNewTcb (Conn
, &Tcb
);
2939 if (EFI_ERROR (Status
)) {
2943 // Encapsulate the SCSI request packet into an iSCSI SCSI Command PDU.
2945 Pdu
= IScsiNewScsiCmdPdu (Packet
, Lun
, Tcb
);
2947 Status
= EFI_OUT_OF_RESOURCES
;
2951 XferContext
= &Tcb
->XferContext
;
2952 PduHdr
= NetbufGetByte (Pdu
, 0, NULL
);
2953 if (PduHdr
== NULL
) {
2954 Status
= EFI_PROTOCOL_ERROR
;
2958 XferContext
->Offset
= ISCSI_GET_DATASEG_LEN (PduHdr
);
2961 // Transmit the SCSI Command PDU.
2963 Status
= TcpIoTransmit (&Conn
->TcpIo
, Pdu
);
2967 if (EFI_ERROR (Status
)) {
2971 if (!Session
->InitialR2T
&&
2972 (XferContext
->Offset
< Session
->FirstBurstLength
) &&
2973 (XferContext
->Offset
< Packet
->OutTransferLength
)
2976 // Unsolicited Data-Out sequence is allowed. There is remaining SCSI
2977 // OUT data, and the limit of FirstBurstLength is not reached.
2979 XferContext
->TargetTransferTag
= ISCSI_RESERVED_TAG
;
2980 XferContext
->DesiredLength
= MIN (
2981 Session
->FirstBurstLength
,
2982 Packet
->OutTransferLength
- XferContext
->Offset
2985 Data
= (UINT8
*) Packet
->OutDataBuffer
+ XferContext
->Offset
;
2986 Status
= IScsiSendDataOutPduSequence (Data
, Lun
, Tcb
);
2987 if (EFI_ERROR (Status
)) {
2992 InBufferContext
.InData
= (UINT8
*) Packet
->InDataBuffer
;
2993 InBufferContext
.InDataLen
= Packet
->InTransferLength
;
2995 while (!Tcb
->StatusXferd
) {
2997 // Start the timeout timer.
3000 Status
= gBS
->SetTimer (Conn
->TimeoutEvent
, TimerRelative
, Timeout
);
3001 if (EFI_ERROR (Status
)) {
3005 TimeoutEvent
= Conn
->TimeoutEvent
;
3009 // Try to receive PDU from target.
3011 Status
= IScsiReceivePdu (Conn
, &Pdu
, &InBufferContext
, FALSE
, FALSE
, TimeoutEvent
);
3012 if (EFI_ERROR (Status
)) {
3016 PduHdr
= NetbufGetByte (Pdu
, 0, NULL
);
3017 if (PduHdr
== NULL
) {
3018 Status
= EFI_PROTOCOL_ERROR
;
3022 switch (ISCSI_GET_OPCODE (PduHdr
)) {
3023 case ISCSI_OPCODE_SCSI_DATA_IN
:
3024 Status
= IScsiOnDataInRcvd (Pdu
, Tcb
, Packet
);
3027 case ISCSI_OPCODE_R2T
:
3028 Status
= IScsiOnR2TRcvd (Pdu
, Tcb
, Lun
, Packet
);
3031 case ISCSI_OPCODE_SCSI_RSP
:
3032 Status
= IScsiOnScsiRspRcvd (Pdu
, Tcb
, Packet
);
3035 case ISCSI_OPCODE_NOP_IN
:
3036 Status
= IScsiOnNopInRcvd (Pdu
, Tcb
);
3039 case ISCSI_OPCODE_VENDOR_T0
:
3040 case ISCSI_OPCODE_VENDOR_T1
:
3041 case ISCSI_OPCODE_VENDOR_T2
:
3043 // These messages are vendor specific. Skip them.
3048 Status
= EFI_PROTOCOL_ERROR
;
3054 if (EFI_ERROR (Status
)) {
3061 if (TimeoutEvent
!= NULL
) {
3062 gBS
->SetTimer (TimeoutEvent
, TimerCancel
, 0);
3074 Reinstate the session on some error.
3076 @param[in] Session The iSCSI session
3078 @retval EFI_SUCCESS The session is reinstated from some error.
3079 @retval Other Reinstatement failed.
3083 IScsiSessionReinstatement (
3084 IN ISCSI_SESSION
*Session
3089 ASSERT (Session
->State
!= SESSION_STATE_FREE
);
3092 // Abort the session and re-init it.
3094 IScsiSessionAbort (Session
);
3095 IScsiSessionInit (Session
, TRUE
);
3100 Status
= IScsiSessionLogin (Session
);
3107 Initialize some session parameters before login.
3109 @param[in, out] Session The iSCSI session.
3110 @param[in] Recovery Whether the request is from a fresh new start or recovery.
3115 IN OUT ISCSI_SESSION
*Session
,
3120 Session
->Signature
= ISCSI_SESSION_SIGNATURE
;
3121 Session
->State
= SESSION_STATE_FREE
;
3123 InitializeListHead (&Session
->Conns
);
3124 InitializeListHead (&Session
->TcbList
);
3130 Session
->InitiatorTaskTag
= 1;
3131 Session
->NextCid
= 1;
3133 Session
->TargetPortalGroupTag
= 0;
3134 Session
->MaxConnections
= ISCSI_MAX_CONNS_PER_SESSION
;
3135 Session
->InitialR2T
= FALSE
;
3136 Session
->ImmediateData
= TRUE
;
3137 Session
->MaxBurstLength
= 262144;
3138 Session
->FirstBurstLength
= MAX_RECV_DATA_SEG_LEN_IN_FFP
;
3139 Session
->DefaultTime2Wait
= 2;
3140 Session
->DefaultTime2Retain
= 20;
3141 Session
->MaxOutstandingR2T
= DEFAULT_MAX_OUTSTANDING_R2T
;
3142 Session
->DataPDUInOrder
= TRUE
;
3143 Session
->DataSequenceInOrder
= TRUE
;
3144 Session
->ErrorRecoveryLevel
= 0;
3149 Abort the iSCSI session. That is, reset all the connection(s), and free the
3152 @param[in, out] Session The iSCSI session.
3157 IN OUT ISCSI_SESSION
*Session
3160 ISCSI_CONNECTION
*Conn
;
3161 EFI_GUID
*ProtocolGuid
;
3163 if (Session
->State
!= SESSION_STATE_LOGGED_IN
) {
3167 ASSERT (!IsListEmpty (&Session
->Conns
));
3169 while (!IsListEmpty (&Session
->Conns
)) {
3170 Conn
= NET_LIST_USER_STRUCT_S (
3171 Session
->Conns
.ForwardLink
,
3174 ISCSI_CONNECTION_SIGNATURE
3176 if (!Conn
->Ipv6Flag
) {
3177 ProtocolGuid
= &gEfiTcp4ProtocolGuid
;
3179 ProtocolGuid
= &gEfiTcp6ProtocolGuid
;
3182 gBS
->CloseProtocol (
3185 Session
->Private
->Image
,
3186 Session
->Private
->ExtScsiPassThruHandle
3189 IScsiConnReset (Conn
);
3191 IScsiDetatchConnection (Conn
);
3192 IScsiDestroyConnection (Conn
);
3195 Session
->State
= SESSION_STATE_FAILED
;