View Javadoc

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.InitiatorMessageParser;
10  import org.jscsi.parser.ProtocolDataUnit;
11  import org.jscsi.target.connection.phase.TargetFullFeaturePhase;
12  import org.jscsi.target.scsi.cdb.ScsiOperationCode;
13  import org.jscsi.target.scsi.sense.senseDataDescriptor.senseKeySpecific.FieldPointerSenseKeySpecificData;
14  import org.jscsi.target.settings.SettingsException;
15  
16  
17  /**
18   * Unlike the other subclasses of {@link TargetFullFeatureStage}, this class is not associated with a single
19   * {@link ScsiOperationCode}. All SCSI Command PDUs containing a SCSI OpCode not supported by the jSCSI Target (i.e.
20   * without a dedicated FullFeatureStage to process them) shall be passed to the {@link #execute(ProtocolDataUnit)}
21   * method of this class, which will dispatch a standard SCSI Response PDU stating that the given
22   * {@link ScsiOperationCode} is not supported by this target.
23   * 
24   * @author Andreas Ergenzinger
25   */
26  public class UnsupportedOpCodeStage extends TargetFullFeatureStage {
27  
28      public UnsupportedOpCodeStage (TargetFullFeaturePhase targetFullFeaturePhase) {
29          super(targetFullFeaturePhase);
30      }
31  
32      @Override
33      public void execute (ProtocolDataUnit pdu) throws IOException , InterruptedException , InternetSCSIException , DigestException , SettingsException {
34  
35          final BasicHeaderSegment bhs = pdu.getBasicHeaderSegment();
36          final InitiatorMessageParser parser = (InitiatorMessageParser) bhs.getParser();
37  
38          // the SCSI OpCode is not supported, tell the initiator
39  
40          final FieldPointerSenseKeySpecificData fp = new FieldPointerSenseKeySpecificData(true,// senseKeySpecificDataValid
41          true,// commandData (i.e. invalid field in CDB)
42          false,// bitPointerValid
43          0,// bitPointer, reserved since invalid
44          0);// fieldPointer to the SCSI OpCode field
45  
46          final FieldPointerSenseKeySpecificData[] fpArray = new FieldPointerSenseKeySpecificData[] { fp };
47  
48          // If the parser is null..
49          int essn = -1;
50  
51          if (parser != null) {
52              essn = parser.getExpectedStatusSequenceNumber();
53          }
54  
55          final ProtocolDataUnit responsePdu = createFixedFormatErrorPdu(fpArray,// senseKeySpecificData
56                  bhs.getInitiatorTaskTag(),// initiatorTaskTag
57                  essn);// expectedDataTransferLength
58  
59          // send response
60          connection.sendPdu(responsePdu);
61      }
62  
63  }