Package org.jscsi.target.connection.stage.fullfeature

Source Code of org.jscsi.target.connection.stage.fullfeature.UnsupportedOpCodeStage

package org.jscsi.target.connection.stage.fullfeature;


import java.io.IOException;
import java.security.DigestException;

import org.jscsi.exception.InternetSCSIException;
import org.jscsi.parser.BasicHeaderSegment;
import org.jscsi.parser.InitiatorMessageParser;
import org.jscsi.parser.ProtocolDataUnit;
import org.jscsi.target.connection.phase.TargetFullFeaturePhase;
import org.jscsi.target.scsi.cdb.ScsiOperationCode;
import org.jscsi.target.scsi.sense.senseDataDescriptor.senseKeySpecific.FieldPointerSenseKeySpecificData;
import org.jscsi.target.settings.SettingsException;


/**
* Unlike the other subclasses of {@link TargetFullFeatureStage}, this class is not associated with a single
* {@link ScsiOperationCode}. All SCSI Command PDUs containing a SCSI OpCode not supported by the jSCSI Target (i.e.
* without a dedicated FullFeatureStage to process them) shall be passed to the {@link #execute(ProtocolDataUnit)}
* method of this class, which will dispatch a standard SCSI Response PDU stating that the given
* {@link ScsiOperationCode} is not supported by this target.
*
* @author Andreas Ergenzinger
*/
public class UnsupportedOpCodeStage extends TargetFullFeatureStage {

    public UnsupportedOpCodeStage (TargetFullFeaturePhase targetFullFeaturePhase) {
        super(targetFullFeaturePhase);
    }

    @Override
    public void execute (ProtocolDataUnit pdu) throws IOException , InterruptedException , InternetSCSIException , DigestException , SettingsException {

        final BasicHeaderSegment bhs = pdu.getBasicHeaderSegment();
        final InitiatorMessageParser parser = (InitiatorMessageParser) bhs.getParser();

        // the SCSI OpCode is not supported, tell the initiator

        final FieldPointerSenseKeySpecificData fp = new FieldPointerSenseKeySpecificData(true,// senseKeySpecificDataValid
        true,// commandData (i.e. invalid field in CDB)
        false,// bitPointerValid
        0,// bitPointer, reserved since invalid
        0);// fieldPointer to the SCSI OpCode field

        final FieldPointerSenseKeySpecificData[] fpArray = new FieldPointerSenseKeySpecificData[] { fp };

        // If the parser is null..
        int essn = -1;

        if (parser != null) {
            essn = parser.getExpectedStatusSequenceNumber();
        }

        final ProtocolDataUnit responsePdu = createFixedFormatErrorPdu(fpArray,// senseKeySpecificData
                bhs.getInitiatorTaskTag(),// initiatorTaskTag
                essn);// expectedDataTransferLength

        // send response
        connection.sendPdu(responsePdu);
    }

}
TOP

Related Classes of org.jscsi.target.connection.stage.fullfeature.UnsupportedOpCodeStage

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.