Beispiel #1
0
def cmd_01(dev):
    import inspect
    
    if 1:
        return cmd_01r(dev)
    
    buff = cmd_01r(dev, validate=False)
    if 0:
        where(2)
        hexdump(buff, indent='  ')
    else:
        print 'cmd_01'
    
    state = ord(buff[0x13])
    print '  State: 0x%02X' % state
    print '  0x15: 0x%02X' % ord(buff[0x15])
    print '  0x16: 0x%02X' % ord(buff[0x16])
    print '  0x17: 0x%02X' % ord(buff[0x17])

    return buff
Beispiel #2
0
def bulk86(dev, target=None, donef=None, prefix=None):
    bulkRead, _bulkWrite, _controlRead, _controlWrite = usb_wraps(dev)
    
    dbg = bulk86_dbg
    
    if dbg:
        print
        print 'bulk86'
        where(2)
        try:
            where(3)
        except IndexError:
            pass
    
    # AFAIK certain packets have no way of knowing done
    # other than knowing in advance how many bytes you should expect
    # Strange since there are continue markers
    if donef is None and target is not None:
        def donef(buff):
            return len(buff) == target
    
    '''
    Ex: need to read 4096 bytes
    Max buffer packet size is 512 bytes
    but for some reason only uses up to 256 bytes of real data
    + 3 framing bytes and 0 fills the rest to form 512 byte transfer
    So to transfer the data 
    '''
    def nxt_buff():
        if dbg:
            print '  nxt_buff: reading'
        p = bulkRead(0x86, 0x0200)
        if dbg:
            hexdump(p, label='  nxt_buff', indent='    ')
        #print str2hex(p)
        prefix_this = ord(p[0])
        size = (ord(p[-1]) << 8) | ord(p[-2])
        '''
        if size != len(p) - 3:
            if truncate and size < len(p) - 3:
                return prefix_this, p[1:1 + size], suffix_this
            else:
                print 'Truncate: %s' % truncate
                print size, len(p) - 3, len(p)
                hexdump(p)
                raise Exception("Bad length (enable truncation?)")
        return prefix_this, p[1:-2], suffix_this
        '''
        # No harm seen in always truncating
        return prefix_this, p[1:1 + size]

    buff = ''
    while True:
        if donef and donef(buff):
            break
            
        # Test on "packet 152/153" (0x64 byte response)
        # gave 19/1010 splits => 1.9% of split
        # Ran some torture tests looping on this to verify this logic is okay
        if dbg and buff:
            print '  NOTE: split packet.  Have %d / %s bytes' % (len(buff), target)
            hexdump(buff, indent='    ')
            splits[0] += 1
        try:
            # Ignore suffix continue until we have a reason to care
            if dbg:
                tstart = time.time()
            prefix_this, buff_this = nxt_buff()
            if dbg:
                tend = time.time()
                print '  time: %0.3f' % (tend - tstart,)
            buff += buff_this
            
            if prefix is not None:
                if prefix != prefix_this:
                    hexdump(buff_this)
                    raise BadPrefix('Wanted prefix 0x%02X, got 0x%02X' % (prefix, prefix_this))
            elif prefix_this == 0x08:
                pass
            else:
                raise BadPrefix('Unknown prefix 0x%02X' % prefix_this)
            
            if donef and not donef(buff):
                if dbg:
                    print '  continue: not done'
                continue
            if dbg:
                print '  break: no special markers'
            break
        
        # FIXME: temp
        except libusb1.USBError:
            #if prefix is None:
            #    return buff
            raise
    #print 'Done w/ buff len %d' % len(buff)
    if target is not None and len(buff) != target:
        hexdump(buff, label='Wrong size', indent='  ')
        prefix_this, buff_this = nxt_buff()
        raise Exception('Target len: buff %d != target %d' % (len(buff), target))
    if dbg:
        hexdump(buff, label='  ret', indent='    ')
        print
    return buff
Beispiel #3
0
def atomic_probe(dev):
    where(2)
    cmd_01(dev)