|
From: <ga...@us...> - 2008-05-13 14:34:56
|
Revision: 4097
http://jnode.svn.sourceforge.net/jnode/?rev=4097&view=rev
Author: galatnm
Date: 2008-05-13 07:34:54 -0700 (Tue, 13 May 2008)
Log Message:
-----------
Refactor code.
Modified Paths:
--------------
trunk/fs/src/driver/org/jnode/driver/block/usb/storage/ITransport.java
trunk/fs/src/driver/org/jnode/driver/block/usb/storage/USBStorageBulkTransport.java
trunk/fs/src/driver/org/jnode/driver/block/usb/storage/USBStorageDeviceData.java
trunk/fs/src/driver/org/jnode/driver/block/usb/storage/USBStorageSCSIHostDriver.java
trunk/fs/src/driver/org/jnode/driver/block/usb/storage/scsi/USBStorageSCSIDriver.java
Modified: trunk/fs/src/driver/org/jnode/driver/block/usb/storage/ITransport.java
===================================================================
--- trunk/fs/src/driver/org/jnode/driver/block/usb/storage/ITransport.java 2008-05-13 14:13:57 UTC (rev 4096)
+++ trunk/fs/src/driver/org/jnode/driver/block/usb/storage/ITransport.java 2008-05-13 14:34:54 UTC (rev 4097)
@@ -25,6 +25,16 @@
import org.jnode.driver.bus.usb.USBException;
public interface ITransport {
- public void transport(CDB cdb);
+ /**
+ *
+ * @param cdb
+ * @param timeout
+ */
+ public void transport(CDB cdb, long timeout);
+
+ /**
+ *
+ * @throws USBException
+ */
public void reset()throws USBException;
}
Modified: trunk/fs/src/driver/org/jnode/driver/block/usb/storage/USBStorageBulkTransport.java
===================================================================
--- trunk/fs/src/driver/org/jnode/driver/block/usb/storage/USBStorageBulkTransport.java 2008-05-13 14:13:57 UTC (rev 4096)
+++ trunk/fs/src/driver/org/jnode/driver/block/usb/storage/USBStorageBulkTransport.java 2008-05-13 14:34:54 UTC (rev 4097)
@@ -29,42 +29,29 @@
import org.jnode.driver.bus.usb.USBDevice;
import org.jnode.driver.bus.usb.USBException;
import org.jnode.driver.bus.usb.USBPacket;
-import org.jnode.driver.bus.usb.USBPipeListener;
import org.jnode.driver.bus.usb.USBRequest;
import org.jnode.util.NumberUtils;
-final class USBStorageBulkTransport implements ITransport, USBPipeListener,
- USBStorageConstants {
+final class USBStorageBulkTransport implements ITransport, USBStorageConstants {
/** My logger */
private static final Logger log = Logger.getLogger(USBStorageBulkTransport.class);
+ /** */
+ private final USBStorageDeviceData storageDeviceData;
- /** The device */
- private final USBDevice device;
-
- /* */
- private final USBStorageDeviceData devData;
-
- USBDataPipe pipe;
-
-
-
/**
*
- * @param dev
+ * @param storageDeviceData
*/
- public USBStorageBulkTransport(USBDevice device, USBStorageDeviceData devData) {
- this.device = device;
- this.devData = devData;
+ public USBStorageBulkTransport(USBStorageDeviceData storageDeviceData) {
+ this.storageDeviceData = storageDeviceData;
}
- /**
- * Bulk only transport workflow.
- *
- * @param cdb
- *
+ /*
+ * (non-Javadoc)
+ * @see org.jnode.driver.block.usb.storage.ITransport#transport(org.jnode.driver.bus.scsi.CDB, int)
*/
- public void transport(CDB cdb) {
+ public void transport(CDB cdb, long timeout) {
try {
byte[] scsiCmd = cdb.toByteArray();
// Setup command wrapper
@@ -78,23 +65,33 @@
cbw.setCdb(scsiCmd);
log.debug(cbw.toString());
// Sent CBW to device
- pipe = (USBDataPipe) devData.getBulkOutEndPoint().getPipe();
- pipe.addListener(this);
- pipe.open();
- USBRequest req = pipe.createRequest(cbw);
- log.debug("*** Request data : " + req.toString());
- log.debug("*** Request status : 0x" + NumberUtils.hex(req.getStatus(),4));
- pipe.asyncSubmit(req);
+ USBDataPipe outPipe = ((USBDataPipe)storageDeviceData.getBulkOutEndPoint().getPipe());
+ USBRequest req = outPipe.createRequest(cbw);
+ if(timeout <= 0){
+ outPipe.asyncSubmit(req);
+ } else {
+ outPipe.syncSubmit(req, timeout);
+ }
+ //
+ CSW csw = new CSW();
+ csw.setSignature(US_BULK_CS_SIGN);
+ USBDataPipe inPipe = ((USBDataPipe)storageDeviceData.getBulkInEndPoint().getPipe());
+ USBRequest resp = inPipe.createRequest(csw);
+ if(timeout <= 0){
+ inPipe.asyncSubmit(resp);
+ } else {
+ inPipe.syncSubmit(resp,timeout);
+ }
} catch (USBException e) {
e.printStackTrace();
}
}
-
+
/**
* Bulk-Only mass storage reset.
*/
public void reset() throws USBException {
- final USBControlPipe pipe = device.getDefaultControlPipe();
+ final USBControlPipe pipe = storageDeviceData.getDevice().getDefaultControlPipe();
final USBRequest req = pipe.createRequest(new SetupPacket(USB_DIR_OUT
| USB_TYPE_CLASS | USB_RECIP_INTERFACE, 0xFF, 0, 0, 0), null);
pipe.syncSubmit(req, GET_TIMEOUT);
@@ -116,27 +113,11 @@
log.debug("*** Request data : " + req.toString());
log.debug("*** Request status : 0x" + NumberUtils.hex(req.getStatus(),4));
if(req.getStatus() == USBREQ_ST_COMPLETED){
- devData.setMaxLun(packet.getData()[0]);
+ storageDeviceData.setMaxLun(packet.getData()[0]);
} else if (req.getStatus() == USBREQ_ST_STALLED){
- devData.setMaxLun((byte)0);
+ storageDeviceData.setMaxLun((byte)0);
} else {
throw new USBException("Request status : 0x" + NumberUtils.hex(req.getStatus(),4));
}
}
-
-
- public void requestCompleted(USBRequest request) {
- log.debug("*** Request Completed ***");
- log.debug("*** Request data : " + request.toString());
- log.debug("USBStorageBulkTransport completed with status : 0x" + NumberUtils.hex(request.getStatus(),4));
-
- CSW csw = (CSW) request;
- log.debug(csw.toString());
- }
-
- public void requestFailed(USBRequest request) {
- log.debug("*** Request data : " + request.toString());
- log.debug("USBStorageBulkTransport failed with status : 0x" + NumberUtils.hex(request.getStatus(),4));
- pipe.close();
- }
}
Modified: trunk/fs/src/driver/org/jnode/driver/block/usb/storage/USBStorageDeviceData.java
===================================================================
--- trunk/fs/src/driver/org/jnode/driver/block/usb/storage/USBStorageDeviceData.java 2008-05-13 14:13:57 UTC (rev 4096)
+++ trunk/fs/src/driver/org/jnode/driver/block/usb/storage/USBStorageDeviceData.java 2008-05-13 14:34:54 UTC (rev 4097)
@@ -18,17 +18,25 @@
* along with this library; If not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
+
package org.jnode.driver.block.usb.storage;
+import org.apache.log4j.Logger;
+import org.jnode.driver.DriverException;
import org.jnode.driver.bus.usb.InterfaceDescriptor;
import org.jnode.driver.bus.usb.USBDataPipe;
+import org.jnode.driver.bus.usb.USBDevice;
import org.jnode.driver.bus.usb.USBEndPoint;
+import org.jnode.driver.bus.usb.USBInterface;
-final class USBStorageDeviceData {
- /** */
- private InterfaceDescriptor intf;
+final class USBStorageDeviceData implements USBStorageConstants {
+ /** My logger */
+ private static final Logger log = Logger.getLogger(USBStorageDeviceData.class);
/** */
+ private USBDevice device;
+ /** */
+ private USBInterface usbInterface;
+ /** */
private int protocol;
/** */
private int subClass;
@@ -51,14 +59,56 @@
/** */
private byte maxLun;
-
- public USBStorageDeviceData(InterfaceDescriptor intf) {
- this.intf = intf;
+ /**
+ *
+ * @param device
+ * @throws DriverException
+ */
+ public USBStorageDeviceData(USBDevice device) throws DriverException {
+ this.device = device;
+ this.usbInterface = this.device.getConfiguration(0).getInterface(0);
+ InterfaceDescriptor intf = this.usbInterface.getDescriptor();
this.maxLun = 0;
this.protocol = intf.getInterfaceProtocol();
this.subClass = intf.getInterfaceSubClass();
+
+ switch (this.protocol) {
+ case US_PR_CBI:
+ log.info("*** Set transport protocol to CONTROL/BULK/INTERRUPT");
+ break;
+ case US_PR_BULK:
+ log.info("*** Set transport protocol to BULK ONLY");
+ this.transport = new USBStorageBulkTransport(this);
+ //((USBStorageBulkTransport)USBMassStorage.getTransport()).getMaxLun(usbDev);
+ break;
+ case US_PR_SCM_ATAPI:
+ log.info("*** Set transport protocol to SCM ATAPI");
+ default:
+ throw new DriverException("Transport protocol not implemented.");
+ }
+
+ USBEndPoint ep;
+ for (int i = 0; i < intf.getNumEndPoints(); i++) {
+ ep = this.usbInterface.getEndPoint(i);
+ // Is it a bulk endpoint ?
+ if ((ep.getDescriptor().getAttributes() & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK) {
+ // In or Out ?
+ if ((ep.getDescriptor().getEndPointAddress() & USB_DIR_IN) == 0) {
+ this.bulkInEndPoint = ep;
+ log.info("*** Set bulk in endpoint");
+ } else {
+ this.bulkOutEndPoint = ep;
+ log.info("*** Set bulk out endpoint");
+ }
+ } else if ((ep.getDescriptor().getAttributes() & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT) {
+ this.intrEndPoint = ep;
+ log.info("*** Set interrupt endpoint");
+ }
+ }
+
+
}
-
+
/**
* @return Returns the receiveBulkPipe.
*/
@@ -119,8 +169,8 @@
*
* @param dev
*/
-
+
/**
* @return Returns the bulkInEndPoint.
*/
@@ -207,4 +257,12 @@
this.subClass = subClass;
}
+ public USBDevice getDevice() {
+ return device;
+ }
+
+ public void setDevice(USBDevice device) {
+ this.device = device;
+ }
+
}
Modified: trunk/fs/src/driver/org/jnode/driver/block/usb/storage/USBStorageSCSIHostDriver.java
===================================================================
--- trunk/fs/src/driver/org/jnode/driver/block/usb/storage/USBStorageSCSIHostDriver.java 2008-05-13 14:13:57 UTC (rev 4096)
+++ trunk/fs/src/driver/org/jnode/driver/block/usb/storage/USBStorageSCSIHostDriver.java 2008-05-13 14:34:54 UTC (rev 4097)
@@ -38,8 +38,8 @@
import org.jnode.driver.bus.scsi.cdb.spc.CDBTestUnitReady;
import org.jnode.driver.bus.scsi.cdb.spc.InquiryData;
import org.jnode.driver.bus.usb.USBConfiguration;
+import org.jnode.driver.bus.usb.USBDataPipe;
import org.jnode.driver.bus.usb.USBDevice;
-import org.jnode.driver.bus.usb.USBEndPoint;
import org.jnode.driver.bus.usb.USBException;
import org.jnode.driver.bus.usb.USBPipeListener;
import org.jnode.driver.bus.usb.USBRequest;
@@ -55,7 +55,7 @@
private static final Logger log = Logger.getLogger(USBStorageSCSIHostDriver.class);
/** Storage specific device data */
- private USBStorageDeviceData USBMassStorage;
+ private USBStorageDeviceData storageDeviceData;
/** The SCSI device that i'm host of */
private USBStorageSCSIDevice scsiDevice;
@@ -69,62 +69,27 @@
@Override
protected void startDevice() throws DriverException {
try {
- final USBDevice usbDev = (USBDevice)getDevice();
- final USBConfiguration conf = usbDev.getConfiguration(0);
- usbDev.setConfiguration(conf);
- // Set transport protocol
- this.USBMassStorage = new USBStorageDeviceData(conf.getInterface(0).getDescriptor());
- switch (USBMassStorage.getProtocol()) {
- case US_PR_CBI:
- log.info("*** Set transport protocol to CONTROL/BULK/INTERRUPT");
- break;
- case US_PR_BULK:
- log.info("*** Set transport protocol to BULK ONLY");
- USBMassStorage.setTransport(new USBStorageBulkTransport(usbDev, USBMassStorage));
- ((USBStorageBulkTransport)USBMassStorage.getTransport()).getMaxLun(usbDev);
- break;
- case US_PR_SCM_ATAPI:
- log.info("*** Set transport protocol to SCM ATAPI");
- default:
- throw new DriverException("Transport protocol not implemented.");
- }
-
- USBEndPoint ep;
-
- for (int i = 0; i < conf.getInterface(0).getDescriptor().getNumEndPoints(); i++) {
- ep = conf.getInterface(0).getEndPoint(i);
- // Is it a bulk endpoint ?
- if ((ep.getDescriptor().getAttributes() & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK) {
- // In or Out ?
- if ((ep.getDescriptor().getEndPointAddress() & USB_DIR_IN) == 0) {
- USBMassStorage.setBulkInEndPoint(ep);
- log.info("*** Set bulk in endpoint");
- } else {
- USBMassStorage.setBulkOutEndPoint(ep);
- log.info("*** Set bulk out endpoint");
- }
- } else if ((ep.getDescriptor().getAttributes() & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT) {
- USBMassStorage.setIntrEndPoint(ep);
- log.info("*** Set interrupt endpoint");
- }
- }
-
- usbDev.registerAPI(SCSIHostControllerAPI.class, this);
+ USBDevice usbDevice = (USBDevice)getDevice();
+ USBConfiguration conf = usbDevice.getConfiguration(0);
+ usbDevice.setConfiguration(conf);
+ // Set usb mass storage informations.
+ this.storageDeviceData = new USBStorageDeviceData(usbDevice);
+ USBDataPipe pipe;
+ pipe = (USBDataPipe)this.storageDeviceData.getBulkOutEndPoint().getPipe();
+ pipe.addListener(this);
+ pipe.open();
+
+ pipe = (USBDataPipe)this.storageDeviceData.getBulkInEndPoint().getPipe();
+ pipe.addListener(this);
+ pipe.open();
+
+ usbDevice.registerAPI(SCSIHostControllerAPI.class, this);
final Bus hostBus = new USBStorageSCSIHostBus(getDevice());
scsiDevice = new USBStorageSCSIDevice(hostBus, "_sg");
- /*try {
- scsiDevice.testUnit();
- } catch (SCSIException ex) {
- throw new DriverException("Cannot TEST UNIT READY device", ex);
- } catch (TimeoutException ex) {
- throw new DriverException("Cannot TEST UNIT READY device : timeout", ex);
- } catch (InterruptedException ex) {
- throw new DriverException("Interrupted while TEST UNIT READY device", ex);
- }*/
+
// Execute INQUIRY
try {
scsiDevice.inquiry();
- scsiDevice.capacity();
} catch (SCSIException ex) {
throw new DriverException("Cannot INQUIRY device", ex);
} catch (TimeoutException ex) {
@@ -134,10 +99,10 @@
}
// Register the generic SCSI device.
try {
- final DeviceManager dm = usbDev.getManager();
+ final DeviceManager dm = usbDevice.getManager();
dm.rename(scsiDevice, "sg", true);
dm.register(scsiDevice);
- dm.rename(usbDev, SCSIHostControllerAPI.DEVICE_PREFIX, true);
+ dm.rename(usbDevice, SCSIHostControllerAPI.DEVICE_PREFIX, true);
} catch (DeviceAlreadyRegisteredException ex) {
throw new DriverException(ex);
}
@@ -189,8 +154,8 @@
public int executeCommand(CDB cdb, byte[] data, int dataOffset, long timeout)
throws SCSIException, TimeoutException, InterruptedException {
log.debug("*** execute command ***");
- ITransport t = USBMassStorage.getTransport();
- t.transport(cdb);
+ ITransport t = storageDeviceData.getTransport();
+ t.transport(cdb, timeout);
return 0;
}
@@ -211,17 +176,20 @@
InterruptedException {
log.info("*** INQUIRY ***");
final byte[] inqData = new byte[96];
- this.executeCommand(new CDBInquiry(inqData.length), inqData, 0, 50000);
+
+ ITransport t = storageDeviceData.getTransport();
+ t.transport(new CDBInquiry(inqData.length), 50000);
+
inquiryResult = new InquiryData(inqData);
log.debug("INQUIRY Data : " + inquiryResult.toString());
}
- protected final void capacity() throws SCSIException, TimeoutException, InterruptedException {
+ /*protected final void capacity() throws SCSIException, TimeoutException, InterruptedException {
log.info("*** Read capacity ***");
CapacityData cd = MMCUtils.readCapacity(this);
log.debug("Capacity Data : " + cd.toString());
- }
+ }*/
/**
* @see org.jnode.driver.bus.scsi.SCSIDeviceAPI#getDescriptor()
Modified: trunk/fs/src/driver/org/jnode/driver/block/usb/storage/scsi/USBStorageSCSIDriver.java
===================================================================
--- trunk/fs/src/driver/org/jnode/driver/block/usb/storage/scsi/USBStorageSCSIDriver.java 2008-05-13 14:13:57 UTC (rev 4096)
+++ trunk/fs/src/driver/org/jnode/driver/block/usb/storage/scsi/USBStorageSCSIDriver.java 2008-05-13 14:34:54 UTC (rev 4097)
@@ -35,13 +35,13 @@
import org.jnode.driver.block.FSBlockAlignmentSupport;
import org.jnode.driver.block.FSBlockDeviceAPI;
import org.jnode.driver.block.usb.storage.USBStorageConstants;
+import org.jnode.driver.block.usb.storage.USBStorageSCSIHostDriver.USBStorageSCSIDevice;
import org.jnode.driver.bus.scsi.SCSIDevice;
import org.jnode.driver.bus.scsi.SCSIDeviceAPI;
import org.jnode.driver.bus.scsi.SCSIException;
import org.jnode.driver.bus.scsi.SCSIHostControllerAPI;
import org.jnode.driver.bus.scsi.cdb.mmc.CapacityData;
import org.jnode.driver.bus.scsi.cdb.mmc.MMCUtils;
-import org.jnode.driver.bus.usb.USBConstants;
import org.jnode.driver.bus.usb.USBPipeListener;
import org.jnode.driver.bus.usb.USBRequest;
import org.jnode.partitions.PartitionTableEntry;
@@ -176,7 +176,7 @@
private void processChanged() throws IOException {
if (changed) {
this.capacity = null;
- final SCSIDevice dev = (SCSIDevice) getDevice();
+ final USBStorageSCSIDevice dev = (USBStorageSCSIDevice) getDevice();
try {
// Gets the capacity.
this.capacity = MMCUtils.readCapacity(dev);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|