Added empty handles for ejecting a disk and padding the INQUIRY.
[goodfet] / client / goodfet.maxusbmass
index 0882642..d0562fa 100755 (executable)
@@ -11,6 +11,13 @@ import time;
 
 from GoodFETMAXUSB import *;
 
+def zeros(length):
+    """Returns a list of zeroes of the specified length."""
+    l=range(0,length);
+    for foo in l:
+        l[foo]=0;
+    return l;
+
 class GoodFETMAXUSBMass(GoodFETMAXUSBDevice):
     """This emulates a USB Mass Storage device."""
     
@@ -277,7 +284,7 @@ class GoodFETMAXUSBMass(GoodFETMAXUSBDevice):
             #print "Responding to CB inquiry.";
             response=[
                 0x00, # 00 for Direct, 1F for "no floppy"
-                0x80, # make 0x80 for removable media
+                0x80, # make 0x80 for removable media, 0x00 for fixed
                 0x00, # Version
                 0x01, # Response Data Format
                 0x1f, #Additional length.
@@ -290,6 +297,8 @@ class GoodFETMAXUSBMass(GoodFETMAXUSBDevice):
                 ord('0'),ord('.'),ord('0'),ord('1')]
             #print "Sending %i byte reply to %i byte query." % (
             #        len(response),dtlen);
+            while len(response)<dtlen:
+                response=response+[0];
             #while not(self.rreg(rEPIRQ)&bmIN3BAVIRQ):
             #    #Wait for the packet to complete before sending the next.
             #    print "Waiting to complete inquiry."
@@ -309,15 +318,22 @@ class GoodFETMAXUSBMass(GoodFETMAXUSBDevice):
             status=0x00;
         elif verb==0x1A: #Mode Sense (6)
             # I should probably send six bytes here.
+            print "Mode Sense (6) requesting %i byte Page Code %02x" % (
+                dtlen,ord(cb[2])&0x3F);
+            #This is completely wrong.
             response=[0x12,0,0,0, 0,0,0,0x1C];
-            self.writebytes(rEP3INFIFO,
-                            response);
-            self.wregAS(rEP3INBC,
-                        len(response));
+            self.fifo_ep3in_tx(response);
+        elif verb==0x5A: #Mode Sense (10)
+            # I should probably send ten bytes here.
+            print "Mode Sense (10) requesting %i byte Page Code %02x" % (
+                dtlen,ord(cb[2])&0x3F);
+            #This is completely wrong.
+            response=[0x12,0x00,0,0, 0,0,0,0x1C]
+            self.fifo_ep3in_tx(response);
         elif verb==0x23: #Read Format Capacity
             response=[
                 0x00, 0,0x00,0x08, #Capacity list length.
-                0,0x00,x10,0x00,   # Number of sectors, implying 10MB.
+                0,0x00,0x10,0x00,   # Number of sectors, implying 10MB.
                 0x01,0x00,            #reserved/desciptor code.
                 0x02,0x00             # 512 bytes/sector.  Why is this twice?
                 ];
@@ -365,13 +381,18 @@ class GoodFETMAXUSBMass(GoodFETMAXUSBDevice):
             #sys.exit();
         elif verb==0x2A: #WRITE SECTOR
             print "Haven't implemented WRITE SECTOR.";
-            sys.exit();
+            #sys.exit();
+        elif verb==0x1B: #EJECT/RETRACT DISK
+            print "Haven't implemented SCSI Start Stop Unit Command (1B)";
+            print "https://en.wikipedia.org/wiki/SCSI_Start_Stop_Unit_Command";
+            #sys.exit();
         else:
             print "ERROR: Unknown SCSI command block verb %02x." % verb;
             status=1; #Command Failed
             if dtlen>0:
-                print "Perhaps I should send %i bytes of dummy data here." % dtlen;
-            sys.exit(1);
+                print "Sending %i bytes of dummy data here." % dtlen;
+                self.fifo_ep3in_tx(zeros(dtlen));
+            #sys.exit(1);
         cbw=self.lastCBW;
         
         #Now we need to send the CSW.
@@ -446,6 +467,7 @@ class GoodFETMAXUSBMassFile(GoodFETMAXUSBMass):
                                        self.datafilelen%512);
             sys.exit();
         return self.datafilelen/512-1;
+
 if(len(sys.argv)==1):
     print "Usage: %s disk.img\n" % sys.argv[0];
     sys.exit();