This commit is contained in:
iceman1001 2019-09-19 10:47:12 +02:00
commit 895410aec0
13 changed files with 714 additions and 714 deletions

View file

@ -480,15 +480,15 @@ int CmdLFNedapClone(const char *Cmd) {
if (i == 0) { if (i == 0) {
SetConfigWithBlock0(blocks[0]); SetConfigWithBlock0(blocks[0]);
if ( t55xxAquireAndCompareBlock0(false, 0, blocks[0], false) ) if (t55xxAquireAndCompareBlock0(false, 0, blocks[0], false))
continue; continue;
} }
if (t55xxVerifyWrite(i, 0, false, false, 0, 0xFF, blocks[i]) == false) if (t55xxVerifyWrite(i, 0, false, false, 0, 0xFF, blocks[i]) == false)
res++; res++;
} }
if ( res == 0 ) if (res == 0)
PrintAndLogEx(SUCCESS, "Success writing to tag"); PrintAndLogEx(SUCCESS, "Success writing to tag");
else { else {
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");

View file

@ -179,15 +179,15 @@ static int CmdNoralsyClone(const char *Cmd) {
if (i == 0) { if (i == 0) {
SetConfigWithBlock0(blocks[0]); SetConfigWithBlock0(blocks[0]);
if ( t55xxAquireAndCompareBlock0(false, 0, blocks[0], false) ) if (t55xxAquireAndCompareBlock0(false, 0, blocks[0], false))
continue; continue;
} }
if (t55xxVerifyWrite(i, 0, false, false, 0, 0xFF, blocks[i]) == false) if (t55xxVerifyWrite(i, 0, false, false, 0, 0xFF, blocks[i]) == false)
res++; res++;
} }
if ( res == 0 ) if (res == 0)
PrintAndLogEx(SUCCESS, "Success writing to tag"); PrintAndLogEx(SUCCESS, "Success writing to tag");
return PM3_SUCCESS; return PM3_SUCCESS;

View file

@ -146,7 +146,7 @@ static int CmdPrescoClone(const char *Cmd) {
if (i == 0) { if (i == 0) {
SetConfigWithBlock0(blocks[0]); SetConfigWithBlock0(blocks[0]);
if ( t55xxAquireAndCompareBlock0(false, 0, blocks[0], false) ) if (t55xxAquireAndCompareBlock0(false, 0, blocks[0], false))
continue; continue;
} }
@ -155,9 +155,9 @@ static int CmdPrescoClone(const char *Cmd) {
} }
if ( res == 0 ) if (res == 0)
PrintAndLogEx(SUCCESS, "Success writing to tag"); PrintAndLogEx(SUCCESS, "Success writing to tag");
return PM3_SUCCESS; return PM3_SUCCESS;
} }

View file

@ -256,18 +256,18 @@ static int CmdPyramidClone(const char *Cmd) {
if (i == 0) { if (i == 0) {
SetConfigWithBlock0(blocks[0]); SetConfigWithBlock0(blocks[0]);
if ( t55xxAquireAndCompareBlock0(false, 0, blocks[0], false) ) if (t55xxAquireAndCompareBlock0(false, 0, blocks[0], false))
continue; continue;
} }
if (t55xxVerifyWrite(i, 0, false, false, 0, 0xFF, blocks[i]) == false) if (t55xxVerifyWrite(i, 0, false, false, 0, 0xFF, blocks[i]) == false)
res++; res++;
} }
if ( res == 0 ) if (res == 0)
PrintAndLogEx(SUCCESS, "Success writing to tag"); PrintAndLogEx(SUCCESS, "Success writing to tag");
return PM3_SUCCESS; return PM3_SUCCESS;
} }

View file

@ -90,14 +90,14 @@ static int CmdVikingClone(const char *Cmd) {
uint8_t blocks[8]; uint8_t blocks[8];
} PACKED payload; } PACKED payload;
payload.Q5 = Q5; payload.Q5 = Q5;
num_to_bytes(rawID, 8, &payload.blocks[0]); num_to_bytes(rawID, 8, &payload.blocks[0]);
PrintAndLogEx(INFO, "Preparing to clone Viking tag - ID " _YELLOW_("%08X")" raw " _YELLOW_("%s"), id, sprint_hex(payload.blocks, sizeof(payload.blocks))); PrintAndLogEx(INFO, "Preparing to clone Viking tag - ID " _YELLOW_("%08X")" raw " _YELLOW_("%s"), id, sprint_hex(payload.blocks, sizeof(payload.blocks)));
clearCommandBuffer(); clearCommandBuffer();
SendCommandNG(CMD_LF_VIKING_CLONE, (uint8_t*)&payload, sizeof(payload)); SendCommandNG(CMD_LF_VIKING_CLONE, (uint8_t *)&payload, sizeof(payload));
PacketResponseNG resp; PacketResponseNG resp;
if (!WaitForResponseTimeout(CMD_LF_VIKING_CLONE, &resp, T55XX_WRITE_TIMEOUT)) { if (!WaitForResponseTimeout(CMD_LF_VIKING_CLONE, &resp, T55XX_WRITE_TIMEOUT)) {
PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation.");

View file

@ -169,7 +169,7 @@ static int CmdVisa2kClone(const char *Cmd) {
uint8_t res = 0; uint8_t res = 0;
PacketResponseNG resp; PacketResponseNG resp;
// fast push mode // fast push mode
conn.block_after_ACK = true; conn.block_after_ACK = true;
for (uint8_t i = 0; i < 4; i++) { for (uint8_t i = 0; i < 4; i++) {
@ -193,15 +193,15 @@ static int CmdVisa2kClone(const char *Cmd) {
if (i == 0) { if (i == 0) {
SetConfigWithBlock0(blocks[0]); SetConfigWithBlock0(blocks[0]);
if ( t55xxAquireAndCompareBlock0(false, 0, blocks[0], false) ) if (t55xxAquireAndCompareBlock0(false, 0, blocks[0], false))
continue; continue;
} }
if (t55xxVerifyWrite(i, 0, false, false, 0, 0xFF, blocks[i]) == false) if (t55xxVerifyWrite(i, 0, false, false, 0, 0xFF, blocks[i]) == false)
res++; res++;
} }
if ( res == 0 ) if (res == 0)
PrintAndLogEx(SUCCESS, "Success writing to tag"); PrintAndLogEx(SUCCESS, "Success writing to tag");
return PM3_SUCCESS; return PM3_SUCCESS;

View file

@ -20,7 +20,7 @@
#include "cmdhflist.h" // annotations #include "cmdhflist.h" // annotations
#include "wiegand_formats.h" #include "wiegand_formats.h"
#include "wiegand_formatutils.h" #include "wiegand_formatutils.h"
#include "util.h" #include "util.h"
static int CmdHelp(const char *Cmd); static int CmdHelp(const char *Cmd);
@ -52,18 +52,18 @@ static int usage_wiegand_decode() {
return PM3_SUCCESS; return PM3_SUCCESS;
} }
void PrintTagId(wiegand_message_t *packed){ void PrintTagId(wiegand_message_t *packed) {
if (packed->Top != 0) { if (packed->Top != 0) {
PrintAndLogEx(SUCCESS, "Card ID: %X%08X%08X", PrintAndLogEx(SUCCESS, "Card ID: %X%08X%08X",
(uint32_t)packed->Top, (uint32_t)packed->Top,
(uint32_t)packed->Mid, (uint32_t)packed->Mid,
(uint32_t)packed->Bot) (uint32_t)packed->Bot)
; ;
} else { } else {
PrintAndLogEx(SUCCESS, "Card ID: %X%08X", PrintAndLogEx(SUCCESS, "Card ID: %X%08X",
(uint32_t)packed->Mid, (uint32_t)packed->Mid,
(uint32_t)packed->Bot) (uint32_t)packed->Bot)
; ;
} }
} }
@ -88,7 +88,7 @@ int CmdWiegandEncode(const char *Cmd) {
int format_idx = -1; int format_idx = -1;
char format[16] = {0}; char format[16] = {0};
wiegand_card_t data; wiegand_card_t data;
memset(&data, 0, sizeof(wiegand_card_t)); memset(&data, 0, sizeof(wiegand_card_t));
@ -133,12 +133,12 @@ int CmdWiegandEncode(const char *Cmd) {
wiegand_message_t packed; wiegand_message_t packed;
memset(&packed, 0, sizeof(wiegand_message_t)); memset(&packed, 0, sizeof(wiegand_message_t));
if (HIDPack(format_idx, &data, &packed) == false) { if (HIDPack(format_idx, &data, &packed) == false) {
PrintAndLogEx(WARNING, "The card data could not be encoded in the selected format."); PrintAndLogEx(WARNING, "The card data could not be encoded in the selected format.");
return PM3_ESOFT; return PM3_ESOFT;
} }
PrintTagId(&packed); PrintTagId(&packed);
return PM3_SUCCESS; return PM3_SUCCESS;
} }
@ -152,7 +152,7 @@ int CmdWiegandDecode(const char *Cmd) {
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
uint32_t strlen = param_getlength(Cmd, cmdp); uint32_t strlen = param_getlength(Cmd, cmdp);
strlen++; // null termin strlen++; // null termin
if ( strlen > 2 ) { if (strlen > 2) {
char *s = calloc(strlen, sizeof(uint8_t)); char *s = calloc(strlen, sizeof(uint8_t));
param_getstr(Cmd, cmdp, s, strlen); param_getstr(Cmd, cmdp, s, strlen);
hexstring_to_u96(&top, &mid, &bot, s); hexstring_to_u96(&top, &mid, &bot, s);
@ -176,11 +176,11 @@ int CmdWiegandDecode(const char *Cmd) {
} }
if (gothex == false) if (gothex == false)
errors = true; errors = true;
if (errors || cmdp < 1) return usage_wiegand_decode(); if (errors || cmdp < 1) return usage_wiegand_decode();
wiegand_message_t packed = initialize_message_object(top, mid, bot); wiegand_message_t packed = initialize_message_object(top, mid, bot);
HIDTryUnpack(&packed, ignore_parity); HIDTryUnpack(&packed, ignore_parity);
return PM3_SUCCESS; return PM3_SUCCESS;
} }

View file

@ -885,10 +885,10 @@ char *strmcopy(const char *buf) {
* *
* Returns the number of nibbles (4 bits) entered. * Returns the number of nibbles (4 bits) entered.
*/ */
int hexstring_to_u96(uint32_t* hi2, uint32_t* hi, uint32_t* lo, const char* str) { int hexstring_to_u96(uint32_t *hi2, uint32_t *hi, uint32_t *lo, const char *str) {
int n = 0, i = 0; int n = 0, i = 0;
while (sscanf(&str[i++], "%1x", &n ) == 1) { while (sscanf(&str[i++], "%1x", &n) == 1) {
*hi2 = (*hi2 << 4) | (*hi >> 28); *hi2 = (*hi2 << 4) | (*hi >> 28);
*hi = (*hi << 4) | (*lo >> 28); *hi = (*hi << 4) | (*lo >> 28);
*lo = (*lo << 4) | (n & 0xf); *lo = (*lo << 4) | (n & 0xf);

View file

@ -98,5 +98,5 @@ void clean_ascii(unsigned char *buf, size_t len);
void strcleanrn(char *buf, size_t len); void strcleanrn(char *buf, size_t len);
void strcreplace(char *buf, size_t len, char from, char to); void strcreplace(char *buf, size_t len, char from, char to);
char *strmcopy(const char *buf); char *strmcopy(const char *buf);
int hexstring_to_u96(uint32_t* hi2, uint32_t* hi, uint32_t* lo, const char* str); int hexstring_to_u96(uint32_t *hi2, uint32_t *hi, uint32_t *lo, const char *str);
#endif #endif

File diff suppressed because it is too large Load diff

View file

@ -23,26 +23,26 @@
#include "ui.h" #include "ui.h"
typedef struct { typedef struct {
bool hasCardNumber; bool hasCardNumber;
bool hasFacilityCode; bool hasFacilityCode;
bool hasIssueLevel; bool hasIssueLevel;
bool hasOEMCode; bool hasOEMCode;
bool hasParity; bool hasParity;
} cardformatdescriptor_t; } cardformatdescriptor_t;
// Structure for defined Wiegand card formats available for packing/unpacking // Structure for defined Wiegand card formats available for packing/unpacking
typedef struct { typedef struct {
const char* Name; const char *Name;
bool (*Pack)(wiegand_card_t* card, wiegand_message_t* packed); bool (*Pack)(wiegand_card_t *card, wiegand_message_t *packed);
bool (*Unpack)(wiegand_message_t* packed, wiegand_card_t* card); bool (*Unpack)(wiegand_message_t *packed, wiegand_card_t *card);
const char* Descrp; const char *Descrp;
cardformatdescriptor_t Fields; cardformatdescriptor_t Fields;
} cardformat_t; } cardformat_t;
void HIDListFormats(); void HIDListFormats();
int HIDFindCardFormat(const char *format); int HIDFindCardFormat(const char *format);
cardformat_t HIDGetCardFormat(int idx); cardformat_t HIDGetCardFormat(int idx);
bool HIDPack(int FormatIndex, wiegand_card_t* card, wiegand_message_t* packed); bool HIDPack(int FormatIndex, wiegand_card_t *card, wiegand_message_t *packed);
bool HIDTryUnpack(wiegand_message_t* packed, bool ignoreParity); bool HIDTryUnpack(wiegand_message_t *packed, bool ignoreParity);
#endif #endif

View file

@ -15,171 +15,171 @@
#include "wiegand_formatutils.h" #include "wiegand_formatutils.h"
#include "ui.h" #include "ui.h"
bool get_bit_by_position(wiegand_message_t* data, uint8_t pos){ bool get_bit_by_position(wiegand_message_t *data, uint8_t pos) {
if (pos >= data->Length) return false; if (pos >= data->Length) return false;
pos = (data->Length - pos) - 1; // invert ordering; Indexing goes from 0 to 1. Subtract 1 for weight of bit. pos = (data->Length - pos) - 1; // invert ordering; Indexing goes from 0 to 1. Subtract 1 for weight of bit.
bool result = false; bool result = false;
if (pos > 95) if (pos > 95)
result = false; result = false;
else if (pos > 63) else if (pos > 63)
result = (data->Top >> (pos - 64)) & 1; result = (data->Top >> (pos - 64)) & 1;
else if (pos > 31) else if (pos > 31)
result = (data->Mid >> (pos - 32)) & 1; result = (data->Mid >> (pos - 32)) & 1;
else else
result = (data->Bot >> pos) & 1; result = (data->Bot >> pos) & 1;
return result; return result;
} }
bool set_bit_by_position(wiegand_message_t* data, bool value, uint8_t pos){ bool set_bit_by_position(wiegand_message_t *data, bool value, uint8_t pos) {
if (pos >= data->Length) return false; if (pos >= data->Length) return false;
pos = (data->Length - pos) - 1; // invert ordering; Indexing goes from 0 to 1. Subtract 1 for weight of bit. pos = (data->Length - pos) - 1; // invert ordering; Indexing goes from 0 to 1. Subtract 1 for weight of bit.
if (pos > 95) { if (pos > 95) {
return false; return false;
} else if (pos > 63) { } else if (pos > 63) {
if (value) if (value)
data->Top |= (1 << (pos - 64)); data->Top |= (1 << (pos - 64));
else else
data->Top &= ~(1 << (pos - 64)); data->Top &= ~(1 << (pos - 64));
return true; return true;
} else if (pos > 31) { } else if (pos > 31) {
if (value) if (value)
data->Mid |= (1 << (pos - 32)); data->Mid |= (1 << (pos - 32));
else else
data->Mid &= ~(1 << (pos - 32)); data->Mid &= ~(1 << (pos - 32));
return true; return true;
} else { } else {
if (value) if (value)
data->Bot |= (1 << pos); data->Bot |= (1 << pos);
else else
data->Bot &= ~(1 << pos); data->Bot &= ~(1 << pos);
return true; return true;
} }
} }
/** /**
* Safeguard the data by doing a manual deep copy * Safeguard the data by doing a manual deep copy
* *
* At the time of the initial writing, the struct does not contain pointers. That doesn't * At the time of the initial writing, the struct does not contain pointers. That doesn't
* mean it won't eventually contain one, however. To prevent memory leaks and erroneous * mean it won't eventually contain one, however. To prevent memory leaks and erroneous
* aliasing, perform the copy function manually instead. Hence, this function. * aliasing, perform the copy function manually instead. Hence, this function.
* *
* If the definition of the wiegand_message struct changes, this function must also * If the definition of the wiegand_message struct changes, this function must also
* be updated to match. * be updated to match.
*/ */
void message_datacopy(wiegand_message_t* src, wiegand_message_t* dest){ void message_datacopy(wiegand_message_t *src, wiegand_message_t *dest) {
dest->Bot = src->Bot; dest->Bot = src->Bot;
dest->Mid = src->Mid; dest->Mid = src->Mid;
dest->Top = src->Top; dest->Top = src->Top;
dest->Length = src->Length; dest->Length = src->Length;
} }
/** /**
* *
* Yes, this is horribly inefficient for linear data. * Yes, this is horribly inefficient for linear data.
* The current code is a temporary measure to have a working function in place * The current code is a temporary measure to have a working function in place
* until all the bugs shaken from the block/chunk version of the code. * until all the bugs shaken from the block/chunk version of the code.
* *
*/ */
uint64_t get_linear_field(wiegand_message_t* data, uint8_t firstBit, uint8_t length){ uint64_t get_linear_field(wiegand_message_t *data, uint8_t firstBit, uint8_t length) {
uint64_t result = 0; uint64_t result = 0;
for (uint8_t i = 0; i < length; i++ ) { for (uint8_t i = 0; i < length; i++) {
result = (result << 1) | get_bit_by_position(data, firstBit + i); result = (result << 1) | get_bit_by_position(data, firstBit + i);
} }
return result; return result;
} }
bool set_linear_field(wiegand_message_t* data, uint64_t value, uint8_t firstBit, uint8_t length){ bool set_linear_field(wiegand_message_t *data, uint64_t value, uint8_t firstBit, uint8_t length) {
wiegand_message_t tmpdata;
message_datacopy(data, &tmpdata);
bool result = true;
for (int i = 0; i < length; i++){
result &= set_bit_by_position(&tmpdata, (value >> ((length - i) - 1)) & 1, firstBit + i);
}
if (result)
message_datacopy(&tmpdata, data);
return result;
}
uint64_t get_nonlinear_field(wiegand_message_t* data, uint8_t numBits, uint8_t* bits){
uint64_t result = 0;
for (int i = 0; i < numBits; i++){
result = (result << 1) | (get_bit_by_position(data, *(bits+i)) & 1);
}
return result;
}
bool set_nonlinear_field(wiegand_message_t* data, uint64_t value, uint8_t numBits, uint8_t* bits){
wiegand_message_t tmpdata; wiegand_message_t tmpdata;
message_datacopy(data, &tmpdata); message_datacopy(data, &tmpdata);
bool result = true; bool result = true;
for (int i = 0; i < numBits; i++){ for (int i = 0; i < length; i++) {
result &= set_bit_by_position(&tmpdata, (value >> ((numBits - i) - 1)) & 1, *(bits + i)); result &= set_bit_by_position(&tmpdata, (value >> ((length - i) - 1)) & 1, firstBit + i);
} }
if (result) if (result)
message_datacopy(&tmpdata, data); message_datacopy(&tmpdata, data);
return result; return result;
} }
uint8_t get_length_from_header(wiegand_message_t* data) { uint64_t get_nonlinear_field(wiegand_message_t *data, uint8_t numBits, uint8_t *bits) {
uint8_t len = 0; uint64_t result = 0;
uint32_t hfmt = 0; // for calculating card length for (int i = 0; i < numBits; i++) {
result = (result << 1) | (get_bit_by_position(data, *(bits + i)) & 1);
if ((data->Top & 0x000FFFFF) > 0) { // > 64 bits }
hfmt = data->Top & 0x000FFFFF; return result;
len = 64; }
} else if ((data->Mid & 0xFFFFFFC0) > 0) { // < 63-38 bits bool set_nonlinear_field(wiegand_message_t *data, uint64_t value, uint8_t numBits, uint8_t *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
printf("a\n");
hfmt = data->Mid & 0x0000001F;
len = 32;
} else if (data->Top == 0 && data->Mid == 0) { //< 32 bits
hfmt = data->Bot;
len = 0;
} else {
hfmt = data->Bot;
len = 0;
}
while (hfmt > 1) { wiegand_message_t tmpdata;
hfmt >>= 1; message_datacopy(data, &tmpdata);
len++;
} bool result = true;
return len; for (int i = 0; i < numBits; i++) {
result &= set_bit_by_position(&tmpdata, (value >> ((numBits - i) - 1)) & 1, *(bits + i));
}
if (result)
message_datacopy(&tmpdata, data);
return result;
} }
wiegand_message_t initialize_message_object(uint32_t top, uint32_t mid, uint32_t bot){ uint8_t get_length_from_header(wiegand_message_t *data) {
wiegand_message_t result; uint8_t len = 0;
memset(&result, 0, sizeof(wiegand_message_t)); uint32_t hfmt = 0; // for calculating card length
result.Top = top; if ((data->Top & 0x000FFFFF) > 0) { // > 64 bits
result.Mid = mid; hfmt = data->Top & 0x000FFFFF;
result.Bot = bot; len = 64;
result.Length = get_length_from_header(&result); } else if ((data->Mid & 0xFFFFFFC0) > 0) { // < 63-38 bits
return result; 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
printf("a\n");
hfmt = data->Mid & 0x0000001F;
len = 32;
} else if (data->Top == 0 && data->Mid == 0) { //< 32 bits
hfmt = data->Bot;
len = 0;
} else {
hfmt = data->Bot;
len = 0;
}
while (hfmt > 1) {
hfmt >>= 1;
len++;
}
return len;
} }
bool add_HID_header(wiegand_message_t* data){ wiegand_message_t initialize_message_object(uint32_t top, uint32_t mid, uint32_t bot) {
if (data->Length > 84 || data->Length == 0) return false; // Invalid value wiegand_message_t result;
memset(&result, 0, sizeof(wiegand_message_t));
if (data->Length >= 64){ result.Top = top;
data->Top |= 1 << (data->Length - 64); // leading 1: start bit result.Mid = mid;
data->Top |= 0x09e00000; // Extended-length header result.Bot = bot;
} else if (data->Length > 37){ result.Length = get_length_from_header(&result);
data->Mid |= 1 << (data->Length - 32); // leading 1: start bit return result;
data->Top |= 0x09e00000; // Extended-length header }
} else if (data->Length == 37){
// No header bits added to 37-bit cards bool add_HID_header(wiegand_message_t *data) {
} else if (data->Length >= 32){ if (data->Length > 84 || data->Length == 0) return false; // Invalid value
data->Mid |= 0x20; // Bit 37; standard header
data->Mid |= 1 << (data->Length - 32); // leading 1: start bit if (data->Length >= 64) {
} else { data->Top |= 1 << (data->Length - 64); // leading 1: start bit
data->Mid |= 0x20; // Bit 37; standard header data->Top |= 0x09e00000; // Extended-length header
data->Bot |= 1 << data->Length; // leading 1: start bit } else if (data->Length > 37) {
} data->Mid |= 1 << (data->Length - 32); // leading 1: start bit
return true; data->Top |= 0x09e00000; // Extended-length header
} else if (data->Length == 37) {
// No header bits added to 37-bit cards
} else if (data->Length >= 32) {
data->Mid |= 0x20; // Bit 37; standard header
data->Mid |= 1 << (data->Length - 32); // leading 1: start bit
} else {
data->Mid |= 0x20; // Bit 37; standard header
data->Bot |= 1 << data->Length; // leading 1: start bit
}
return true;
} }

View file

@ -18,32 +18,32 @@
// Structure for packed wiegand messages // Structure for packed wiegand messages
// Always align lowest value (last transmitted) bit to ordinal position 0 (lowest valued bit bottom) // Always align lowest value (last transmitted) bit to ordinal position 0 (lowest valued bit bottom)
typedef struct { typedef struct {
uint8_t Length; // Number of encoded bits in wiegand message (excluding headers and preamble) uint8_t Length; // Number of encoded bits in wiegand message (excluding headers and preamble)
uint32_t Top; // Bits in x<<64 positions uint32_t Top; // Bits in x<<64 positions
uint32_t Mid; // Bits in x<<32 positions uint32_t Mid; // Bits in x<<32 positions
uint32_t Bot; // Lowest ordinal positions uint32_t Bot; // Lowest ordinal positions
} wiegand_message_t; } wiegand_message_t;
// Structure for unpacked wiegand card, like HID prox // Structure for unpacked wiegand card, like HID prox
typedef struct { typedef struct {
uint32_t FacilityCode; uint32_t FacilityCode;
uint64_t CardNumber; uint64_t CardNumber;
uint32_t IssueLevel; uint32_t IssueLevel;
uint32_t OEM; uint32_t OEM;
bool ParityValid; // Only valid for responses bool ParityValid; // Only valid for responses
} wiegand_card_t; } wiegand_card_t;
bool get_bit_by_position(wiegand_message_t* data, uint8_t pos); bool get_bit_by_position(wiegand_message_t *data, uint8_t pos);
bool set_bit_by_position(wiegand_message_t* data, bool value, uint8_t pos); bool set_bit_by_position(wiegand_message_t *data, bool value, uint8_t pos);
uint64_t get_linear_field(wiegand_message_t* data, uint8_t firstBit, uint8_t length); uint64_t get_linear_field(wiegand_message_t *data, uint8_t firstBit, uint8_t length);
bool set_linear_field(wiegand_message_t* data, uint64_t value, uint8_t firstBit, uint8_t length); bool set_linear_field(wiegand_message_t *data, uint64_t value, uint8_t firstBit, uint8_t length);
uint64_t get_nonlinear_field(wiegand_message_t* data, uint8_t numBits, uint8_t* bits); uint64_t get_nonlinear_field(wiegand_message_t *data, uint8_t numBits, uint8_t *bits);
bool set_nonlinear_field(wiegand_message_t* data, uint64_t value, uint8_t numBits, uint8_t* bits); bool set_nonlinear_field(wiegand_message_t *data, uint64_t value, uint8_t numBits, uint8_t *bits);
wiegand_message_t initialize_message_object(uint32_t top, uint32_t mid, uint32_t bot); wiegand_message_t initialize_message_object(uint32_t top, uint32_t mid, uint32_t bot);
bool add_HID_header(wiegand_message_t* data); bool add_HID_header(wiegand_message_t *data);
#endif #endif