Package org.jscsi.parser.scsi

Examples of org.jscsi.parser.scsi.SCSICommandParser


    /** {@inheritDoc} */
    public final void execute () throws InternetSCSIException {

        final ProtocolDataUnit protocolDataUnit = protocolDataUnitFactory.create(false, true, OperationCode.SCSI_COMMAND, connection.getSetting(OperationalTextKey.HEADER_DIGEST), connection.getSetting(OperationalTextKey.DATA_DIGEST));
        final SCSICommandParser scsi = (SCSICommandParser) protocolDataUnit.getBasicHeaderSegment().getParser();

        scsi.setReadExpectedFlag(true);
        scsi.setWriteExpectedFlag(false);
        scsi.setTaskAttributes(taskAttributes);
        scsi.setExpectedDataTransferLength(expectedDataTransferLength);
        scsi.setCommandDescriptorBlock(SCSICommandDescriptorBlockParser.createReadMessage(logicalBlockAddress, transferLength));

        connection.send(protocolDataUnit);
        connection.nextState(new ReadResponseState(connection, buffer, 0, 0));
        super.stateFollowing = true;
        // return true;
View Full Code Here


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

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

        ProtocolDataUnit responsePdu = null;// the response PDU

        // get command details in CDB
        if (LOGGER.isDebugEnabled()) {// print CDB bytes
            LOGGER.debug("CDB bytes: \n" + Debug.byteBufferToString(parser.getCDB()));
        }

        final InquiryCDB cdb = new InquiryCDB(parser.getCDB());
        final FieldPointerSenseKeySpecificData[] illegalFieldPointers = cdb.getIllegalFieldPointers();

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("cdb.getAllocationLength() = " + cdb.getAllocationLength());
            LOGGER.debug("cdb.getEnableVitalProductData() = " + cdb.getEnableVitalProductData());
            LOGGER.debug("cdb.isNormalACA() = " + cdb.isNormalACA());
            LOGGER.debug("cdb.getPageCode() = " + cdb.getPageCode());
            LOGGER.debug("cdb.getPageCode().getVitalProductDataPageName() = " + cdb.getPageCode().getVitalProductDataPageName());
        }

        if (illegalFieldPointers != null) {
            // an illegal request has been made
            LOGGER.error("illegal INQUIRY request");

            responsePdu = createFixedFormatErrorPdu(illegalFieldPointers, bhs.getInitiatorTaskTag(), parser.getExpectedDataTransferLength());

            // send response
            connection.sendPdu(responsePdu);

        } else {
            // PDU is okay
            // carry out command

            IResponseData responseData = null;

            // "If the EVPD bit is set to zero, ...
            if (!cdb.getEnableVitalProductData()) {
                // ... the device server shall return the standard INQUIRY
                // data."
                responseData = StandardInquiryData.getInstance();
            } else {
                /*
                 * SCSI initiator is requesting either "device identification" or "supported VPD pages" or this else
                 * block would not have been entered. (see {@link InquiryCDB#checkIntegrity(ByteBuffer dataSegment)})
                 */
                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 :
                        // The initiator must not request unsupported mode pages.
                        throw new InternetSCSIException();
                }
            }

            // send response
            sendResponse(bhs.getInitiatorTaskTag(), parser.getExpectedDataTransferLength(), responseData);
          
        }

    }
View Full Code Here

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

        final BasicHeaderSegment bhs = pdu.getBasicHeaderSegment();
        final SCSICommandParser parser = (SCSICommandParser) bhs.getParser();
        final ModeSense6Cdb cdb = new ModeSense6Cdb(parser.getCDB());

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(Boolean.toString(cdb.getDisableBlockDescriptors()));
            LOGGER.debug(cdb.getPageControl().toString());
            LOGGER.debug(Integer.toString(cdb.getPageCode()));
            LOGGER.debug(Integer.toString(cdb.getSubpageCode()));
            LOGGER.debug("cdb.getAllocationLength() = " + cdb.getAllocationLength());
            // LOGGER.debug(cdb.getModePage());
        }

        // final PageControl pageControl = cdb.getPageControl();//see 8 lines
        // below
        final ModePageCode modePageCode = cdb.getModePage();

        // ModeParameterList and ModeParameterListBuilder common to
        // all supported ModePage requests

        ModePage[] modePages = null;
        if (modePageCode == ModePageCode.INFORMATIONAL_EXCEPTIONS_CONTROL_MODE_PAGE) {
            // TODO this should to be made dynamic wrt. cdb.getPageControl();

            modePages = new ModePage[] { getInformationExceptionsControlModePage() };

        } else if (modePageCode == ModePageCode.CACHING_MODE_PAGE) {

            modePages = new ModePage[] { getCachingModePage() };

        } else if (modePageCode == ModePageCode.RETURN_ALL_MODE_PAGES_ONLY) {

            modePages = new ModePage[] { getInformationExceptionsControlModePage(), getCachingModePage() };

        }// else modeParameterList stays null

        // create and send response PDU
        if (modePages != null) {

            // create ModeParameterList
            final ModeParameterListBuilder builder = new ModeParameterListBuilder(HeaderType.MODE_PARAMETER_HEADER_6);
            builder.setLogicalBlockDescriptors(new ShortLogicalBlockDescriptor(session.getStorageModule().getSizeInBlocks(),// numberOfLogicalBlocks
            VIRTUAL_BLOCK_SIZE));// logicalBlockLength
            builder.setModePages(modePages);
            ModeParameterList modeParameterList = ModeParameterList.build(builder);

            // send response
            sendResponse(bhs.getInitiatorTaskTag(),// initiatorTaskTag,
                    parser.getExpectedDataTransferLength(),// expectedDataTransferLength,
                    modeParameterList);// responseData

        } else {
            /*
             * The initiator has requested a mode sense page which the jSCSI Target cannot provide. This could be
View Full Code Here

        0);// cacheSegmentSize
    }

    public boolean canHandle (final ProtocolDataUnit pdu) {
        final BasicHeaderSegment bhs = pdu.getBasicHeaderSegment();
        final SCSICommandParser parser = (SCSICommandParser) bhs.getParser();
        final ModeSense6Cdb cdb = new ModeSense6Cdb(parser.getCDB());
        final ModePageCode modePageCode = cdb.getModePage();
        if (modePageCode == ModePageCode.INFORMATIONAL_EXCEPTIONS_CONTROL_MODE_PAGE) {
            return true;
        } else if (modePageCode == ModePageCode.CACHING_MODE_PAGE) {
            return true;
View Full Code Here

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

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

        ProtocolDataUnit responsePdu = null;// the response PDU

        // get command details in CDB
        final SendDiagnosticCdb cdb = new SendDiagnosticCdb(parser.getCDB());
        final FieldPointerSenseKeySpecificData[] illegalFieldPointers = cdb.getIllegalFieldPointers();

        if (illegalFieldPointers != null) {
            // an illegal request has been made

            responsePdu = createFixedFormatErrorPdu(illegalFieldPointers,// senseKeySpecificData
                    bhs.getInitiatorTaskTag(),// initiatorTaskTag
                    parser.getExpectedDataTransferLength());// expectedDataTransferLength

        } else {
            // PDU is okay
            // carry out command
View Full Code Here

            LOGGER.debug("initialR2T = " + initialR2T);
        }

        // get relevant values from PDU/CDB
        BasicHeaderSegment bhs = pdu.getBasicHeaderSegment();
        SCSICommandParser parser = (SCSICommandParser) bhs.getParser();
        final int initiatorTaskTag = bhs.getInitiatorTaskTag();
        WriteCdb cdb;
        final ScsiOperationCode scsiOpCode = ScsiOperationCode.valueOf(parser.getCDB().get(0));
        if (scsiOpCode == ScsiOperationCode.WRITE_10)
            cdb = new Write10Cdb(parser.getCDB());
        else if (scsiOpCode == ScsiOperationCode.WRITE_6)
            cdb = new Write6Cdb(parser.getCDB());
        else {
            // anything else wouldn't be good (programmer error)
            // close connection
            throw new InternetSCSIException("wrong SCSI Operation Code " + scsiOpCode + " in WriteStage");
        }
        final int transferLength = cdb.getTransferLength();
        final long logicalBlockAddress = cdb.getLogicalBlockAddress();

        // transform to from block units to byte units
        final int transferLengthInBytes = transferLength * VIRTUAL_BLOCK_SIZE;
        long storageIndex = logicalBlockAddress * VIRTUAL_BLOCK_SIZE;

        // check if requested blocks are out of bounds
        // (might add FPSKSD to the CDB's list to be detected in the next step)
        checkOverAndUnderflow(cdb);

        if (cdb.getIllegalFieldPointers() != null) {
            /*
             * CDB is invalid, inform initiator by closing the connection. Sending an error status SCSI Response PDU
             * will not work reliably, since the initiator may not be expecting a response so soon. Also, if the
             * WriteStage is simply left early (without closing the connection), the initiator may send additional
             * unsolicited Data-Out PDUs, which the jSCSI Target is currently unable to ignore or process properly.
             */
            LOGGER.debug("illegal field in Write CDB");
            LOGGER.debug("CDB:\n" + Debug.byteBufferToString(parser.getCDB()));
           
            // Not necessarily close the connection

            // create and send error PDU and leave stage
            final ProtocolDataUnit responsePdu = createFixedFormatErrorPdu(cdb.getIllegalFieldPointers(),// senseKeySpecificData
                    initiatorTaskTag, parser.getExpectedDataTransferLength());
            connection.sendPdu(responsePdu);
            return;
        }

        // *** start receiving data (or process what has already been sent) ***
 
View Full Code Here

            LOGGER.debug("maxRecvDataSegmentLength = " + settings.getMaxRecvDataSegmentLength());
        }

        // ... and from the PDU
        BasicHeaderSegment bhs = pdu.getBasicHeaderSegment();
        SCSICommandParser parser = (SCSICommandParser) bhs.getParser();
        final int initiatorTaskTag = bhs.getInitiatorTaskTag();

        // get the Read(6) or Read(10) CDB
        ReadCdb cdb;
        final ScsiOperationCode scsiOpCode = ScsiOperationCode.valueOf(parser.getCDB().get(0));
        if (scsiOpCode == ScsiOperationCode.READ_10)// most likely option first
            cdb = new Read10Cdb(parser.getCDB());
        else if (scsiOpCode == ScsiOperationCode.READ_6)
            cdb = new Read6Cdb(parser.getCDB());
        else {
            // anything else wouldn't be good (programmer error)
            // close connection
            throw new InternetSCSIException("wrong SCSI Operation Code " + scsiOpCode + " in ReadStage");
        }

        // check if requested blocks are out of bounds
        checkOverAndUnderflow(cdb);

        // check illegal field pointers
        if (cdb.getIllegalFieldPointers() != null) {
            // the command must fail

            LOGGER.debug("illegal field in Read CDB");

            // create and send error PDU and leave stage
            final ProtocolDataUnit responsePdu = createFixedFormatErrorPdu(cdb.getIllegalFieldPointers(),// senseKeySpecificData
                    initiatorTaskTag, parser.getExpectedDataTransferLength());
            connection.sendPdu(responsePdu);
            return;
        }

        final int totalTransferLength = VIRTUAL_BLOCK_SIZE * cdb.getTransferLength();
        final long storageOffset = VIRTUAL_BLOCK_SIZE * cdb.getLogicalBlockAddress();

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("cdb.getLogicalBlockAddress() = " + cdb.getLogicalBlockAddress());
            LOGGER.debug("blockSize = " + VIRTUAL_BLOCK_SIZE);
            LOGGER.debug("totalTransferLength = " + totalTransferLength);
            LOGGER.debug("expectedDataSegmentLength = " + parser.getExpectedDataTransferLength());
        }

        // *** start sending ***
        // initialize counters and data segment buffer
        int bytesSent = 0;
View Full Code Here

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

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

        ProtocolDataUnit responsePDU = null;// the response PDU

        // get command details in CDB
        final RequestSenseCdb cdb = new RequestSenseCdb(parser.getCDB());
        final FieldPointerSenseKeySpecificData[] illegalFieldPointers = cdb.getIllegalFieldPointers();

        if (illegalFieldPointers != null) {
            // an illegal request has been made

            SenseData senseData;

            if (cdb.getDescriptorFormat()) {
                // descriptor format sense data has been requested

                senseData = new DescriptorFormatSenseData(ErrorType.CURRENT,// errorType
                SenseKey.ILLEGAL_REQUEST,// sense key
                AdditionalSenseCodeAndQualifier.INVALID_FIELD_IN_CDB,// additional
                                                                     // sense
                                                                     // code
                                                                     // and
                                                                     // qualifier
                new SenseDataDescriptor[0]);// sense data descriptors

            } else {
                // fixed format sense data has been requested

                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
            }

            responsePDU = TargetPduFactory.createSCSIResponsePdu(false,// bidirectionalReadResidualOverflow
                    false,// bidirectionalReadResidualUnderflow
                    false,// residualOverflow
                    false,// residualUnderflow,
                    SCSIResponseParser.ServiceResponse.TARGET_FAILURE,// response,
                    SCSIStatus.CHECK_CONDITION,// status,
                    bhs.getInitiatorTaskTag(),// initiatorTaskTag,
                    0,// snackTag
                    0,// expectedDataSequenceNumber
                    0,// bidirectionalReadResidualCount
                    0,// residualCount
                    new ScsiResponseDataSegment(senseData, parser.getExpectedDataTransferLength()));// data
                                                                                                    // segment

        } else {
            /*
             * PDU is okay carry out command Sense data shall be available and cleared under the conditions defined in
             * SAM-3. If the device server has no other sense data available to return, it shall return the sense key
             * set to NO SENSE and the additional sense code set to NO ADDITIONAL SENSE INFORMATION. This will always be
             * the case with the jSCSI Target.
             */

            SenseData senseData;

            final SenseKey senseKey = SenseKey.NO_SENSE;
            final AdditionalSenseCodeAndQualifier additionalSense = AdditionalSenseCodeAndQualifier.NO_ADDITIONAL_SENSE_INFORMATION;

            if (cdb.getDescriptorFormat()) {
                // descriptor format sense data has been requested

                senseData = new DescriptorFormatSenseData(ErrorType.CURRENT,// errorType
                senseKey,// sense key
                additionalSense,// additional sense code and qualifier
                new SenseDataDescriptor[0]);// sense data descriptors

            } else {
                // fixed format sense data has been requested

                senseData = new FixedFormatSenseData(false,// valid
                ErrorType.CURRENT,// error type
                false,// file mark
                false,// end of medium
                false,// incorrect length indicator
                senseKey,// sense key
                new FourByteInformation(),// information
                new FourByteInformation(),// command specific
                                          // information
                additionalSense,// additional sense code and qualifier
                (byte) 0,// field replaceable unit code
                null,// sense key specific data, only report first
                     // problem
                null);// additional sense bytes
            }

            responsePDU = TargetPduFactory.createSCSIResponsePdu(false,// bidirectionalReadResidualOverflow
                    false,// bidirectionalReadResidualUnderflow
                    false,// residualOverflow
                    false,// residualUnderflow,
                    SCSIResponseParser.ServiceResponse.COMMAND_COMPLETED_AT_TARGET,// response,
                    SCSIStatus.GOOD,// status,
                    bhs.getInitiatorTaskTag(),// initiatorTaskTag,
                    0,// snackTag
                    0,// expectedDataSequenceNumber
                    0,// bidirectionalReadResidualCount
                    0,// residualCount
                    new ScsiResponseDataSegment(senseData, parser.getExpectedDataTransferLength()));// data
                                                                                                    // segment
        }

        // send response
        connection.sendPdu(responsePDU);
View Full Code Here

        if (LOGGER.isDebugEnabled()) {
            // sharrajesh
            // Needed to debug, out of order receiving of StatusSN and ExpStatSN
            if (bhs.getOpCode() == OperationCode.SCSI_COMMAND) {
                final SCSICommandParser scsiParser = (SCSICommandParser) bhs.getParser();
                ScsiOperationCode scsiOpCode = ScsiOperationCode.valueOf(scsiParser.getCDB().get(0));
                LOGGER.debug("scsiOpCode = " + scsiOpCode);
                LOGGER.debug("CDB bytes: \n" + Debug.byteBufferToString(scsiParser.getCDB()));
            }
            // LOGGER.debug("parser.expectedStatusSequenceNumber: " + expectedStatusSequenceNumber);
            if (connection == null)
                LOGGER.debug("connection: null");
            else if (connection.getStatusSequenceNumber() == null)
View Full Code Here

TOP

Related Classes of org.jscsi.parser.scsi.SCSICommandParser

Copyright © 2018 www.massapicom. 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.