Skip to content

Commit

Permalink
lets see if this still detects sentinels
Browse files Browse the repository at this point in the history
  • Loading branch information
iceman1001 committed Aug 21, 2022
1 parent 28449aa commit 38a664f
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions client/src/wiegand_formatutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,24 +131,17 @@ bool set_nonlinear_field(wiegand_message_t *data, uint64_t value, uint8_t numBit
static uint8_t get_length_from_header(wiegand_message_t *data) {
/**
* detect if message has "preamble" / "sentinel bit"
*
* Right now we just calculate the highest bit set
* 37 bit formats is hard to detect since it doesnt have a sentinel bit
*/


uint8_t len = 0;
uint32_t hfmt = 0; // for calculating card length

if ((data->Top & 0x000FFFFF) > 0) { // > 64 bits
hfmt = data->Top & 0x000FFFFF;
len = 64;
} else if ((data->Mid & 0xFFFFFFC0) > 0) { // < 63-38 bits
hfmt = data->Mid & 0xFFFFFFC0;
len = 32;
} else if (data->Mid && (data->Mid & 0x00000020) == 0) { // 37 bits;
hfmt = 0;
len = 37;
} else if ((data->Mid & 0x0000001F) > 0) { // 36-32 bits
hfmt = data->Mid & 0x0000001F;
} else if (data->Mid > 0) { // < 63-32 bits
hfmt = data->Mid;
len = 32;
} else {
hfmt = data->Bot;
Expand All @@ -159,8 +152,11 @@ static uint8_t get_length_from_header(wiegand_message_t *data) {
hfmt >>= 1;
len++;
}

// everything less than 26 bits found, assume 26 bits
if (len < 26)
len = 26;

return len;
}

Expand Down

0 comments on commit 38a664f

Please sign in to comment.