Quellcode durchsuchen

Self-heal enrollment when the sensor's calibration is stale

When the sensor resets its calibration/ownership state it also drops the
enrollment template.  The saved CalibrationData.blob then no longer
matches the device: capture hangs at IOCTL_BIOMETRIC_CAPTURE_DATA without
ever reporting a SensorStatus, so GNOME Settings never advances, the
client cancels and the user is left with no enrolled print (observed
2026-10-24 after the sensor lost its record).

Check the pre-enroll delete.exe payload instead of only its exit status:
00 means no record.  In that case move CalibrationData.blob and
PairingData.blob aside as .stale-<epoch> and let enroll.exe recalibrate
and save a fresh blob, so recovery is automatic on the next enrollment.

- also treat a missing/error delete payload as a failed pre-delete instead
  of silently clearing the reported finger list
- refresh work/artifacts/sandbox/CalibrationData.blob with the newly
  generated blob so restores do not ship the stale one
- document the failure mode and the automatic recovery in the README

Verified: 8 enrollment stages + commit, then fprintd-verify -> verify-match.
Johannes Zellner vor 3 Wochen
Ursprung
Commit
39b3fbb38c
3 geänderte Dateien mit 61 neuen und 5 gelöschten Zeilen
  1. 12 0
      README.md
  2. BIN
      work/artifacts/sandbox/CalibrationData.blob
  3. 49 5
      work/fprintd-shim/fprintd-shim.py

+ 12 - 0
README.md

@@ -377,6 +377,18 @@ nothing.  The shim therefore deletes any existing record first (the delete
 ioctl does not reset the device) so every enrollment is a fresh write,
 which has been reliable.
 
+Known caveat — stale calibration after the sensor loses its record: when the
+sensor's calibration/ownership state is reset (unexpected power loss, driver
+reset, firmware state change), the template disappears and the saved
+`CalibrationData.blob` no longer matches.  Capture then hangs forever at
+"about to IOCTL_BIOMETRIC_CAPTURE_DATA" without a `SensorStatus`, so Settings
+enrollment never progresses and the client eventually cancels (leaving no
+print at all).  Since 2026-10-24 the shim checks the pre-enroll `delete.exe`
+status: a `00` payload means "no record", so it moves `CalibrationData.blob` /
+`PairingData.blob` aside as `.stale-<epoch>` before enrolling.  `enroll.exe`
+then recalibrates and saves a fresh blob, so recovery is automatic on the
+next enrollment attempt (the moved files are kept for diagnosis).
+
 ### Multi-finger support — plan for the next session
 
 Today the sensor holds exactly one record because the sandbox harness

BIN
work/artifacts/sandbox/CalibrationData.blob


+ 49 - 5
work/fprintd-shim/fprintd-shim.py

@@ -553,6 +553,29 @@ class ShimDevice:
 
     # ------------------------------------------------------ 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):
         with self.lock:
             running = self.enrolling
@@ -645,12 +668,33 @@ class ShimDevice:
             if self.enrolled_fingers(user):
                 log.info('enroll: existing record for %s, deleting it first',
                          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(
-                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:
                 # the device has no record now: report that honestly even if
                 # the enrollment is aborted later on