| 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.target.connection.phase.TargetFullFeaturePhase; |
| 12 | |
import org.jscsi.target.scsi.IResponseData; |
| 13 | |
import org.jscsi.target.scsi.cdb.InquiryCDB; |
| 14 | |
import org.jscsi.target.scsi.inquiry.PageCode.VitalProductDataPageName; |
| 15 | |
import org.jscsi.target.scsi.inquiry.StandardInquiryData; |
| 16 | |
import org.jscsi.target.scsi.inquiry.SupportedVpdPages; |
| 17 | |
import org.jscsi.target.scsi.sense.senseDataDescriptor.senseKeySpecific.FieldPointerSenseKeySpecificData; |
| 18 | |
import org.jscsi.target.settings.SettingsException; |
| 19 | |
import org.jscsi.target.util.Debug; |
| 20 | |
import org.slf4j.Logger; |
| 21 | |
import org.slf4j.LoggerFactory; |
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
public class InquiryStage extends TargetFullFeatureStage { |
| 30 | |
|
| 31 | 0 | private static final Logger LOGGER = LoggerFactory.getLogger(InquiryStage.class); |
| 32 | |
|
| 33 | |
public InquiryStage (TargetFullFeaturePhase targetFullFeaturePhase) { |
| 34 | 0 | super(targetFullFeaturePhase); |
| 35 | 0 | } |
| 36 | |
|
| 37 | |
@Override |
| 38 | |
public void execute (ProtocolDataUnit pdu) throws IOException , InterruptedException , InternetSCSIException , DigestException , SettingsException { |
| 39 | |
|
| 40 | 0 | final BasicHeaderSegment bhs = pdu.getBasicHeaderSegment(); |
| 41 | 0 | final SCSICommandParser parser = (SCSICommandParser) bhs.getParser(); |
| 42 | |
|
| 43 | 0 | ProtocolDataUnit responsePdu = null; |
| 44 | |
|
| 45 | |
|
| 46 | 0 | if (LOGGER.isDebugEnabled()) { |
| 47 | 0 | LOGGER.debug("CDB bytes: \n" + Debug.byteBufferToString(parser.getCDB())); |
| 48 | |
} |
| 49 | |
|
| 50 | 0 | final InquiryCDB cdb = new InquiryCDB(parser.getCDB()); |
| 51 | 0 | final FieldPointerSenseKeySpecificData[] illegalFieldPointers = cdb.getIllegalFieldPointers(); |
| 52 | |
|
| 53 | 0 | if (LOGGER.isDebugEnabled()) { |
| 54 | 0 | LOGGER.debug("cdb.getAllocationLength() = " + cdb.getAllocationLength()); |
| 55 | 0 | LOGGER.debug("cdb.getEnableVitalProductData() = " + cdb.getEnableVitalProductData()); |
| 56 | 0 | LOGGER.debug("cdb.isNormalACA() = " + cdb.isNormalACA()); |
| 57 | 0 | LOGGER.debug("cdb.getPageCode() = " + cdb.getPageCode()); |
| 58 | 0 | LOGGER.debug("cdb.getPageCode().getVitalProductDataPageName() = " + cdb.getPageCode().getVitalProductDataPageName()); |
| 59 | |
} |
| 60 | |
|
| 61 | 0 | if (illegalFieldPointers != null) { |
| 62 | |
|
| 63 | 0 | LOGGER.error("illegal INQUIRY request"); |
| 64 | |
|
| 65 | 0 | responsePdu = createFixedFormatErrorPdu(illegalFieldPointers, bhs.getInitiatorTaskTag(), parser.getExpectedDataTransferLength()); |
| 66 | |
|
| 67 | |
|
| 68 | 0 | connection.sendPdu(responsePdu); |
| 69 | |
|
| 70 | |
} else { |
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | 0 | IResponseData responseData = null; |
| 75 | |
|
| 76 | |
|
| 77 | 0 | if (!cdb.getEnableVitalProductData()) { |
| 78 | |
|
| 79 | |
|
| 80 | 0 | responseData = StandardInquiryData.getInstance(); |
| 81 | |
} else { |
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | 0 | final VitalProductDataPageName pageName = cdb.getPageCode().getVitalProductDataPageName(); |
| 87 | |
|
| 88 | 0 | switch (pageName) { |
| 89 | |
case SUPPORTED_VPD_PAGES : |
| 90 | 0 | responseData = SupportedVpdPages.getInstance(); |
| 91 | 0 | break; |
| 92 | |
case DEVICE_IDENTIFICATION : |
| 93 | 0 | responseData = session.getTargetServer().getDeviceIdentificationVpdPage(); |
| 94 | 0 | break; |
| 95 | |
default : |
| 96 | |
|
| 97 | 0 | throw new InternetSCSIException(); |
| 98 | |
} |
| 99 | |
} |
| 100 | |
|
| 101 | |
|
| 102 | 0 | sendResponse(bhs.getInitiatorTaskTag(), parser.getExpectedDataTransferLength(), responseData); |
| 103 | |
|
| 104 | |
} |
| 105 | |
|
| 106 | 0 | } |
| 107 | |
|
| 108 | |
} |