fix(rawcli): identify false-positives on 15693/LF; retry 14a
With only a MIFARE Classic present, identify randomly reported ISO15693 (bogus UID) or "LF tag" — because a flaky-link 14a miss fell through to lenient checks: - 15693 accepted any `uid` even without `found`; now requires found AND a real E0-prefixed UID (a 14a miss leaves non-E0 garbage). - LF reported a tag whenever lf.search() returned its (always-truthy) sample-capture result; it can't confirm a tag without demod, so drop it from identify (reliable LF detection is a follow-up). - Retry the 14a scan (up to 3x) so a transient miss doesn't fall through. 3 tests (E0-gated 15693, bogus-UID + false-LF rejection). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -144,7 +144,13 @@ def identify(session, emit=None) -> dict:
|
||||
if dev is None:
|
||||
return {"found": False, "error": "no device connected"}
|
||||
|
||||
scan = _try(lambda: dev.hf.iso14a.scan(), {"found": False})
|
||||
# ISO 14443-A — retry: the scan can miss before it selects on a flaky link, and a miss must
|
||||
# not fall through to a bogus 15693/LF hit.
|
||||
scan = {"found": False}
|
||||
for _ in range(3):
|
||||
scan = _try(lambda: dev.hf.iso14a.scan(), {"found": False})
|
||||
if scan.get("found"):
|
||||
break
|
||||
if scan.get("found"):
|
||||
session.field, session.protocol = "hf", "hf14a"
|
||||
# always emit ANSI; the app's printer renders it (and strips it off a non-terminal)
|
||||
@@ -159,21 +165,17 @@ def identify(session, emit=None) -> dict:
|
||||
"transponder": session.transponder, "uid": scan.get("uid"),
|
||||
"version": version.hex() if version else None}
|
||||
|
||||
# ISO 15693 — require found AND a real E0-prefixed UID, else a 14a miss reads as a bogus tag.
|
||||
scan15 = _try(lambda: dev.hf.iso15.scan(), {"found": False})
|
||||
if scan15.get("found") or scan15.get("uid"):
|
||||
uid15 = scan15.get("uid")
|
||||
if scan15.get("found") and isinstance(uid15, str) and uid15.lower().startswith("e0"):
|
||||
session.field, session.protocol = "hf", "hf15"
|
||||
session.transponder = "ISO15693"
|
||||
return {"found": True, "field": "hf", "protocol": "15693",
|
||||
"transponder": "ISO15693", "uid": scan15.get("uid")}
|
||||
|
||||
lf = _try(lambda: dev.lf.search(), None)
|
||||
if lf:
|
||||
session.field, session.protocol = "lf", "lf"
|
||||
name = getattr(lf, "tag_type", None) or getattr(lf, "type", None) or "LF tag"
|
||||
session.transponder = str(name)
|
||||
return {"found": True, "field": "lf", "protocol": "lf",
|
||||
"transponder": session.transponder, "raw": lf}
|
||||
"transponder": "ISO15693", "uid": uid15}
|
||||
|
||||
# LF: lf.search() only captures samples — it can't confirm a tag without demod, so it would
|
||||
# always false-positive. Reliable LF identify (T55xx probe / EM4100 demod) is a follow-up.
|
||||
return {"found": False}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user