Patches to Mass Storage emulation in MAXUSB.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Tue, 6 Nov 2012 22:31:46 +0000 (22:31 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Tue, 6 Nov 2012 22:31:46 +0000 (22:31 +0000)
git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@1322 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

client/GoodFETMAXUSB.py
client/goodfet.maxusbmass

index b35ba51..ede1026 100644 (file)
@@ -299,6 +299,27 @@ class GoodFETMAXUSB(GoodFET):
             ashex=ashex+(" %02x"%ord(foo));
         if self.usbverbose: print "GETAS %02x==%s" % (reg,ashex);
         return toret;
             ashex=ashex+(" %02x"%ord(foo));
         if self.usbverbose: print "GETAS %02x==%s" % (reg,ashex);
         return toret;
+    def fifo_ep3in_tx(self,data):
+        """Sends the data out of EP3 in 64-byte chunks."""
+        #Wait for the buffer to be free before starting.
+        while not(self.rreg(rEPIRQ)&bmIN3BAVIRQ): pass;
+        
+        count=len(data);
+        pos=0;
+        while count>0:
+            #Send 64-byte chunks or the remainder.
+            c=min(count,64);
+            self.writebytes(rEP3INFIFO,
+                            data[pos:pos+c]);
+            self.wregAS(rEP3INBC,c);
+            count=count-c;
+            pos=pos+c;
+            
+            #Wait for the buffer to be free before continuing.
+            while not(self.rreg(rEPIRQ)&bmIN3BAVIRQ): pass;
+            
+        return;
+        
     def ctl_write_nd(self,request):
         """Control Write with no data stage.  Assumes PERADDR is set
         and the SUDFIFO contains the 8 setup bytes.  Returns with
     def ctl_write_nd(self,request):
         """Control Write with no data stage.  Assumes PERADDR is set
         and the SUDFIFO contains the 8 setup bytes.  Returns with
index da42c90..de25c6e 100755 (executable)
@@ -11,6 +11,13 @@ import time;
 
 from GoodFETMAXUSB import *;
 
 
 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."""
     
 class GoodFETMAXUSBMass(GoodFETMAXUSBDevice):
     """This emulates a USB Mass Storage device."""
     
@@ -309,11 +316,18 @@ class GoodFETMAXUSBMass(GoodFETMAXUSBDevice):
             status=0x00;
         elif verb==0x1A: #Mode Sense (6)
             # I should probably send six bytes here.
             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];
             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.
         elif verb==0x23: #Read Format Capacity
             response=[
                 0x00, 0,0x00,0x08, #Capacity list length.
@@ -370,8 +384,9 @@ class GoodFETMAXUSBMass(GoodFETMAXUSBDevice):
             print "ERROR: Unknown SCSI command block verb %02x." % verb;
             status=1; #Command Failed
             if dtlen>0:
             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.
         cbw=self.lastCBW;
         
         #Now we need to send the CSW.