Skip to content

Commit 322cb82

Browse files
authored
Picopass remove sentinel (#29)
1 parent 885f01f commit 322cb82

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

application.fam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ App(
99
"gui",
1010
],
1111
stack_size=4 * 1024,
12-
fap_description="App to communicate with NFC tags using the PicoPass format",
13-
fap_version="1.1",
12+
fap_description="App to communicate with NFC tags using the PicoPass(iClass) format",
13+
fap_version="1.2",
1414
fap_icon="125_10px.png",
1515
fap_category="NFC",
1616
fap_libs=["mbedtls"],

picopass_device.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ ReturnCode picopass_device_parse_credential(PicopassBlock* AA1, PicopassPacs* pa
356356
return ERR_NONE;
357357
}
358358

359-
ReturnCode picopass_device_parse_wiegand(uint8_t* data, PicopassWiegandRecord* record) {
360-
uint32_t* halves = (uint32_t*)data;
359+
ReturnCode picopass_device_parse_wiegand(uint8_t* credential, PicopassWiegandRecord* record) {
360+
uint32_t* halves = (uint32_t*)credential;
361361
if(halves[0] == 0) {
362362
uint8_t leading0s = __builtin_clz(REVERSE_BYTES_U32(halves[1]));
363363
record->bitLength = 31 - leading0s;
@@ -367,8 +367,16 @@ ReturnCode picopass_device_parse_wiegand(uint8_t* data, PicopassWiegandRecord* r
367367
}
368368
FURI_LOG_D(TAG, "bitLength: %d", record->bitLength);
369369

370+
// Remove sentinel bit from credential. Byteswapping to handle array of bytes vs 64bit value
371+
uint64_t sentinel = __builtin_bswap64(1ULL << record->bitLength);
372+
uint64_t swapped = 0;
373+
memcpy(&swapped, credential, sizeof(uint64_t));
374+
swapped = swapped ^ sentinel;
375+
memcpy(credential, &swapped, sizeof(uint64_t));
376+
FURI_LOG_D(TAG, "PACS: (%d) %016llx", record->bitLength, swapped);
377+
370378
if(record->bitLength == 26) {
371-
uint8_t* v4 = data + 4;
379+
uint8_t* v4 = credential + 4;
372380
uint32_t bot = v4[3] | (v4[2] << 8) | (v4[1] << 16) | (v4[0] << 24);
373381

374382
record->CardNumber = (bot >> 1) & 0xFFFF;

0 commit comments

Comments
 (0)