@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 {