Coverage Report - org.jscsi.target.connection.stage.fullfeature.SendDiagnosticStage
 
Classes in this File Line Coverage Branch Coverage Complexity
SendDiagnosticStage
0%
0/12
0%
0/2
1.5
 
 1  
 package org.jscsi.target.connection.stage.fullfeature;
 2  
 
 3  
 
 4  
 import java.io.IOException;
 5  
 import java.security.DigestException;
 6  
 
 7  
 import org.jscsi.exception.InternetSCSIException;
 8  
 import org.jscsi.parser.BasicHeaderSegment;
 9  
 import org.jscsi.parser.ProtocolDataUnit;
 10  
 import org.jscsi.parser.scsi.SCSICommandParser;
 11  
 import org.jscsi.parser.scsi.SCSIResponseParser;
 12  
 import org.jscsi.parser.scsi.SCSIStatus;
 13  
 import org.jscsi.target.connection.TargetPduFactory;
 14  
 import org.jscsi.target.connection.phase.TargetFullFeaturePhase;
 15  
 import org.jscsi.target.scsi.ScsiResponseDataSegment;
 16  
 import org.jscsi.target.scsi.cdb.SendDiagnosticCdb;
 17  
 import org.jscsi.target.scsi.sense.senseDataDescriptor.senseKeySpecific.FieldPointerSenseKeySpecificData;
 18  
 import org.jscsi.target.settings.SettingsException;
 19  
 
 20  
 
 21  
 /**
 22  
  * A stage for processing <code>SEND DIAGNOSTIC</code> SCSI commands.
 23  
  * <p>
 24  
  * Only support for the default self-test feature, as required by SPC-3, is implemented. Request for other types of
 25  
  * self-test operations will be declined.
 26  
  * 
 27  
  * @author Andreas Ergenzinger
 28  
  */
 29  
 public class SendDiagnosticStage extends TargetFullFeatureStage {
 30  
 
 31  
     public SendDiagnosticStage (TargetFullFeaturePhase targetFullFeaturePhase) {
 32  0
         super(targetFullFeaturePhase);
 33  0
     }
 34  
 
 35  
     @Override
 36  
     public void execute (ProtocolDataUnit pdu) throws IOException , InterruptedException , InternetSCSIException , DigestException , SettingsException {
 37  
 
 38  0
         final BasicHeaderSegment bhs = pdu.getBasicHeaderSegment();
 39  0
         final SCSICommandParser parser = (SCSICommandParser) bhs.getParser();
 40  
 
 41  0
         ProtocolDataUnit responsePdu = null;// the response PDU
 42  
 
 43  
         // get command details in CDB
 44  0
         final SendDiagnosticCdb cdb = new SendDiagnosticCdb(parser.getCDB());
 45  0
         final FieldPointerSenseKeySpecificData[] illegalFieldPointers = cdb.getIllegalFieldPointers();
 46  
 
 47  0
         if (illegalFieldPointers != null) {
 48  
             // an illegal request has been made
 49  
 
 50  0
             responsePdu = createFixedFormatErrorPdu(illegalFieldPointers,// senseKeySpecificData
 51  
                     bhs.getInitiatorTaskTag(),// initiatorTaskTag
 52  
                     parser.getExpectedDataTransferLength());// expectedDataTransferLength
 53  
 
 54  
         } else {
 55  
             // PDU is okay
 56  
             // carry out command
 57  
 
 58  
             /*
 59  
              * The self-test bit is 1, since request of a non-default self-test is not supported and would have led to
 60  
              * illegalFieldPointer != null A self-test (SELFTEST) bit set to one specifies that the device server shall
 61  
              * perform the logical unit default self-test. If the self-test successfully passes, the command shall be
 62  
              * terminated with GOOD status. If the self-test fails, the command shall be terminated with CHECK CONDITION
 63  
              * status, with the sense key set to HARDWARE ERROR. The self-test is always successful.
 64  
              */
 65  0
             responsePdu = TargetPduFactory.createSCSIResponsePdu(false,// bidirectionalReadResidualOverflow
 66  
                     false,// bidirectionalReadResidualUnderflow
 67  
                     false,// residualOverflow
 68  
                     false,// residualUnderflow,
 69  
                     SCSIResponseParser.ServiceResponse.COMMAND_COMPLETED_AT_TARGET,// response,
 70  
                     SCSIStatus.GOOD,// status,
 71  
                     bhs.getInitiatorTaskTag(),// initiatorTaskTag,
 72  
                     0,// snackTag
 73  
                     0,// expectedDataSequenceNumber
 74  
                     0,// bidirectionalReadResidualCount
 75  
                     0,// residualCount
 76  
                     ScsiResponseDataSegment.EMPTY_DATA_SEGMENT);// data
 77  
                                                                 // segment
 78  
         }
 79  
 
 80  
         // send response
 81  0
         connection.sendPdu(responsePdu);
 82  0
     }
 83  
 
 84  
 }