X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=client%2FGoodFETMAXUSB.py;h=db220b22a6e3cf3e6a9635c2417bfeeb72083585;hp=8f05d43d7ec6c60ea90e0e0f727d0ccb0b1dc199;hb=9a25dff298eb442c289d193e721727fd40a56e5d;hpb=2f6dc7ff6da98e249560706dd14a8cda9ad23e51 diff --git a/client/GoodFETMAXUSB.py b/client/GoodFETMAXUSB.py index 8f05d43..db220b2 100644 --- a/client/GoodFETMAXUSB.py +++ b/client/GoodFETMAXUSB.py @@ -90,7 +90,7 @@ GD_STRING =0x03 # Get device descriptor: String GD_HID =0x21 # Get descriptor: HID GD_REPORT =0x22 # Get descriptor: Report -# SETUP packet offsets +# SETUP packet header offsets bmRequestType =0 bRequest =1 wValueL =2 @@ -203,6 +203,16 @@ bmHXFRDNIRQ =0x80 class GoodFETMAXUSB(GoodFET): MAXUSBAPP=0x40; + + def setup2str(self,SUD): + """Converts the header of a setup packet to a string.""" + return "bmRequestType=0x%02x, bRequest=0x%02x, wValue=0x%04x, wIndex=0x%04x, wLength=0x%04x" % ( + ord(SUD[0]), ord(SUD[1]), + ord(SUD[2])+(ord(SUD[3])<<8), + ord(SUD[4])+(ord(SUD[5])<<8), + ord(SUD[6])+(ord(SUD[7])<<8) + ); + def MAXUSBsetup(self): """Move the FET into the MAXUSB application.""" self.writecmd(self.MAXUSBAPP,0x10,0,self.data); #MAXUSB/SETUP @@ -250,6 +260,16 @@ class GoodFETMAXUSB(GoodFET): ashex=ashex+(" %02x"%ord(foo)); print "GET %02x==%s" % (reg,ashex); return toret; + def readbytesAS(self,reg,length): + """Peek some bytes from a register, acking prior transfer.""" + data=[(reg<<3)|1]+range(0,length); + self.writecmd(self.MAXUSBAPP,0x00,len(data),data); + toret=self.data[1:len(self.data)]; + ashex=""; + for foo in toret: + ashex=ashex+(" %02x"%ord(foo)); + print "GET %02x==%s" % (reg,ashex); + return toret; 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 @@ -318,9 +338,11 @@ class GoodFETMAXUSB(GoodFET): #Very innefficient, move this to C if performance is needed. for j in range(0,pktsize): self.xfrdata=self.xfrdata+[self.rreg(rRCVFIFO)]; + xfrsize=self.xfrdata[0]; self.wreg(rHIRQ,bmRCVDAVIRQ); #Clear IRQ xfrlen=xfrlen+pktsize; #Add byte count to total transfer length. + print "%i / %i" % (xfrlen,xfrsize) #Packet is complete if: # 1. The device sent a short packet,