|
@@ -553,6 +553,29 @@ class ShimDevice:
|
|
|
|
|
|
|
|
# ------------------------------------------------------ enroll ops
|
|
# ------------------------------------------------------ enroll ops
|
|
|
|
|
|
|
|
|
|
+ def _rotate_calibration(self):
|
|
|
|
|
+ """Move saved calibration aside so the driver recalibrates.
|
|
|
|
|
+
|
|
|
|
|
+ The sensor drops its enrollment record when its calibration/ownership
|
|
|
|
|
+ state is reset (unexpected power loss, driver reset, firmware state
|
|
|
|
|
+ change). The saved blob then no longer matches the device and the
|
|
|
|
|
+ capture ioctl waits forever without ever reporting a finger, so
|
|
|
|
|
+ enrollment appears to hang. With no blob present enroll.exe performs
|
|
|
|
|
+ a fresh calibration and saves a new one.
|
|
|
|
|
+ """
|
|
|
|
|
+ for name in ('CalibrationData.blob', 'PairingData.blob'):
|
|
|
|
|
+ path = os.path.join(SANDBOX, name)
|
|
|
|
|
+ if not os.path.exists(path):
|
|
|
|
|
+ continue
|
|
|
|
|
+ backup = f'{path}.stale-{int(time.time())}'
|
|
|
|
|
+ try:
|
|
|
|
|
+ os.replace(path, backup)
|
|
|
|
|
+ except OSError as e:
|
|
|
|
|
+ log.warning('enroll: cannot move %s aside: %s', path, e)
|
|
|
|
|
+ else:
|
|
|
|
|
+ log.info('enroll: moved %s aside (%s); forcing recalibration',
|
|
|
|
|
+ name, os.path.basename(backup))
|
|
|
|
|
+
|
|
|
def _stop_enroll(self, quiet=False):
|
|
def _stop_enroll(self, quiet=False):
|
|
|
with self.lock:
|
|
with self.lock:
|
|
|
running = self.enrolling
|
|
running = self.enrolling
|
|
@@ -645,12 +668,33 @@ class ShimDevice:
|
|
|
if self.enrolled_fingers(user):
|
|
if self.enrolled_fingers(user):
|
|
|
log.info('enroll: existing record for %s, deleting it first',
|
|
log.info('enroll: existing record for %s, deleting it first',
|
|
|
user)
|
|
user)
|
|
|
|
|
+ del_st = {'payload': None}
|
|
|
|
|
+
|
|
|
|
|
+ def on_delete_line(line):
|
|
|
|
|
+ if del_st['payload'] is None and line.startswith('Got back 0x'):
|
|
|
|
|
+ hexpart = line.split(':', 1)[1].strip() if ':' in line else ''
|
|
|
|
|
+ del_st['payload'] = hexpart.lower()
|
|
|
|
|
+
|
|
|
dstatus, dcode = self._run_harness(
|
|
dstatus, dcode = self._run_harness(
|
|
|
- DELETE_EXE, DELETE_TIMEOUT, self.enroll_cancel, None, slot,
|
|
|
|
|
- expect_markers=('about to 442034',))
|
|
|
|
|
- d_ok = (dstatus == 'eof' and dcode == 0)
|
|
|
|
|
- log.info('enroll: pre-delete %s (harness %s rc=%s)',
|
|
|
|
|
- 'ok' if d_ok else 'FAILED', dstatus, dcode)
|
|
|
|
|
|
|
+ DELETE_EXE, DELETE_TIMEOUT, self.enroll_cancel,
|
|
|
|
|
+ on_delete_line, slot, expect_markers=('about to 442034',))
|
|
|
|
|
+ payload = del_st['payload'] or ''
|
|
|
|
|
+ d_deleted = payload.startswith('01')
|
|
|
|
|
+ d_none = payload.startswith('00')
|
|
|
|
|
+ d_ok = (dstatus == 'eof' and dcode == 0 and (d_deleted or d_none))
|
|
|
|
|
+ if d_deleted:
|
|
|
|
|
+ d_text = 'deleted existing record'
|
|
|
|
|
+ elif d_none:
|
|
|
|
|
+ d_text = 'no record present'
|
|
|
|
|
+ else:
|
|
|
|
|
+ d_text = 'FAILED'
|
|
|
|
|
+ log.info('enroll: pre-delete %s (harness %s rc=%s payload=%s)',
|
|
|
|
|
+ d_text, dstatus, dcode, payload or '-')
|
|
|
|
|
+ if d_none:
|
|
|
|
|
+ # No template on the sensor means its calibration/ownership
|
|
|
|
|
+ # state was reset: the saved blob is stale and capture would
|
|
|
|
|
+ # hang forever. Force a fresh calibration during this enrol.
|
|
|
|
|
+ self._rotate_calibration()
|
|
|
if d_ok:
|
|
if d_ok:
|
|
|
# the device has no record now: report that honestly even if
|
|
# the device has no record now: report that honestly even if
|
|
|
# the enrollment is aborted later on
|
|
# the enrollment is aborted later on
|