def __init__(self): self.is_secondary = False self.pin = None self.secret = None self.is_empty = None self.magic_value = PA_MAGIC_V2 if version.has_608 else PA_MAGIC_V1 self.delay_achieved = 0 # so far, how much time wasted? self.delay_required = 0 # how much will be needed? self.num_fails = 0 # for UI: number of fails PINs self.attempts_left = 0 # ignore in mk1/2 case, only valid for mk3 self.state_flags = 0 # useful readback self.private_state = 0 # opaque data, but preserve self.cached_main_pin = bytearray(32) assert MAX_PIN_LEN == 32 # update FMT otherwise assert ustruct.calcsize(PIN_ATTEMPT_FMT_V1) == PIN_ATTEMPT_SIZE_V1, \ ustruct.calcsize(PIN_ATTEMPT_FMT) assert ustruct.calcsize(PIN_ATTEMPT_FMT_V2_ADDITIONS ) == PIN_ATTEMPT_SIZE - PIN_ATTEMPT_SIZE_V1 self.buf = bytearray( PIN_ATTEMPT_SIZE if version.has_608 else PIN_ATTEMPT_SIZE_V1) # check for bricked system early import callgate if callgate.get_is_bricked(): # die right away if it's not going to work callgate.enter_dfu(3)
async def usb_keypad_emu(): # Take keypresses on USB virtual serial port (when not in REPL mode) # and converts them into keypad events. Super handy for UX testing/dev. # # IMPORTANT: # - code is **not** used in real product, but left here for devs to use # - this code isn't even called; unless you add code to do so. # u = pyb.USB_VCP() while 1: await sleep_ms(100) while u.isconnected() and u.any(): from main import numpad k = u.read(3).decode() remap = { '\r': 'y', '\x1b': 'x', 'q': 'x', '\x1b[A': '5', '\x1b[B': '8', '\x1b[C': '9', '\x1b[D': '7' } if k in remap: k = remap[k] if k in '\x04': # ^D # warm reset from machine import soft_reset soft_reset() if k == 'U': # enter DFU #from machine import bootloader #bootloader() import callgate callgate.enter_dfu() if k in '0123456789xy': numpad.inject(k) else: print('? %r' % k)
def roundtrip(self, method_num, **kws): self.marshal(self.buf, **kws) #print("> tx: %s" % b2a_hex(buf)) err = ckcc.gate(18, self.buf, method_num) #print("[%d] rx: %s" % (err, b2a_hex(self.buf))) if err <= -100: #print("[%d] req: %s" % (err, b2a_hex(self.buf))) if err == EPIN_I_AM_BRICK: # don't try to continue! enter_dfu(3) raise BootloaderError(PA_ERROR_CODES[err], err) elif err: raise RuntimeError(err) return self.unmarshal(self.buf)
def __init__(self): self.is_secondary = False self.pin = None self.secret = None self.is_empty = None self.delay_achieved = 0 # so far, how much time wasted? self.delay_required = 0 # how much will be needed? self.num_fails = 0 # for UI: number of fails PINs self.attempt_target = 0 # counter number from chip self.state_flags = 0 # useful readback self.private_state = 0 # opaque data, but preserve assert MAX_PIN_LEN == 32 # update FMT otherwise assert ustruct.calcsize( PIN_ATTEMPT_FMT) == PIN_ATTEMPT_SIZE, ustruct.calcsize( PIN_ATTEMPT_FMT) self.buf = bytearray(PIN_ATTEMPT_SIZE) # check for bricked system early import callgate if callgate.get_is_bricked(): # die right away if it's not going to work callgate.enter_dfu(3)
async def usb_keypad_emu(): # Take keypresses on USB virtual serial port (when not in REPL mode) # and converts them into keypad events. Super handy for UX testing/dev. # # IMPORTANT: # - code is **not** used in real product, but left here for devs to use # - this code isn't even called; unless you add code to do so, see ../stm32/my_lib_boot2.py # u = pyb.USB_VCP() while 1: await sleep_ms(100) while u.isconnected() and u.any(): from main import numpad k = u.read(3).decode() remap = { '\r': 'y', '\x1b': 'x', 'q': 'x', '\x1b[A': '5', '\x1b[B': '8', '\x1b[C': '9', '\x1b[D': '7' } if k in remap: k = remap[k] if k in '\x04': # ^D # warm reset from machine import soft_reset soft_reset() if k == 'd': numpad.debug = (numpad.debug + 1) % 3 continue if k == 'n': if numpad.disabled: numpad.start() else: numpad.stop() print("npdis = %d" % numpad.disabled) continue if k == 'r': numpad.trigger_baseline = True continue if k == 's': numpad.sensitivity = (numpad.sensitivity + 1) % 5 print("sensi = %d" % numpad.sensitivity) continue if k == 'U': # enter DFU import callgate callgate.enter_dfu() # not reached if k == 't': ckcc.vcp_enabled(True) print("Repl enabled") continue if k == 'm': import gc print("Memory: %d" % gc.mem_free()) continue if k in '0123456789xy': numpad.inject(k) else: print('? %r' % k)
async def start_dfu(*a): from callgate import enter_dfu enter_dfu(0)
async def usb_keypad_emu(): # Take keypresses on USB virtual serial port (when not in REPL mode) # and converts them into keypad events. Super handy for UX testing/dev. # # IMPORTANT: # - code is **not** used in real product, but left here for devs to use # - this code isn't even called; unless you add code to do so, see ../stm32/my_lib_boot2.py # from ux import the_ux from menu import MenuSystem from seed import WordNestMenu u = pyb.USB_VCP() remap = { '\r': 'y', '\x1b': 'x', '\x1b[A': '5', '\x1b[B': '8', '\x1b[C': '9', '\x1b[D': '7' } while 1: await sleep_ms(100) while u.isconnected() and u.any(): from main import numpad k = u.read(3).decode() if k in '\x04': # ^D # warm reset from machine import soft_reset soft_reset() if 0: if k == 'd': numpad.debug = (numpad.debug + 1) % 3 continue if k == 'n': if numpad.disabled: numpad.start() else: numpad.stop() print("npdis = %d" % numpad.disabled) continue if k == 'U': # enter DFU import callgate callgate.enter_dfu() # not reached if k == 'T': ckcc.vcp_enabled(True) print("Repl enabled") continue if k == 'M': import gc print("Memory: %d" % gc.mem_free()) continue # word menus: shortcut for first letter top = the_ux.top_of_stack() if top and isinstance(top, WordNestMenu) and len(top.items) > 6: pos = min(len(i.label) for i in top.items) if pos >= 2: for n, it in enumerate(top.items): if it.label[pos-2] == k: top.goto_idx(n) top.show() k = None break if k is None: continue if k in remap: k = remap[k] if k in '0123456789xy': numpad.inject(k) continue print('? %r' % k)