Examples of BasicHeaderSegment


Examples of org.jscsi.parser.BasicHeaderSegment

        boolean loginSuccessful = true;// will determine if settings are
                                       // committed

        try {
            // if possible, enter LOPN Stage
            BasicHeaderSegment bhs = pdu.getBasicHeaderSegment();
            LoginRequestParser parser = (LoginRequestParser) bhs.getParser();

            LoginStage nextStageNumber;// will store return value from the last
                                       // login stage

            // Security Negotiation Stage (optional)
            if (parser.getCurrentStageNumber() == LoginStage.SECURITY_NEGOTIATION) {
                // complete SNS
                stage = new SecurityNegotiationStage(this);
                stage.execute(pdu);
                nextStageNumber = stage.getNextStageNumber();

                if (nextStageNumber != null)
                    authenticated = true;
                else {
                    loginSuccessful = false;
                    return false;
                }

                if (nextStageNumber == LoginStage.LOGIN_OPERATIONAL_NEGOTIATION) {
                    // receive first PDU from LOPNS
                    pdu = connection.receivePdu();
                    bhs = pdu.getBasicHeaderSegment();
                    parser = (LoginRequestParser) bhs.getParser();
                } else if (nextStageNumber == LoginStage.FULL_FEATURE_PHASE) {
                    // we are done here
                    return true;
                } else {
                    // should be unreachable, since SNS may not return NSG==SNS
View Full Code Here

Examples of org.jscsi.parser.BasicHeaderSegment

    public boolean execute () throws DigestException , IOException , InterruptedException , InternetSCSIException , SettingsException {

        running = true;
        while (running) {
            ProtocolDataUnit pdu = connection.receivePdu();
            BasicHeaderSegment bhs = pdu.getBasicHeaderSegment();

            // identify desired stage
            switch (bhs.getOpCode()) {

                case SCSI_COMMAND :
                    if (connection.getTargetSession().isNormalSession()) {
                        final SCSICommandParser parser = (SCSICommandParser) bhs.getParser();
                        ScsiOperationCode scsiOpCode = ScsiOperationCode.valueOf(parser.getCDB().get(0));

                        LOGGER.debug("scsiOpCode = " + scsiOpCode);// log SCSI
                                                                   // Operation Code
View Full Code Here

Examples of org.jscsi.parser.BasicHeaderSegment

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

        // find out the type of READ CAPACITY command ((10) or (16))
        final BasicHeaderSegment bhs = pdu.getBasicHeaderSegment();
        final SCSICommandParser parser = (SCSICommandParser) bhs.getParser();
        final ScsiOperationCode opCode = ScsiOperationCode.valueOf(parser.getCDB().get(0));
        ReadCapacityCdb cdb;
        if (opCode == ScsiOperationCode.READ_CAPACITY_10)
            cdb = new ReadCapacity10Cdb(parser.getCDB());
        else if (opCode == ScsiOperationCode.READ_CAPACITY_16)
            cdb = new ReadCapacity16Cdb(parser.getCDB());
        else {
            // programmer error, we should not be here, close the connection
            throw new InternetSCSIException("wrong SCSI Operation Code " + opCode + " in ReadCapacityStage");
        }

        /*
         * Everything is fine, carry on. The PMI bit of the command descriptor block is ignored, since there is no way
         * to know if "substantial vendor specific delay in data transfer may be encountered" after the address in the
         * LOGICAL BLOCK ADDRESS field. Therefore we always try to return the whole length of the storage medium.
         */

        // make sure that the LOGICAL BLOCK ADDRESS field is valid and send
        // appropriate response
        if (session.getStorageModule().checkBounds(cdb.getLogicalBlockAddress(), 0) != 0) {
            // invalid, log error, send error PDU, and return
            LOGGER.error("encountered " + cdb.getClass() + " in ReadCapacityStage with " + "LOGICAL BLOCK ADDRESS = " + cdb.getLogicalBlockAddress());

            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 };
            final ProtocolDataUnit responsePdu = createFixedFormatErrorPdu(fpArray,// senseKeySpecificData
                    AdditionalSenseCodeAndQualifier.LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE,// additionalSenseCodeAndQualifier
                    bhs.getInitiatorTaskTag(),// initiatorTaskTag
                    parser.getExpectedDataTransferLength());// expectedDataTransferLength
            connection.sendPdu(responsePdu);
            return;
        } else {
            // send PDU with requested READ CAPACITY parameter data
            ReadCapacityParameterData parameterData;
            if (cdb instanceof ReadCapacity10Cdb)
                parameterData = new ReadCapacity10ParameterData(session.getStorageModule().getSizeInBlocks(),// returnedLogicalBlockAddress
                VIRTUAL_BLOCK_SIZE);// logicalBlockLengthInBytes
            else
                parameterData = new ReadCapacity16ParameterData(session.getStorageModule().getSizeInBlocks(),// returnedLogicalBlockAddress
                VIRTUAL_BLOCK_SIZE);// logicalBlockLengthInBytes

            sendResponse(bhs.getInitiatorTaskTag(),// initiatorTaskTag,
                    parser.getExpectedDataTransferLength(),// expectedDataTransferLength,
                    parameterData);// responseData
        }
    }
View Full Code Here

Examples of org.jscsi.parser.BasicHeaderSegment

    }

    @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

Examples of org.jscsi.parser.BasicHeaderSegment

    }

    @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);
    }
View Full Code Here

Examples of org.jscsi.parser.BasicHeaderSegment

    }

    @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 {
            /*
 
View Full Code Here

Examples of org.jscsi.parser.BasicHeaderSegment

        20,// numberOfCacheSegments
        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) {
View Full Code Here

Examples of org.jscsi.parser.BasicHeaderSegment

    }

    @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

            /*
             * The self-test bit is 1, since request of a non-default self-test is not supported and would have led to
             * illegalFieldPointer != null A self-test (SELFTEST) bit set to one specifies that the device server shall
             * perform the logical unit default self-test. If the self-test successfully passes, the command shall be
             * terminated with GOOD status. If the self-test fails, the command shall be terminated with CHECK CONDITION
             * status, with the sense key set to HARDWARE ERROR. The self-test is always successful.
             */
            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
                    ScsiResponseDataSegment.EMPTY_DATA_SEGMENT);// data
View Full Code Here

Examples of org.jscsi.parser.BasicHeaderSegment

            LOGGER.debug("immediateData = " + immediateData);
            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) ***
        int bytesReceived = 0;

        // *** receive immediate data ***
        if (immediateData && bhs.getDataSegmentLength() > 0) {
            final byte[] immediateDataArray = pdu.getDataSegment().array();

            session.getStorageModule().write(immediateDataArray, storageIndex);
            bytesReceived = immediateDataArray.length;

            if (LOGGER.isDebugEnabled()) LOGGER.debug("wrote " + immediateDataArray.length + "bytes as immediate data");
        }

        // *** receive unsolicited data ***
        if (!initialR2T && !bhs.isFinalFlag()) {

            if (LOGGER.isDebugEnabled()) LOGGER.debug("receiving unsolicited data");

            boolean firstBurstOver = false;
            while (!firstBurstOver && bytesReceived <= firstBurstLength) {

                // receive and check PDU
                pdu = connection.receivePdu();
                bhs = pdu.getBasicHeaderSegment();

                checkDataOutParser(bhs.getParser());

                final DataOutParser dataOutParser = (DataOutParser) bhs.getParser();

                session.getStorageModule().write(pdu.getDataSegment().array(), storageIndex + dataOutParser.getBufferOffset());
                ;
                bytesReceived += bhs.getDataSegmentLength();

                if (bhs.isFinalFlag()) firstBurstOver = true;
            }
        }

        // *** receive solicited data ***
        if (bytesReceived < transferLengthInBytes) {
            if (LOGGER.isDebugEnabled()) LOGGER.debug(bytesReceived + "<" + transferLengthInBytes);

            int readyToTransferSequenceNumber = 0;
            int desiredDataTransferLength;

            while (bytesReceived < transferLengthInBytes) {

                desiredDataTransferLength = Math.min(maxBurstLength, transferLengthInBytes - bytesReceived);

                // send R2T
                pdu = TargetPduFactory.createReadyToTransferPdu(0,// logicalUnitNumber
                        initiatorTaskTag, TargetServer.getNextTargetTransferTag(),// targetTransferTag
                        readyToTransferSequenceNumber++, bytesReceived,// bufferOffset
                        desiredDataTransferLength);

                connection.sendPdu(pdu);

                // receive DataOut PDUs
                expectedDataSequenceNumber = 0;// reset sequence counter//FIXME
                                               // fix in jSCSI Initiator
                boolean solicitedDataCycleOver = false;
                int bytesReceivedThisCycle = 0;
                while (!solicitedDataCycleOver) {

                    // receive and check PDU
                    pdu = connection.receivePdu();
                    bhs = pdu.getBasicHeaderSegment();
                    checkDataOutParser(bhs.getParser());

                    if (bhs.getParser() instanceof NOPOutParser) {

                        /* send SCSI Response PDU */
                        pdu = TargetPduFactory.createSCSIResponsePdu(false,// bidirectionalReadResidualOverflow
                                false,// bidirectionalReadResidualUnderflow
                                false,// residualOverflow
                                false,// residualUnderflow
                                SCSIResponseParser.ServiceResponse.COMMAND_COMPLETED_AT_TARGET,// response
                                SCSIStatus.GOOD,// status
                                initiatorTaskTag, 0,// snackTag
                                0,// (ExpDataSN or) Reserved
                                0,// bidirectionalReadResidualCount
                                0,// residualCount
                                ScsiResponseDataSegment.EMPTY_DATA_SEGMENT);// dataSegment

                        connection.sendPdu(pdu);
                        return;
                    } else if (bhs.getParser() instanceof DataOutParser) {
                        final DataOutParser dataOutParser = (DataOutParser) bhs.getParser();

                        session.getStorageModule().write(pdu.getDataSegment().array(), storageIndex + dataOutParser.getBufferOffset());

                        bytesReceivedThisCycle += bhs.getDataSegmentLength();

                        /*
                         * Checking the final flag should be enough, but is not, when dealing with the jSCSI Initiator.
                         * This is also one of the reasons, why the contents of this while loop, though very similar to
                         * what is happening during the receiving of the unsolicited data PDU sequence, has not been put
                         * into a dedicated method.
                         */
                        if (bhs.isFinalFlag() || bytesReceivedThisCycle >= desiredDataTransferLength) solicitedDataCycleOver = true;
                    }
                }
                bytesReceived += bytesReceivedThisCycle;
            }
        }
View Full Code Here

Examples of org.jscsi.parser.BasicHeaderSegment

            LOGGER.debug("immediateData = " + immediateData);
            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
View Full Code Here
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.