]> localhost Git - scsi2sd-util.git/commitdiff
Fix bugs with incorrect device enable bits, wrong quirks byte offsets
authorMichael McMaster <michael@codesrc.com>
Sat, 30 Jan 2021 12:51:54 +0000 (22:51 +1000)
committerMichael McMaster <michael@codesrc.com>
Sat, 30 Jan 2021 12:51:54 +0000 (22:51 +1000)
scsi2sd.io/src/main/java/com/codesrc/scsi2sd/io/V3FirmwareUsbDevice.java
scsi2sd.ui/src/main/java/com/codesrc/scsi2sd/model/DiskConfig.java

index 8b1b269bd3325d671515e8430966e33e68be8de3..99c8b3925ccdd0d35f584d268ea85eb521b64fa0 100644 (file)
@@ -186,28 +186,21 @@ public class V3FirmwareUsbDevice implements UsbDevice {
         System.out.println(HidPacketProtocol.uint8ToInt(response[0]));
 
         for (int i = 1; i + 4 < response.length; i += 5) {
-            // TODO OUTPUT THE TYPE AS WELL
+            int devType = HidPacketProtocol.uint8ToInt(response[i]);
+            String devTypeStr = "Unknown";
+            switch (devType) {
+                case 0: devTypeStr = "SD"; break;
+                case 1: devTypeStr = "SPIFLASH"; break;
+            }
+
             int capacity = (HidPacketProtocol.uint8ToInt(response[i + 1]) << 24) |
                     (HidPacketProtocol.uint8ToInt(response[i + 2]) << 16) |
                     (HidPacketProtocol.uint8ToInt(response[i + 3]) << 8) |
                     (HidPacketProtocol.uint8ToInt(response[i + 4]));
-            System.out.print("Found storage device with capacity: ");
+            System.out.print("Found storage device type " + devTypeStr + " with capacity: ");
             System.out.println(capacity * 512L);
         }
         /*
-        System.out.println("Writing a sector");
-        byte[] writeCmd = new byte[519];
-        writeCmd[0] = (byte)Commands.DEV_WRITE.ordinal();
-        writeCmd[1] = 1; // flash
-        writeCmd[2] = 0; // Sector number
-        writeCmd[3] = 0; // Sector number
-        writeCmd[4] = 0; // Sector number
-        writeCmd[5] = 1; // Sector number
-        for (var i = 0; i < 512; ++i) {
-            writeCmd[6+i] = HidPacketProtocol.intToUint8(255 - (i % 255));
-        }
-        response = protocolDevice.sendHIDPacket(writeCmd, 1);
-        
         System.out.println("Reading a sector");
         byte[] readCmd = {(byte)Commands.DEV_READ.ordinal(), (byte)1, (byte)0, (byte)0, (byte)0, (byte)1};
         byte[] readResponse = protocolDevice.sendHIDPacket(readCmd, 512);
index 83b4a8e0c29a6ede5f85b0ee4a9b7850a68ff257..cb0a587e80f2e1eef592c68b3d3d33e84a9dfd92 100644 (file)
@@ -57,6 +57,8 @@ public class DiskConfig {
 
     private Set<Quirks> quirks;
 
+    private int storageDevice;
+
     public DiskConfig(
             Type type,
             long sdSectorStart,
@@ -81,6 +83,7 @@ public class DiskConfig {
         this.revision = other.revision;
         this.serial = other.serial;
         this.quirks = new HashSet<>(other.quirks);
+        this.storageDevice = other.storageDevice;
     }
 
     public DiskConfig(
@@ -107,6 +110,8 @@ public class DiskConfig {
         this.serial = this.pad("12345678", 16);
 
         this.quirks = new HashSet<Quirks>();
+
+        this.storageDevice = 0;
     }
 
     public DiskConfig(byte[] in) {
@@ -131,14 +136,16 @@ public class DiskConfig {
         this.revision = new String(in, 42, 4, StandardCharsets.US_ASCII);
         this.serial = new String(in, 46, 16, StandardCharsets.US_ASCII);
 
-        this.quirks = Quirks.fromBitmask(BitUtil.letohs(in, 52));
+        this.quirks = Quirks.fromBitmask(BitUtil.letohs(in, 62));
+
+        storageDevice = BitUtil.uint8ToInt(in[64]);
     }
 
 
     public byte[] asBytes() {
         byte[] out = new byte[LENGTH];
 
-        out[0] = BitUtil.intToUint8((this.scsiId & 0x07) | (this.active ? 0 : 0x80));
+        out[0] = BitUtil.intToUint8((this.scsiId & 0x07) | (this.active ? 0x80 : 0));
 
         out[1] = BitUtil.intToUint8(this.deviceType.getValue());
         out[2] = 0; // flagsDeprecated
@@ -169,8 +176,10 @@ public class DiskConfig {
         System.arraycopy(this.serial.getBytes(StandardCharsets.US_ASCII), 0, out, 46, 16);
 
         var quirksMask = BitUtil.getMask(this.quirks);
-        out[52] = BitUtil.longToUint8(quirksMask);
-        out[53] = BitUtil.longToUint8(quirksMask >> 8);
+        out[62] = BitUtil.longToUint8(quirksMask);
+        out[63] = BitUtil.longToUint8(quirksMask >> 8);
+
+        out[64] = BitUtil.intToUint8((this.scsiId & 0x07) == 1 ? 1 : 0);
 
         return out;
     }