fix(lf): per-protocol identify label (native HID/AWID/FDX-B no longer KeyError)
identify_lf built its label from emitted['id_hex'], which only EM4100 provides — a native HID/AWID/FDX-B tag (no T5577 config) would KeyError. Add credential_label() to format each decoder's own fields: "HID Prox H10301 FC.. Card..", "AWID-26 FC.. Card..", "FDX-B 124-000000000555 (animal)", "EM4100 <id>". Tests for native FDX-B + HID labels. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -22,6 +22,20 @@ _DECODERS = (
|
||||
)
|
||||
|
||||
|
||||
def credential_label(c: dict) -> str:
|
||||
"""One-line name for a decoded credential, per protocol (each decoder returns its own fields)."""
|
||||
p = c.get("protocol", "?")
|
||||
if p == "EM4100":
|
||||
return f"EM4100 {c['id_hex']}"
|
||||
if p == "HID Prox":
|
||||
return f"HID Prox {c['format']} FC {c['facility_code']} Card {c['card_number']}"
|
||||
if p == "AWID":
|
||||
return f"{c['format']} FC {c['facility_code']} Card {c['card_number']}"
|
||||
if p == "FDX-B":
|
||||
return f"FDX-B {c['id']}" + (" (animal)" if c.get("animal") else "")
|
||||
return p
|
||||
|
||||
|
||||
def demod_samples(samples) -> dict | None:
|
||||
"""Decode a raw LF envelope to a credential by trying each protocol demod in turn.
|
||||
|
||||
@@ -87,13 +101,13 @@ def identify_lf(device, emit=None) -> dict | None:
|
||||
f"({config['modulation']}, RF/{config['data_bit_rate']}, {config['max_block']} blocks)"
|
||||
f" -> {emulating}")
|
||||
if emitted is not None:
|
||||
emit(f" emitted: {emitted['protocol']} id {emitted['id_hex']}")
|
||||
emit(f" emitted: {credential_label(emitted)}")
|
||||
|
||||
# label: prefer the physical chip + what it emulates; else the emitted credential
|
||||
if chip:
|
||||
label = f"{chip} ({emulating})"
|
||||
else:
|
||||
label = f"{emitted['protocol']} {emitted['id_hex']}"
|
||||
label = credential_label(emitted)
|
||||
|
||||
return {
|
||||
"found": True,
|
||||
|
||||
Reference in New Issue
Block a user