from tls97 import tls from usb97 import usb from db97 import db, subtype_to_string from time import sleep from struct import pack, unpack from binascii import hexlify, unhexlify from util import assert_status, unhex from hw_tables import dev_info_lookup from blobs import identify_prg, enroll_prg def glow_start_scan(): cmd=unhexlify('3920bf0200ffff0000019900200000000099990000000000000000000000000020000000000000000000000000ffff000000990020000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000') assert_status(tls.app(cmd)) def glow_end_enroll(): cmd=unhexlify('39f4010000f401000001ff002000000000ffff0000000000000000000000000020000000000000000000000000f401000000ff0020000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000') assert_status(tls.app(cmd)) def start_scan(cmd): assert_status(tls.app(cmd)) def cancel_capture(): usb.queue.put(b'') #sleep(0.2) #rsp=tls.app(b'\x04') #assert_status(rsp) usb.read_82() def wait_for_finger(): while True: b=usb.wait_int() if len(b) == 0: raise Exception('Cancelled') if b[0] == 2: break def get_prg_status(): return tls.app(unhexlify('5100000000')) def wait_till_finished(): while True: status = get_prg_status() if status[0] in [0, 7]: break sleep(0.2) def stop_prg(): return tls.app(unhexlify('5100200000')) def capture(prg): usb.purge_int_queue() start_scan(prg) b=usb.wait_int() if b[0] != 0: raise Exception('Unexpected interrupt type %s' % hexlify(b).decode()) try: wait_for_finger() wait_till_finished() finally: res=stop_prg() while True: b=usb.wait_int() if b[0] != 3: raise Exception('Unexpected interrupt type %s' % hexlify(b).decode()) if b[1] == 0x43: break assert_status(res) res = res[2:] l, res = res[:4], res[4:] l, = unpack(' 0: (t, l), x = unpack(' 1: raise Exception('Expected only one child record for finger') print('Recognised finger %02x (%s) from user %s' % (subtype, subtype_to_string(subtype), repr(usr.identity))) print('Template hash: %s' % hexlify(hsh).decode()) if len(finger_record.children) > 0: if finger_record.children[0]['type'] != 8: raise Exception('Expected data blob as a finger child') blob_id = finger_record.children[0]['dbid'] blob = db.get_record_value(blob_id).value tag, sz = unpack('