@Override
public ProtocolDataUnit check (final Connection pConnection) throws InterruptedException , IOException , InternetSCSIException {
ProtocolDataUnit responsePdu;
final BasicHeaderSegment bhs = new ProtocolDataUnitFactory().create(false, true, OperationCode.SCSI_COMMAND, "None", "None").getBasicHeaderSegment();
final SCSICommandParser parser = (SCSICommandParser) bhs.getParser();
final SendDiagnosticCdb cdb = new SendDiagnosticCdb(parser.getCDB());
// create the whole sense data
FixedFormatSenseData senseData = new FixedFormatSenseData(false,// valid
ErrorType.CURRENT,// error type
false,// file mark
false,// end of medium
false,// incorrect length indicator
SenseKey.ILLEGAL_REQUEST,// sense key
new FourByteInformation(),// information
new FourByteInformation(),// command specific information
AdditionalSenseCodeAndQualifier.INVALID_FIELD_IN_CDB,// additional sense
// code and
// qualifier
(byte) 0,// field replaceable unit code
cdb.getIllegalFieldPointers()[0],// sense key specific data, only report
// first problem
new AdditionalSenseBytes());// additional sense bytes
// keep only the part of the sense data that will be sent
final ScsiResponseDataSegment dataSegment = new ScsiResponseDataSegment(senseData, parser.getExpectedDataTransferLength());
final int senseDataSize = senseData.size();
// calculate residuals and flags
final int residualCount = Math.abs(parser.getExpectedDataTransferLength() - senseDataSize);
final boolean residualOverflow = parser.getExpectedDataTransferLength() < senseDataSize;
final boolean residualUnderflow = parser.getExpectedDataTransferLength() > senseDataSize;
// create and return PDU
responsePdu = TargetPduFactory.createSCSIResponsePdu(false,// bidirectionalReadResidualOverflow
false,// bidirectionalReadResidualUnderflow
residualOverflow,// residualOverflow
residualUnderflow,// residualUnderflow,
SCSIResponseParser.ServiceResponse.COMMAND_COMPLETED_AT_TARGET,// response,
SCSIStatus.CHECK_CONDITION,// status,
bhs.getInitiatorTaskTag(),// initiatorTaskTag,
0,// snackTag
0,// expectedDataSequenceNumber
0,// bidirectionalReadResidualCount
residualCount,// residualCount
dataSegment);// data segment
return responsePdu;
}
}, // ReportLunsStage checker
new Checker() {
@Override
public ProtocolDataUnit check (final Connection pConnection) throws InterruptedException , IOException , InternetSCSIException {
ProtocolDataUnit responsePdu;
final BasicHeaderSegment bhs = new ProtocolDataUnitFactory().create(false, true, OperationCode.SCSI_COMMAND, "None", "None").getBasicHeaderSegment();
final SCSICommandParser parser = (SCSICommandParser) bhs.getParser();
final ReportLunsCDB cdb = new ReportLunsCDB(parser.getCDB());
final FieldPointerSenseKeySpecificData[] illegalFieldPointers = cdb.getIllegalFieldPointers();
FixedFormatSenseData senseData = new FixedFormatSenseData(false,// valid
ErrorType.CURRENT,// error type
false,// file mark
false,// end of medium
false,// incorrect length indicator
SenseKey.ILLEGAL_REQUEST,// sense key
new FourByteInformation(),// information
new FourByteInformation(),// command specific information
AdditionalSenseCodeAndQualifier.INVALID_FIELD_IN_CDB,// additional sense
// code and
// qualifier
(byte) 0,// field replaceable unit code
illegalFieldPointers[0],// sense key specific data, only report
// first problem
new AdditionalSenseBytes());// additional sense bytes
// keep only the part of the sense data that will be sent
final ScsiResponseDataSegment dataSegment = new ScsiResponseDataSegment(senseData, parser.getExpectedDataTransferLength());
final int senseDataSize = senseData.size();
// calculate residuals and flags
final int residualCount = Math.abs(parser.getExpectedDataTransferLength() - senseDataSize);
final boolean residualOverflow = parser.getExpectedDataTransferLength() < senseDataSize;
final boolean residualUnderflow = parser.getExpectedDataTransferLength() > senseDataSize;
// create and return PDU
responsePdu = TargetPduFactory.createSCSIResponsePdu(false,// bidirectionalReadResidualOverflow
false,// bidirectionalReadResidualUnderflow
residualOverflow,// residualOverflow
residualUnderflow,// residualUnderflow,
SCSIResponseParser.ServiceResponse.COMMAND_COMPLETED_AT_TARGET,// response,
SCSIStatus.CHECK_CONDITION,// status,
bhs.getInitiatorTaskTag(),// initiatorTaskTag,
0,// snackTag
0,// expectedDataSequenceNumber
0,// bidirectionalReadResidualCount
residualCount,// residualCount
dataSegment);// data segment
// send response
return responsePdu;
}
}, // InquiryStage checker
new Checker() {
@Override
public ProtocolDataUnit check (final Connection pConnection) throws InterruptedException , IOException , InternetSCSIException {
ProtocolDataUnit responsePdu;
final BasicHeaderSegment bhs = new ProtocolDataUnitFactory().create(false, true, OperationCode.SCSI_COMMAND, "None", "None").getBasicHeaderSegment();
final SCSICommandParser parser = (SCSICommandParser) bhs.getParser();
final InquiryCDB cdb = new InquiryCDB(parser.getCDB());
IResponseData responseData = null;
if (!cdb.getEnableVitalProductData()) {
responseData = StandardInquiryData.getInstance();
} else {
final VitalProductDataPageName pageName = cdb.getPageCode().getVitalProductDataPageName();
switch (pageName) {// is never null
case SUPPORTED_VPD_PAGES :
responseData = SupportedVpdPages.getInstance();
break;
case DEVICE_IDENTIFICATION :
responseData = session.getTargetServer().getDeviceIdentificationVpdPage();
break;
default :
throw new InternetSCSIException();
}
}
// The part from the targetfullfeaturephase
final ByteBuffer fullBuffer = ByteBuffer.allocate(responseData.size());
responseData.serialize(fullBuffer, 0);
ByteBuffer trimmedBuffer;
if (fullBuffer.capacity() <= parser.getExpectedDataTransferLength()) {
trimmedBuffer = fullBuffer;
} else {
trimmedBuffer = ByteBuffer.allocate(parser.getExpectedDataTransferLength());
trimmedBuffer.put(fullBuffer.array(),// source array
0,// offset in source
parser.getExpectedDataTransferLength());// length
}
final boolean residualOverflow = parser.getExpectedDataTransferLength() < fullBuffer.capacity();
final boolean residualUnderflow = parser.getExpectedDataTransferLength() > fullBuffer.capacity();
final int residualCount = Math.abs(parser.getExpectedDataTransferLength() - fullBuffer.capacity());
responsePdu = TargetPduFactory.createSCSIResponsePdu(false,// bidirectionalReadResidualOverflow
false,// bidirectionalReadResidualUnderflow
residualOverflow,// residualOverflow
residualUnderflow,// residualUnderflow
ServiceResponse.COMMAND_COMPLETED_AT_TARGET,// response
SCSIStatus.GOOD,// status
bhs.getInitiatorTaskTag(), 0,// snackTag, reserved
0,// expectedDataSequenceNumber
0,// bidirectionalReadResidualCount
residualCount,// residualCount
ScsiResponseDataSegment.EMPTY_DATA_SEGMENT);// scsiResponseDataSegment
return responsePdu;
}
}, // RequestSenseStage checker
new Checker() {
@Override
public ProtocolDataUnit check (final Connection pConnection) throws InterruptedException , IOException , InternetSCSIException {
ProtocolDataUnit responsePdu;
final BasicHeaderSegment bhs = new ProtocolDataUnitFactory().create(false, true, OperationCode.SCSI_COMMAND, "None", "None").getBasicHeaderSegment();
final SCSICommandParser parser = (SCSICommandParser) bhs.getParser();
final RequestSenseCdb cdb = new RequestSenseCdb(parser.getCDB());
SenseData senseData;
final SenseKey senseKey = SenseKey.NO_SENSE;
final AdditionalSenseCodeAndQualifier additionalSense = AdditionalSenseCodeAndQualifier.NO_ADDITIONAL_SENSE_INFORMATION;
if (cdb.getDescriptorFormat()) {
senseData = new DescriptorFormatSenseData(ErrorType.CURRENT,// errorType
senseKey,// sense key
additionalSense,// additional sense code and qualifier
new SenseDataDescriptor[0]);// sense data descriptors
} else {