From d18d1c671342a8f7bdcca30db1cb663ab1eecdb5 Mon Sep 17 00:00:00 2001 From: munzzyy Date: Fri, 10 Jul 2026 14:16:54 -0500 Subject: [PATCH] Fix IR56 wiegand decode leaking header sentinel bit into facility code --- CHANGELOG.md | 1 + client/src/wiegand_formats.c | 4 +++- tools/pm3_tests.sh | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a0a18f0f..c9417b1e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac ## [unreleased][unreleased] +- Fixed `wiegand decode` returning facility code 16777339 instead of the encoded value for the IR56 (Inner Range 56-bit) format by masking the header sentinel bit off the facility code (@munzzyy) - Fixed `lf em 4x05 dump` writing byte-swapped (corrupted) block data to the saved dump file (@munzzyy) - Added `hf 14b dump` support for Standard ISO14443-B tags (@thisiscamk) - Added `hf 14b ctrdbl` and `hf 14b ctdump` commands for interacting with ASK CTS tags (@kormax) diff --git a/client/src/wiegand_formats.c b/client/src/wiegand_formats.c index 8131b4d99..0791ac876 100644 --- a/client/src/wiegand_formats.c +++ b/client/src/wiegand_formats.c @@ -1472,7 +1472,9 @@ static bool Unpack_IR56(wiegand_message_t *packed, wiegand_card_t *card) { if (packed->Length != 56) return false; - card->FacilityCode = packed->Mid; + // Mask off the header/sentinel bit that add_HID_header sets at position 56 + // (Mid |= 1 << 24) so it doesn't leak into the 24-bit facility code. + card->FacilityCode = packed->Mid & 0x00FFFFFF; card->CardNumber = packed->Bot; return true; } diff --git a/tools/pm3_tests.sh b/tools/pm3_tests.sh index 4fd24e09e..9b1190d21 100755 --- a/tools/pm3_tests.sh +++ b/tools/pm3_tests.sh @@ -506,6 +506,8 @@ while true; do if ! CheckExecute "wiegand Verkada40 decode test 2" "$CLIENTBIN -c 'wiegand decode --raw 86400007D9'" "Verkada40.*FC: 50 CN: 1004 parity \( ok \)"; then break; fi if ! CheckExecute "wiegand Verkada40 encode test 3" "$CLIENTBIN -c 'wiegand encode -w Verkada40 --fc 81 --cn 5008'" "8A20002721"; then break; fi if ! CheckExecute "wiegand Verkada40 decode test 3" "$CLIENTBIN -c 'wiegand decode --raw 8A20002721'" "Verkada40.*FC: 81 CN: 5008 parity \( ok \)"; then break; fi + if ! CheckExecute "wiegand IR56 encode roundtrip" "$CLIENTBIN -c 'wiegand encode -w IR56 --fc 123 --cn 123 --pre'" "9E000000100007B0000007B"; then break; fi + if ! CheckExecute "wiegand IR56 decode roundtrip" "$CLIENTBIN -c 'wiegand decode --raw 9E000000100007B0000007B'" "IR56.*FC: 123 CN: 123"; then break; fi echo -e "\n${C_BLUE}Testing LF:${C_NC}" if ! CheckExecute "lf hitag2 test" "$CLIENTBIN -c 'lf hitag test'" "Tests \( ok"; then break; fi