From 0c3773e1ba589579489dc024525794b3a3ddc548 Mon Sep 17 00:00:00 2001 From: Eric Betts Date: Wed, 23 Aug 2023 05:33:35 -0700 Subject: [PATCH] Picopass remove sentinel (#29) --- application.fam | 4 ++-- picopass_device.c | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/application.fam b/application.fam index 5bfdd01e68f..90dd84c8dff 100644 --- a/application.fam +++ b/application.fam @@ -9,8 +9,8 @@ App( "gui", ], stack_size=4 * 1024, - fap_description="App to communicate with NFC tags using the PicoPass format", - fap_version="1.1", + fap_description="App to communicate with NFC tags using the PicoPass(iClass) format", + fap_version="1.2", fap_icon="125_10px.png", fap_category="NFC", fap_libs=["mbedtls"], diff --git a/picopass_device.c b/picopass_device.c index 52c39c44c92..73f79eca727 100644 --- a/picopass_device.c +++ b/picopass_device.c @@ -356,8 +356,8 @@ ReturnCode picopass_device_parse_credential(PicopassBlock* AA1, PicopassPacs* pa return ERR_NONE; } -ReturnCode picopass_device_parse_wiegand(uint8_t* data, PicopassWiegandRecord* record) { - uint32_t* halves = (uint32_t*)data; +ReturnCode picopass_device_parse_wiegand(uint8_t* credential, PicopassWiegandRecord* record) { + uint32_t* halves = (uint32_t*)credential; if(halves[0] == 0) { uint8_t leading0s = __builtin_clz(REVERSE_BYTES_U32(halves[1])); record->bitLength = 31 - leading0s; @@ -367,8 +367,16 @@ ReturnCode picopass_device_parse_wiegand(uint8_t* data, PicopassWiegandRecord* r } FURI_LOG_D(TAG, "bitLength: %d", record->bitLength); + // Remove sentinel bit from credential. Byteswapping to handle array of bytes vs 64bit value + uint64_t sentinel = __builtin_bswap64(1ULL << record->bitLength); + uint64_t swapped = 0; + memcpy(&swapped, credential, sizeof(uint64_t)); + swapped = swapped ^ sentinel; + memcpy(credential, &swapped, sizeof(uint64_t)); + FURI_LOG_D(TAG, "PACS: (%d) %016llx", record->bitLength, swapped); + if(record->bitLength == 26) { - uint8_t* v4 = data + 4; + uint8_t* v4 = credential + 4; uint32_t bot = v4[3] | (v4[2] << 8) | (v4[1] << 16) | (v4[0] << 24); record->CardNumber = (bot >> 1) & 0xFFFF;