Skip to content

Commit

Permalink
Merge pull request #2 from ActiveVolcano/windows10
Browse files Browse the repository at this point in the history
Resolves compatible with Microsoft Windows 10 bundled iSCSI initiator
  • Loading branch information
ActiveVolcano authored Aug 5, 2022
2 parents 087fe37 + 45ec5bf commit cc69317
Show file tree
Hide file tree
Showing 15 changed files with 306 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,17 @@ public final void setDataDigest (final IDigest newDataDigest) {
@Override
public final String toString () {
final StringBuilder sb = new StringBuilder(Constants.LOG_INITIAL_SIZE);
BaseEncoding base16 = BaseEncoding.base16 ().withSeparator (" ", 2).lowerCase ();

try {
sb.append (" First 16 bytes: 0x");
byte[] pdu = new byte [calcSize()];
basicHeaderSegment.serialize (ByteBuffer.wrap (pdu), 0);
sb.append (base16.encode (pdu, 0, 16)).append ("\n");

} catch (InternetSCSIException e) {
sb.append ("Exception in serialize: " + e.getMessage ());
}

sb.append(basicHeaderSegment.toString());
for (AdditionalHeaderSegment ahs : additionalHeaderSegments) {
Expand All @@ -531,7 +542,7 @@ public final String toString () {
// "If the mark is defined and larger than the new position then it is discarded."
int pos = dataSegment.position ();
dataSegment.position (0).get (preview).position (pos);
sb.append (BaseEncoding.base16 ().withSeparator (" ", 2).encode (preview));
sb.append (base16.encode (preview));
}

return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* Copyright (c) 2012, University of Konstanz, Distributed Systems Group All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or other materials provided with the
* distribution. * Neither the name of the University of Konstanz nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
Expand All @@ -30,7 +30,7 @@

/**
* This class parses a Data-In message defined in the iSCSI Standard (RFC3720).
*
*
* @author Volker Wildi
*/
public class DataInParser extends TargetMessageParser {
Expand Down Expand Up @@ -88,7 +88,7 @@ public class DataInParser extends TargetMessageParser {

/**
* Default constructor, creates a new, empty DataInParser object.
*
*
* @param initProtocolDataUnit The reference <code>ProtocolDataUnit</code> instance, which contains this
* <code>DataInParser</code> subclass object.
*/
Expand Down Expand Up @@ -175,7 +175,7 @@ public final boolean incrementSequenceNumber () {
* have to be in increasing Buffer Offset order and overlays are forbidden.<br/>
* The ordering between sequences is determined by DataSequenceInOrder. When set to Yes, it means that sequences
* have to be in increasing Buffer Offset order and overlays are forbidden.
*
*
* @return The buffer offset of this DataInParser object.
*/
public int getBufferOffset () {
Expand All @@ -191,7 +191,7 @@ public int getBufferOffset () {
* For output (write) data PDUs, the DataSN is the Data-Out PDU number within the current output sequence. The
* current output sequence is either identified by the Initiator Task Tag (for unsolicited data) or is a data
* sequence generated for one R2T (for data solicited through R2T).
*
*
* @return The Data Sequence Number of this DataInParser object.
*/
public int getDataSequenceNumber () {
Expand All @@ -206,7 +206,7 @@ public int getDataSequenceNumber () {
* Residual Count indicates the number of bytes that were not transferred because the initiator’s Expected Data
* Transfer Length was not sufficient. If the U bit is set, the Residual Count indicates the number of bytes that
* were not transferred out of the number of bytes expected to be transferred.
*
*
* @return The Residual Count of this object.
*/
public int getResidualCount () {
Expand All @@ -225,7 +225,7 @@ public int getResidualCount () {
* is reserved and means that the Target Transfer Tag is not supplied. If the Target Transfer Tag is provided, then
* the LUN field MUST hold a valid value and be consistent with whatever was specified with the command; otherwise,
* the LUN field is reserved.
*
*
* @return Returns the Target Transfer Tag of this DataInParser object.
*/
public int getTargetTaskTag () {
Expand All @@ -251,7 +251,7 @@ public int getTargetTaskTag () {
* initiator also MUST NOT acknowledge the status for the task before those holes are filled. A status
* acknowledgement for a task that generated the Data-In PDUs is considered by the target as an implicit
* acknowledgement of the Data-In PDUs if such an acknowledgement was requested by the target.
*
*
* @return Returns <code>true</code>, if the AcknowledgeBit is set. Else <code>false</code>.
*/
public boolean isAcknowledgeFlag () {
Expand All @@ -262,7 +262,7 @@ public boolean isAcknowledgeFlag () {
/**
* In this case, the Bidirectional Read Residual Count indicates the number of bytes that were not transferred to
* the initiator because the initiator’s Expected Bidirectional Read Data Transfer Length was not sufficient.
*
*
* @return <code>True</code>, if the ReadResidualOverflow-Flag of this object is set. Else <code>false</code>.
*/
public boolean isBidirectionalReadResidualOverflow () {
Expand All @@ -273,7 +273,7 @@ public boolean isBidirectionalReadResidualOverflow () {
/**
* In this case, the Bidirectional Read Residual Count indicates the number of bytes that were not transferred to
* the initiator out of the number of bytes expected to be transferred.
*
*
* @return <code>True</code>, if the ReadResidualUnderflow-Flag of this object is set. Else <code>false</code>.
*/
public boolean isBidirectionalReadResidualUnderflow () {
Expand All @@ -285,7 +285,7 @@ public boolean isBidirectionalReadResidualUnderflow () {
* In this case, the Residual Count indicates the number of bytes that were not transferred because the initiator’s
* Expected Data Transfer Length was not sufficient. For a bidirectional operation, the Residual Count contains the
* residual for the write operation.
*
*
* @return <code>True</code>, if the ResidualOverflow-Flag of this object is set. Else <code>false</code>.
*/
public boolean isResidualOverflow () {
Expand All @@ -297,7 +297,7 @@ public boolean isResidualOverflow () {
* In this case, the Residual Count indicates the number of bytes that were not transferred out of the number of
* bytes that were expected to be transferred. For a bidirectional operation, the Residual Count contains the
* residual for the write operation.
*
*
* @return <code>True</code>, if the ResidualUnderflow-Flag of this object is set. Else <code>false</code>.
*/
public boolean isResidualUnderflow () {
Expand All @@ -312,7 +312,7 @@ public boolean isResidualUnderflow () {
* If a SCSI device error is detected while data from the initiator is still expected (the command PDU did not
* contain all the data and the target has not received a Data PDU with the final bit Set), the target MUST wait
* until it receives a Data PDU with the F bit set in the last expected sequence before sending the Response PDU.
*
*
* @return The status code of this object.
* @see SCSIStatus
*/
Expand All @@ -326,7 +326,7 @@ public SCSIStatus getStatus () {
* <code>F bit</code> MUST also be set to <code>1</code>.<br/>
* The fields StatSN, Status, and Residual Count only have meaningful content if the S bit is set to <code>1</code>
* and their values are defined in Section 10.4 SCSI Response.
*
*
* @return <code>True</code>, if the Status-Flag of this object is set. Else <code>false</code>.
*/
public boolean isStatusFlag () {
Expand Down Expand Up @@ -462,10 +462,10 @@ protected int serializeBytes1to3 () {
line |= ACKNOWLEDGE_FLAG_MASK;
}
if (residualOverflow) {
line |= Constants.READ_RESIDUAL_OVERFLOW_FLAG_MASK;
line |= Constants.RESIDUAL_OVERFLOW_FLAG_MASK;
}
if (residualUnderflow) {
line |= Constants.READ_RESIDUAL_UNDERFLOW_FLAG_MASK;
line |= Constants.RESIDUAL_UNDERFLOW_FLAG_MASK;
}
if (statusFlag) {
line |= STATUS_FLAG_MASK;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* Copyright (c) 2012, University of Konstanz, Distributed Systems Group All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or other materials provided with the
* distribution. * Neither the name of the University of Konstanz nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
Expand All @@ -25,6 +25,8 @@
import org.jscsi.parser.TargetMessageParser;
import org.jscsi.parser.datasegment.DataSegmentFactory.DataSegmentFormat;
import org.jscsi.utils.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
Expand Down Expand Up @@ -59,11 +61,13 @@
* negotiation keys). All keys in Chapter 12, except for the X extension formats, MUST be supported by iSCSI initiators
* and targets. Keys in Chapter 11, only need to be supported when the function to which they refer is mandatory to
* implement.
*
*
* @author Volker Wildi
*/
public final class LoginResponseParser extends TargetMessageParser {

private static final Logger LOGGER = LoggerFactory.getLogger (LoginResponseParser.class);

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------

Expand All @@ -87,7 +91,7 @@ public final class LoginResponseParser extends TargetMessageParser {
* <p>
* If the target wishes to reject the Login Request for more than one reason, it should return the primary reason
* for the rejection.
*
*
* @see LoginStatus
*/
private LoginStatus status;
Expand Down Expand Up @@ -115,7 +119,7 @@ public final class LoginResponseParser extends TargetMessageParser {

/**
* Default constructor, creates a new, empty <code>LoginResponseParser</code> object.
*
*
* @param initProtocolDataUnit The reference <code>ProtocolDataUnit</code> instance, which contains this
* <code>LoginResponseParser</code> subclass object.
*/
Expand Down Expand Up @@ -195,7 +199,7 @@ public final boolean canHaveDigests () {
* A non-zero Status-Class indicates an exception. In this case, Status-Class is sufficient for a simple initiator
* to use when handling exceptions, without having to look at the Status-Detail. The Status-Detail allows
* finer-grained exception handling for more sophisticated initiators and for better information for logging.
*
*
* @return The status of this LoginResponseParser object.
*/
public final LoginStatus getStatus () {
Expand All @@ -208,7 +212,7 @@ public final LoginStatus getStatus () {
* complete (it will be continued on subsequent Login Responses); otherwise, it indicates that this Login Response
* ends a set of key=value pairs. A Login Response with the <code>C</code> bit set to <code>1</code> MUST have the
* <code>T</code> bit set to <code>0</code>.
*
*
* @return The status of the Continue Flag of this <code>LoginResponseParser</code> object.
*/
public final boolean isContinueFlag () {
Expand All @@ -218,7 +222,7 @@ public final boolean isContinueFlag () {

/**
* Returns the <em>Current Stage Number</em> of this Login Response Message.
*
*
* @return Number of the Current Stage.
* @see org.jscsi.parser.login.LoginStage
*/
Expand All @@ -229,7 +233,7 @@ public final LoginStage getCurrentStageNumber () {

/**
* Returns the Initiator Session ID (ISID) of this LoginResponseParser object.
*
*
* @return Returns the Initiator Session ID (ISID) of this LoginResponseParser object.
* @see ISID
*/
Expand All @@ -244,7 +248,7 @@ public final ISID getInitiatorSessionID () {
* All Login Responses within the Login Phase MUST carry the same Version-max.
* <p>
* The initiator MUST use the value presented as a response to the first Login Request.
*
*
* @return The maximum version of this login request message.
*/
public final int getMaxVersion () {
Expand All @@ -261,7 +265,7 @@ public final int getMaxVersion () {
* All Login Responses within the Login Phase MUST carry the same Version-active.
* <p>
* The initiator MUST use the value presented as a response to the first Login Request.
*
*
* @return The active version of this <code>LoginResponseParser</code> object.
*/
public final int getActiveVersion () {
Expand All @@ -271,7 +275,7 @@ public final int getActiveVersion () {

/**
* Returns the <em> Next Stage Number</em> of this Login Response Message.
*
*
* @return The Number of the Next Stage.
* @see org.jscsi.parser.login.LoginStage
*/
Expand All @@ -286,7 +290,7 @@ public final LoginStage getNextStageNumber () {
* Final-Response in a new session, this field should be set to the TSIH provided by the initiator in the Login
* Request. For a new session, the target MUST generate a non-zero TSIH and ONLY return it in the Login
* Final-Response (see Section 5.3 Login Phase).
*
*
* @return Returns the Target Session Identifying Handle of this <code>LoginResponseParser</code> object.
*/
public final short getTargetSessionIdentifyingHandle () {
Expand Down Expand Up @@ -361,19 +365,10 @@ protected final void deserializeBytes36to39 (final int line) throws InternetSCSI
/** {@inheritDoc} */
@Override
protected final void checkIntegrity () throws InternetSCSIException {

String exceptionMessage;
do {
if (status != LoginStatus.SUCCESS && statusSequenceNumber != 0) {
exceptionMessage = "While no successful login is preformed, the StatusSequenceNumber must be 0.";
break;
}

// message is checked correctly
return;
} while (false);

throw new InternetSCSIException(exceptionMessage);
if (status != LoginStatus.SUCCESS && statusSequenceNumber != 0) {
LOGGER.warn ("While no successful login is preformed, the StatusSequenceNumber must be 0.");
// throw new InternetSCSIException(exceptionMessage);
}
}

// --------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit cc69317

Please sign in to comment.