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,7 +480,7 @@ 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;
} }
@ -488,7 +488,7 @@ int CmdLFNedapClone(const char *Cmd) {
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,7 +179,7 @@ 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;
} }
@ -187,7 +187,7 @@ static int CmdNoralsyClone(const char *Cmd) {
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,7 +155,7 @@ 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,7 +256,7 @@ 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;
} }
@ -265,7 +265,7 @@ static int CmdPyramidClone(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

@ -97,7 +97,7 @@ static int CmdVikingClone(const char *Cmd) {
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

@ -193,7 +193,7 @@ 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;
} }
@ -201,7 +201,7 @@ static int CmdVisa2kClone(const char *Cmd) {
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

@ -52,7 +52,7 @@ 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,
@ -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);

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

View file

@ -9,7 +9,7 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include "wiegand_formats.h" #include "wiegand_formats.h"
bool Pack_H10301(wiegand_card_t* card, wiegand_message_t* packed){ bool Pack_H10301(wiegand_card_t *card, wiegand_message_t *packed) {
memset(packed, 0, sizeof(wiegand_message_t)); memset(packed, 0, sizeof(wiegand_message_t));
if (card->FacilityCode > 0xFF) return false; // Can't encode FC. if (card->FacilityCode > 0xFF) return false; // Can't encode FC.
@ -25,7 +25,7 @@ bool Pack_H10301(wiegand_card_t* card, wiegand_message_t* packed){
return add_HID_header(packed); return add_HID_header(packed);
} }
bool Unpack_H10301(wiegand_message_t* packed, wiegand_card_t* card){ bool Unpack_H10301(wiegand_message_t *packed, wiegand_card_t *card) {
memset(card, 0, sizeof(wiegand_card_t)); memset(card, 0, sizeof(wiegand_card_t));
if (packed->Length != 26) return false; // Wrong length? Stop here. if (packed->Length != 26) return false; // Wrong length? Stop here.
@ -37,7 +37,7 @@ bool Unpack_H10301(wiegand_message_t* packed, wiegand_card_t* card){
return true; return true;
} }
bool Pack_Tecom27(wiegand_card_t* card, wiegand_message_t* packed){ bool Pack_Tecom27(wiegand_card_t *card, wiegand_message_t *packed) {
memset(packed, 0, sizeof(wiegand_message_t)); memset(packed, 0, sizeof(wiegand_message_t));
if (card->FacilityCode > 0x7FF) return false; // Can't encode FC. if (card->FacilityCode > 0x7FF) return false; // Can't encode FC.
@ -46,22 +46,22 @@ bool Pack_Tecom27(wiegand_card_t* card, wiegand_message_t* packed){
if (card->OEM > 0) return false; // Not used in this format if (card->OEM > 0) return false; // Not used in this format
packed->Length = 27; packed->Length = 27;
set_nonlinear_field(packed, card->FacilityCode, 10, (uint8_t[]){15, 19, 24, 23, 22, 18, 6, 10, 14, 3, 2}); set_nonlinear_field(packed, card->FacilityCode, 10, (uint8_t[]) {15, 19, 24, 23, 22, 18, 6, 10, 14, 3, 2});
set_nonlinear_field(packed, card->CardNumber, 16, (uint8_t[]){0, 1, 13, 12, 9, 26, 20, 16, 17, 21, 25, 7, 8, 11, 4, 5}); set_nonlinear_field(packed, card->CardNumber, 16, (uint8_t[]) {0, 1, 13, 12, 9, 26, 20, 16, 17, 21, 25, 7, 8, 11, 4, 5});
return add_HID_header(packed); return add_HID_header(packed);
} }
bool Unpack_Tecom27(wiegand_message_t* packed, wiegand_card_t* card){ bool Unpack_Tecom27(wiegand_message_t *packed, wiegand_card_t *card) {
memset(card, 0, sizeof(wiegand_card_t)); memset(card, 0, sizeof(wiegand_card_t));
if (packed->Length != 27) return false; // Wrong length? Stop here. if (packed->Length != 27) return false; // Wrong length? Stop here.
card->CardNumber = get_nonlinear_field(packed, 16, (uint8_t[]){0, 1, 13, 12, 9, 26, 20, 16, 17, 21, 25, 7, 8, 11, 4, 5}); card->CardNumber = get_nonlinear_field(packed, 16, (uint8_t[]) {0, 1, 13, 12, 9, 26, 20, 16, 17, 21, 25, 7, 8, 11, 4, 5});
card->FacilityCode = get_nonlinear_field(packed, 10, (uint8_t[]){15, 19, 24, 23, 22, 18, 6, 10, 14, 3, 2}); card->FacilityCode = get_nonlinear_field(packed, 10, (uint8_t[]) {15, 19, 24, 23, 22, 18, 6, 10, 14, 3, 2});
return true; return true;
} }
bool Pack_2804W(wiegand_card_t* card, wiegand_message_t* packed){ bool Pack_2804W(wiegand_card_t *card, wiegand_message_t *packed) {
memset(packed, 0, sizeof(wiegand_message_t)); memset(packed, 0, sizeof(wiegand_message_t));
if (card->FacilityCode > 0x0FF) return false; // Can't encode FC. if (card->FacilityCode > 0x0FF) return false; // Can't encode FC.
@ -73,7 +73,7 @@ bool Pack_2804W(wiegand_card_t* card, wiegand_message_t* packed){
set_linear_field(packed, card->FacilityCode, 4, 8); set_linear_field(packed, card->FacilityCode, 4, 8);
set_linear_field(packed, card->CardNumber, 12, 15); set_linear_field(packed, card->CardNumber, 12, 15);
set_bit_by_position(packed, set_bit_by_position(packed,
oddparity32(get_nonlinear_field(packed, 16, (uint8_t[]){4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26})) oddparity32(get_nonlinear_field(packed, 16, (uint8_t[]) {4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26}))
, 2); , 2);
set_bit_by_position(packed, set_bit_by_position(packed,
evenparity32(get_linear_field(packed, 1, 13)) evenparity32(get_linear_field(packed, 1, 13))
@ -84,7 +84,7 @@ bool Pack_2804W(wiegand_card_t* card, wiegand_message_t* packed){
return add_HID_header(packed); return add_HID_header(packed);
} }
bool Unpack_2804W(wiegand_message_t* packed, wiegand_card_t* card){ bool Unpack_2804W(wiegand_message_t *packed, wiegand_card_t *card) {
memset(card, 0, sizeof(wiegand_card_t)); memset(card, 0, sizeof(wiegand_card_t));
if (packed->Length != 28) return false; // Wrong length? Stop here. if (packed->Length != 28) return false; // Wrong length? Stop here.
@ -93,12 +93,12 @@ bool Unpack_2804W(wiegand_message_t* packed, wiegand_card_t* card){
card->CardNumber = get_linear_field(packed, 12, 15); card->CardNumber = get_linear_field(packed, 12, 15);
card->ParityValid = card->ParityValid =
(get_bit_by_position(packed, 0) == evenparity32(get_linear_field(packed, 1, 13))) && (get_bit_by_position(packed, 0) == evenparity32(get_linear_field(packed, 1, 13))) &&
(get_bit_by_position(packed, 2) == oddparity32(get_nonlinear_field(packed, 16, (uint8_t[]){4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26}))) && (get_bit_by_position(packed, 2) == oddparity32(get_nonlinear_field(packed, 16, (uint8_t[]) {4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26}))) &&
(get_bit_by_position(packed, 27) == oddparity32(get_linear_field(packed, 0, 27))); (get_bit_by_position(packed, 27) == oddparity32(get_linear_field(packed, 0, 27)));
return true; return true;
} }
bool Pack_ATSW30(wiegand_card_t* card, wiegand_message_t* packed){ bool Pack_ATSW30(wiegand_card_t *card, wiegand_message_t *packed) {
memset(packed, 0, sizeof(wiegand_message_t)); memset(packed, 0, sizeof(wiegand_message_t));
if (card->FacilityCode > 0xFFF) return false; // Can't encode FC. if (card->FacilityCode > 0xFFF) return false; // Can't encode FC.
@ -118,7 +118,7 @@ bool Pack_ATSW30(wiegand_card_t* card, wiegand_message_t* packed){
return add_HID_header(packed); return add_HID_header(packed);
} }
bool Unpack_ATSW30(wiegand_message_t* packed, wiegand_card_t* card){ bool Unpack_ATSW30(wiegand_message_t *packed, wiegand_card_t *card) {
memset(card, 0, sizeof(wiegand_card_t)); memset(card, 0, sizeof(wiegand_card_t));
if (packed->Length != 30) return false; // Wrong length? Stop here. if (packed->Length != 30) return false; // Wrong length? Stop here.
@ -131,7 +131,7 @@ bool Unpack_ATSW30(wiegand_message_t* packed, wiegand_card_t* card){
return true; return true;
} }
bool Pack_ADT31(wiegand_card_t* card, wiegand_message_t* packed){ bool Pack_ADT31(wiegand_card_t *card, wiegand_message_t *packed) {
memset(packed, 0, sizeof(wiegand_message_t)); memset(packed, 0, sizeof(wiegand_message_t));
if (card->FacilityCode > 0x0F) return false; // Can't encode FC. if (card->FacilityCode > 0x0F) return false; // Can't encode FC.
@ -146,7 +146,7 @@ bool Pack_ADT31(wiegand_card_t* card, wiegand_message_t* packed){
return add_HID_header(packed); return add_HID_header(packed);
} }
bool Unpack_ADT31(wiegand_message_t* packed, wiegand_card_t* card){ bool Unpack_ADT31(wiegand_message_t *packed, wiegand_card_t *card) {
memset(card, 0, sizeof(wiegand_card_t)); memset(card, 0, sizeof(wiegand_card_t));
if (packed->Length != 31) return false; // Wrong length? Stop here. if (packed->Length != 31) return false; // Wrong length? Stop here.
@ -155,7 +155,7 @@ bool Unpack_ADT31(wiegand_message_t* packed, wiegand_card_t* card){
return true; return true;
} }
bool Pack_Kastle(wiegand_card_t* card, wiegand_message_t* packed){ bool Pack_Kastle(wiegand_card_t *card, wiegand_message_t *packed) {
memset(packed, 0, sizeof(wiegand_message_t)); memset(packed, 0, sizeof(wiegand_message_t));
if (card->FacilityCode > 0x00FF) return false; // Can't encode FC. if (card->FacilityCode > 0x00FF) return false; // Can't encode FC.
@ -173,7 +173,7 @@ bool Pack_Kastle(wiegand_card_t* card, wiegand_message_t* packed){
return add_HID_header(packed); return add_HID_header(packed);
} }
bool Unpack_Kastle(wiegand_message_t* packed, wiegand_card_t* card){ bool Unpack_Kastle(wiegand_message_t *packed, wiegand_card_t *card) {
memset(card, 0, sizeof(wiegand_card_t)); memset(card, 0, sizeof(wiegand_card_t));
if (packed->Length != 32) return false; // Wrong length? Stop here. if (packed->Length != 32) return false; // Wrong length? Stop here.
@ -188,7 +188,7 @@ bool Unpack_Kastle(wiegand_message_t* packed, wiegand_card_t* card){
return true; return true;
} }
bool Pack_D10202(wiegand_card_t* card, wiegand_message_t* packed){ bool Pack_D10202(wiegand_card_t *card, wiegand_message_t *packed) {
memset(packed, 0, sizeof(wiegand_message_t)); memset(packed, 0, sizeof(wiegand_message_t));
if (card->FacilityCode > 0x007F) return false; // Can't encode FC. if (card->FacilityCode > 0x007F) return false; // Can't encode FC.
@ -204,7 +204,7 @@ bool Pack_D10202(wiegand_card_t* card, wiegand_message_t* packed){
return add_HID_header(packed); return add_HID_header(packed);
} }
bool Unpack_D10202(wiegand_message_t* packed, wiegand_card_t* card){ bool Unpack_D10202(wiegand_message_t *packed, wiegand_card_t *card) {
memset(card, 0, sizeof(wiegand_card_t)); memset(card, 0, sizeof(wiegand_card_t));
if (packed->Length != 33) return false; // Wrong length? Stop here. if (packed->Length != 33) return false; // Wrong length? Stop here.
@ -217,7 +217,7 @@ bool Unpack_D10202(wiegand_message_t* packed, wiegand_card_t* card){
return true; return true;
} }
bool Pack_H10306(wiegand_card_t* card, wiegand_message_t* packed){ bool Pack_H10306(wiegand_card_t *card, wiegand_message_t *packed) {
memset(packed, 0, sizeof(wiegand_message_t)); memset(packed, 0, sizeof(wiegand_message_t));
if (card->FacilityCode > 0xFFFF) return false; // Can't encode FC. if (card->FacilityCode > 0xFFFF) return false; // Can't encode FC.
@ -230,11 +230,11 @@ bool Pack_H10306(wiegand_card_t* card, wiegand_message_t* packed){
packed->Bot |= (card->FacilityCode & 0x7FFF) << 17; packed->Bot |= (card->FacilityCode & 0x7FFF) << 17;
packed->Mid |= (card->FacilityCode & 0x8000) >> 15; packed->Mid |= (card->FacilityCode & 0x8000) >> 15;
packed->Mid |= (evenparity32((packed->Mid & 0x00000001) ^ (packed->Bot & 0xFFFE0000)) & 1) << 1; packed->Mid |= (evenparity32((packed->Mid & 0x00000001) ^ (packed->Bot & 0xFFFE0000)) & 1) << 1;
packed->Bot |= ( oddparity32(packed->Bot & 0x0001FFFE) & 1); packed->Bot |= (oddparity32(packed->Bot & 0x0001FFFE) & 1);
return add_HID_header(packed); return add_HID_header(packed);
} }
bool Unpack_H10306(wiegand_message_t* packed, wiegand_card_t* card){ bool Unpack_H10306(wiegand_message_t *packed, wiegand_card_t *card) {
memset(card, 0, sizeof(wiegand_card_t)); memset(card, 0, sizeof(wiegand_card_t));
if (packed->Length != 34) return false; // Wrong length? Stop here. if (packed->Length != 34) return false; // Wrong length? Stop here.
@ -247,7 +247,7 @@ bool Unpack_H10306(wiegand_message_t* packed, wiegand_card_t* card){
return true; return true;
} }
bool Pack_N10002(wiegand_card_t* card, wiegand_message_t* packed){ bool Pack_N10002(wiegand_card_t *card, wiegand_message_t *packed) {
memset(packed, 0, sizeof(wiegand_message_t)); memset(packed, 0, sizeof(wiegand_message_t));
if (card->FacilityCode > 0xFF) return false; // Can't encode FC. if (card->FacilityCode > 0xFF) return false; // Can't encode FC.
@ -261,7 +261,7 @@ bool Pack_N10002(wiegand_card_t* card, wiegand_message_t* packed){
return add_HID_header(packed); return add_HID_header(packed);
} }
bool Unpack_N10002(wiegand_message_t* packed, wiegand_card_t* card){ bool Unpack_N10002(wiegand_message_t *packed, wiegand_card_t *card) {
memset(card, 0, sizeof(wiegand_card_t)); memset(card, 0, sizeof(wiegand_card_t));
if (packed->Length != 34) return false; // Wrong length? Stop here. if (packed->Length != 34) return false; // Wrong length? Stop here.
@ -271,7 +271,7 @@ bool Unpack_N10002(wiegand_message_t* packed, wiegand_card_t* card){
return true; return true;
} }
bool Pack_C1k35s(wiegand_card_t* card, wiegand_message_t* packed){ bool Pack_C1k35s(wiegand_card_t *card, wiegand_message_t *packed) {
memset(packed, 0, sizeof(wiegand_message_t)); memset(packed, 0, sizeof(wiegand_message_t));
if (card->FacilityCode > 0xFFF) return false; // Can't encode FC. if (card->FacilityCode > 0xFFF) return false; // Can't encode FC.
@ -284,12 +284,12 @@ bool Pack_C1k35s(wiegand_card_t* card, wiegand_message_t* packed){
packed->Bot |= (card->FacilityCode & 0x000007FF) << 21; packed->Bot |= (card->FacilityCode & 0x000007FF) << 21;
packed->Mid |= (card->FacilityCode & 0x00000800) >> 11; packed->Mid |= (card->FacilityCode & 0x00000800) >> 11;
packed->Mid |= (evenparity32((packed->Mid & 0x00000001) ^ (packed->Bot & 0xB6DB6DB6)) & 1) << 1; packed->Mid |= (evenparity32((packed->Mid & 0x00000001) ^ (packed->Bot & 0xB6DB6DB6)) & 1) << 1;
packed->Bot |= ( oddparity32((packed->Mid & 0x00000003) ^ (packed->Bot & 0x6DB6DB6C)) & 1); packed->Bot |= (oddparity32((packed->Mid & 0x00000003) ^ (packed->Bot & 0x6DB6DB6C)) & 1);
packed->Mid |= ( oddparity32((packed->Mid & 0x00000003) ^ (packed->Bot & 0xFFFFFFFF)) & 1) << 2; packed->Mid |= (oddparity32((packed->Mid & 0x00000003) ^ (packed->Bot & 0xFFFFFFFF)) & 1) << 2;
return add_HID_header(packed); return add_HID_header(packed);
} }
bool Unpack_C1k35s(wiegand_message_t* packed, wiegand_card_t* card){ bool Unpack_C1k35s(wiegand_message_t *packed, wiegand_card_t *card) {
memset(card, 0, sizeof(wiegand_card_t)); memset(card, 0, sizeof(wiegand_card_t));
if (packed->Length != 35) return false; // Wrong length? Stop here. if (packed->Length != 35) return false; // Wrong length? Stop here.
@ -298,12 +298,12 @@ bool Unpack_C1k35s(wiegand_message_t* packed, wiegand_card_t* card){
card->FacilityCode = ((packed->Mid & 1) << 11) | ((packed->Bot >> 21)); card->FacilityCode = ((packed->Mid & 1) << 11) | ((packed->Bot >> 21));
card->ParityValid = card->ParityValid =
(evenparity32((packed->Mid & 0x00000001) ^ (packed->Bot & 0xB6DB6DB6)) == ((packed->Mid >> 1) & 1)) && (evenparity32((packed->Mid & 0x00000001) ^ (packed->Bot & 0xB6DB6DB6)) == ((packed->Mid >> 1) & 1)) &&
( oddparity32((packed->Mid & 0x00000003) ^ (packed->Bot & 0x6DB6DB6C)) == ((packed->Bot >> 0) & 1)) && (oddparity32((packed->Mid & 0x00000003) ^ (packed->Bot & 0x6DB6DB6C)) == ((packed->Bot >> 0) & 1)) &&
( oddparity32((packed->Mid & 0x00000003) ^ (packed->Bot & 0xFFFFFFFF)) == ((packed->Mid >> 2) & 1)); (oddparity32((packed->Mid & 0x00000003) ^ (packed->Bot & 0xFFFFFFFF)) == ((packed->Mid >> 2) & 1));
return true; return true;
} }
bool Pack_H10320(wiegand_card_t* card, wiegand_message_t* packed){ bool Pack_H10320(wiegand_card_t *card, wiegand_message_t *packed) {
memset(packed, 0, sizeof(wiegand_message_t)); memset(packed, 0, sizeof(wiegand_message_t));
if (card->FacilityCode > 0) return false; // Can't encode FC. (none in this format) if (card->FacilityCode > 0) return false; // Can't encode FC. (none in this format)
@ -313,49 +313,49 @@ bool Pack_H10320(wiegand_card_t* card, wiegand_message_t* packed){
packed->Length = 36; // Set number of bits packed->Length = 36; // Set number of bits
// This card is BCD-encoded rather than binary. Set the 4-bit groups independently. // This card is BCD-encoded rather than binary. Set the 4-bit groups independently.
for (uint32_t idx = 0; idx < 8; idx++){ for (uint32_t idx = 0; idx < 8; idx++) {
set_linear_field(packed, (uint64_t)(card->CardNumber / pow(10, 7-idx)) % 10, idx * 4, 4); set_linear_field(packed, (uint64_t)(card->CardNumber / pow(10, 7 - idx)) % 10, idx * 4, 4);
} }
set_bit_by_position(packed, evenparity32( set_bit_by_position(packed, evenparity32(
get_nonlinear_field(packed, 8, (uint8_t[]){0, 4, 8, 12, 16, 20, 24, 28}) get_nonlinear_field(packed, 8, (uint8_t[]) {0, 4, 8, 12, 16, 20, 24, 28})
), 32); ), 32);
set_bit_by_position(packed, oddparity32( set_bit_by_position(packed, oddparity32(
get_nonlinear_field(packed, 8, (uint8_t[]){1, 5, 9, 13, 17, 21, 25, 29}) get_nonlinear_field(packed, 8, (uint8_t[]) {1, 5, 9, 13, 17, 21, 25, 29})
), 33); ), 33);
set_bit_by_position(packed, evenparity32( set_bit_by_position(packed, evenparity32(
get_nonlinear_field(packed, 8, (uint8_t[]){2, 6, 10, 14, 18, 22, 28, 30}) get_nonlinear_field(packed, 8, (uint8_t[]) {2, 6, 10, 14, 18, 22, 28, 30})
), 34); ), 34);
set_bit_by_position(packed, evenparity32( set_bit_by_position(packed, evenparity32(
get_nonlinear_field(packed, 8, (uint8_t[]){3, 7, 11, 15, 19, 23, 29, 31}) get_nonlinear_field(packed, 8, (uint8_t[]) {3, 7, 11, 15, 19, 23, 29, 31})
), 35); ), 35);
return add_HID_header(packed); return add_HID_header(packed);
} }
bool Unpack_H10320(wiegand_message_t* packed, wiegand_card_t* card){ bool Unpack_H10320(wiegand_message_t *packed, wiegand_card_t *card) {
memset(card, 0, sizeof(wiegand_card_t)); memset(card, 0, sizeof(wiegand_card_t));
if (packed->Length != 36) return false; // Wrong length? Stop here. if (packed->Length != 36) return false; // Wrong length? Stop here.
// This card is BCD-encoded rather than binary. Get the 4-bit groups independently. // This card is BCD-encoded rather than binary. Get the 4-bit groups independently.
for (uint32_t idx = 0; idx < 8; idx++){ for (uint32_t idx = 0; idx < 8; idx++) {
uint64_t val = get_linear_field(packed, idx * 4, 4); uint64_t val = get_linear_field(packed, idx * 4, 4);
if (val > 9){ if (val > 9) {
// Violation of BCD; Zero and exit. // Violation of BCD; Zero and exit.
card->CardNumber = 0; card->CardNumber = 0;
return false; return false;
} else { } else {
card->CardNumber += val * pow(10, 7-idx); card->CardNumber += val * pow(10, 7 - idx);
} }
} }
card->ParityValid = card->ParityValid =
(get_bit_by_position(packed, 32) == evenparity32(get_nonlinear_field(packed, 8, (uint8_t[]){0, 4, 8, 12, 16, 20, 24, 28}))) && (get_bit_by_position(packed, 32) == evenparity32(get_nonlinear_field(packed, 8, (uint8_t[]) {0, 4, 8, 12, 16, 20, 24, 28}))) &&
(get_bit_by_position(packed, 33) == oddparity32(get_nonlinear_field(packed, 8, (uint8_t[]){1, 5, 9, 13, 17, 21, 25, 29}))) && (get_bit_by_position(packed, 33) == oddparity32(get_nonlinear_field(packed, 8, (uint8_t[]) {1, 5, 9, 13, 17, 21, 25, 29}))) &&
(get_bit_by_position(packed, 34) == evenparity32(get_nonlinear_field(packed, 8, (uint8_t[]){2, 6, 10, 14, 18, 22, 28, 30}))) && (get_bit_by_position(packed, 34) == evenparity32(get_nonlinear_field(packed, 8, (uint8_t[]) {2, 6, 10, 14, 18, 22, 28, 30}))) &&
(get_bit_by_position(packed, 35) == evenparity32(get_nonlinear_field(packed, 8, (uint8_t[]){3, 7, 11, 15, 19, 23, 29, 31}))); (get_bit_by_position(packed, 35) == evenparity32(get_nonlinear_field(packed, 8, (uint8_t[]) {3, 7, 11, 15, 19, 23, 29, 31})));
return true; return true;
} }
bool Pack_S12906(wiegand_card_t* card, wiegand_message_t* packed){ bool Pack_S12906(wiegand_card_t *card, wiegand_message_t *packed) {
memset(packed, 0, sizeof(wiegand_message_t)); memset(packed, 0, sizeof(wiegand_message_t));
if (card->FacilityCode > 0xFF) return false; // Can't encode FC. if (card->FacilityCode > 0xFF) return false; // Can't encode FC.
@ -372,7 +372,7 @@ bool Pack_S12906(wiegand_card_t* card, wiegand_message_t* packed){
return add_HID_header(packed); return add_HID_header(packed);
} }
bool Unpack_S12906(wiegand_message_t* packed, wiegand_card_t* card){ bool Unpack_S12906(wiegand_message_t *packed, wiegand_card_t *card) {
memset(card, 0, sizeof(wiegand_card_t)); memset(card, 0, sizeof(wiegand_card_t));
if (packed->Length != 36) return false; // Wrong length? Stop here. if (packed->Length != 36) return false; // Wrong length? Stop here.
@ -386,7 +386,7 @@ bool Unpack_S12906(wiegand_message_t* packed, wiegand_card_t* card){
return true; return true;
} }
bool Pack_Sie36(wiegand_card_t* card, wiegand_message_t* packed){ bool Pack_Sie36(wiegand_card_t *card, wiegand_message_t *packed) {
memset(packed, 0, sizeof(wiegand_message_t)); memset(packed, 0, sizeof(wiegand_message_t));
if (card->FacilityCode > 0x0003FFFF) return false; // Can't encode FC. if (card->FacilityCode > 0x0003FFFF) return false; // Can't encode FC.
@ -398,15 +398,15 @@ bool Pack_Sie36(wiegand_card_t* card, wiegand_message_t* packed){
set_linear_field(packed, card->FacilityCode, 1, 18); set_linear_field(packed, card->FacilityCode, 1, 18);
set_linear_field(packed, card->CardNumber, 19, 16); set_linear_field(packed, card->CardNumber, 19, 16);
set_bit_by_position(packed, set_bit_by_position(packed,
oddparity32(get_nonlinear_field(packed, 23, (uint8_t[]){1, 3, 4, 6, 7, 9, 10, 12, 13, 15, 16, 18, 19, 21, 22, 24, 25, 27, 28, 30, 31, 33, 34})) oddparity32(get_nonlinear_field(packed, 23, (uint8_t[]) {1, 3, 4, 6, 7, 9, 10, 12, 13, 15, 16, 18, 19, 21, 22, 24, 25, 27, 28, 30, 31, 33, 34}))
, 0); , 0);
set_bit_by_position(packed, set_bit_by_position(packed,
evenparity32(get_nonlinear_field(packed, 23, (uint8_t[]){1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26, 28, 29, 31, 32, 34})) evenparity32(get_nonlinear_field(packed, 23, (uint8_t[]) {1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26, 28, 29, 31, 32, 34}))
, 35); , 35);
return add_HID_header(packed); return add_HID_header(packed);
} }
bool Unpack_Sie36(wiegand_message_t* packed, wiegand_card_t* card){ bool Unpack_Sie36(wiegand_message_t *packed, wiegand_card_t *card) {
memset(card, 0, sizeof(wiegand_card_t)); memset(card, 0, sizeof(wiegand_card_t));
if (packed->Length != 36) return false; // Wrong length? Stop here. if (packed->Length != 36) return false; // Wrong length? Stop here.
@ -414,12 +414,12 @@ bool Unpack_Sie36(wiegand_message_t* packed, wiegand_card_t* card){
card->FacilityCode = get_linear_field(packed, 1, 18); card->FacilityCode = get_linear_field(packed, 1, 18);
card->CardNumber = get_linear_field(packed, 19, 16); card->CardNumber = get_linear_field(packed, 19, 16);
card->ParityValid = card->ParityValid =
(get_bit_by_position(packed, 0) == oddparity32(get_nonlinear_field(packed, 23, (uint8_t[]){1, 3, 4, 6, 7, 9, 10, 12, 13, 15, 16, 18, 19, 21, 22, 24, 25, 27, 28, 30, 31, 33, 34}))) && (get_bit_by_position(packed, 0) == oddparity32(get_nonlinear_field(packed, 23, (uint8_t[]) {1, 3, 4, 6, 7, 9, 10, 12, 13, 15, 16, 18, 19, 21, 22, 24, 25, 27, 28, 30, 31, 33, 34}))) &&
(get_bit_by_position(packed, 35) == oddparity32(get_nonlinear_field(packed, 23, (uint8_t[]){1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26, 28, 29, 31, 32, 34}))); (get_bit_by_position(packed, 35) == oddparity32(get_nonlinear_field(packed, 23, (uint8_t[]) {1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26, 28, 29, 31, 32, 34})));
return true; return true;
} }
bool Pack_C15001(wiegand_card_t* card, wiegand_message_t* packed){ bool Pack_C15001(wiegand_card_t *card, wiegand_message_t *packed) {
memset(packed, 0, sizeof(wiegand_message_t)); memset(packed, 0, sizeof(wiegand_message_t));
if (card->FacilityCode > 0x000000FF) return false; // Can't encode FC. if (card->FacilityCode > 0x000000FF) return false; // Can't encode FC.
@ -436,7 +436,7 @@ bool Pack_C15001(wiegand_card_t* card, wiegand_message_t* packed){
return add_HID_header(packed); return add_HID_header(packed);
} }
bool Unpack_C15001(wiegand_message_t* packed, wiegand_card_t* card){ bool Unpack_C15001(wiegand_message_t *packed, wiegand_card_t *card) {
memset(card, 0, sizeof(wiegand_card_t)); memset(card, 0, sizeof(wiegand_card_t));
if (packed->Length != 36) return false; // Wrong length? Stop here. if (packed->Length != 36) return false; // Wrong length? Stop here.
@ -450,7 +450,7 @@ bool Unpack_C15001(wiegand_message_t* packed, wiegand_card_t* card){
return true; return true;
} }
bool Pack_H10302(wiegand_card_t* card, wiegand_message_t* packed){ bool Pack_H10302(wiegand_card_t *card, wiegand_message_t *packed) {
memset(packed, 0, sizeof(wiegand_message_t)); memset(packed, 0, sizeof(wiegand_message_t));
if (card->FacilityCode > 0) return false; // Can't encode FC. (none in this format) if (card->FacilityCode > 0) return false; // Can't encode FC. (none in this format)
@ -465,7 +465,7 @@ bool Pack_H10302(wiegand_card_t* card, wiegand_message_t* packed){
return add_HID_header(packed); return add_HID_header(packed);
} }
bool Unpack_H10302(wiegand_message_t* packed, wiegand_card_t* card){ bool Unpack_H10302(wiegand_message_t *packed, wiegand_card_t *card) {
memset(card, 0, sizeof(wiegand_card_t)); memset(card, 0, sizeof(wiegand_card_t));
if (packed->Length != 37) return false; // Wrong length? Stop here. if (packed->Length != 37) return false; // Wrong length? Stop here.
@ -477,7 +477,7 @@ bool Unpack_H10302(wiegand_message_t* packed, wiegand_card_t* card){
return true; return true;
} }
bool Pack_H10304(wiegand_card_t* card, wiegand_message_t* packed){ bool Pack_H10304(wiegand_card_t *card, wiegand_message_t *packed) {
memset(packed, 0, sizeof(wiegand_message_t)); memset(packed, 0, sizeof(wiegand_message_t));
if (card->FacilityCode > 0x0000FFFF) return false; // Can't encode FC. if (card->FacilityCode > 0x0000FFFF) return false; // Can't encode FC.
@ -490,11 +490,11 @@ bool Pack_H10304(wiegand_card_t* card, wiegand_message_t* packed){
packed->Bot |= (card->FacilityCode & 0x00000FFF) << 20; packed->Bot |= (card->FacilityCode & 0x00000FFF) << 20;
packed->Mid |= (card->FacilityCode & 0x0000F000) >> 12; packed->Mid |= (card->FacilityCode & 0x0000F000) >> 12;
packed->Mid |= (evenparity32((packed->Mid & 0x0000000F) ^ (packed->Bot & 0xFFFC0000)) & 1) << 4; packed->Mid |= (evenparity32((packed->Mid & 0x0000000F) ^ (packed->Bot & 0xFFFC0000)) & 1) << 4;
packed->Bot |= ( oddparity32(packed->Bot & 0x0007FFFE) & 1); packed->Bot |= (oddparity32(packed->Bot & 0x0007FFFE) & 1);
return add_HID_header(packed); return add_HID_header(packed);
} }
bool Unpack_H10304(wiegand_message_t* packed, wiegand_card_t* card){ bool Unpack_H10304(wiegand_message_t *packed, wiegand_card_t *card) {
memset(card, 0, sizeof(wiegand_card_t)); memset(card, 0, sizeof(wiegand_card_t));
if (packed->Length != 37) return false; // Wrong length? Stop here. if (packed->Length != 37) return false; // Wrong length? Stop here.
@ -503,11 +503,11 @@ bool Unpack_H10304(wiegand_message_t* packed, wiegand_card_t* card){
card->FacilityCode = ((packed->Mid & 0xF) << 12) | ((packed->Bot >> 20)); card->FacilityCode = ((packed->Mid & 0xF) << 12) | ((packed->Bot >> 20));
card->ParityValid = card->ParityValid =
(evenparity32((packed->Mid & 0x0000000F) ^ (packed->Bot & 0xFFFC0000)) == ((packed->Mid >> 4) & 1)) && (evenparity32((packed->Mid & 0x0000000F) ^ (packed->Bot & 0xFFFC0000)) == ((packed->Mid >> 4) & 1)) &&
(oddparity32( packed->Bot & 0x0007FFFE) == (packed->Bot & 1)); (oddparity32(packed->Bot & 0x0007FFFE) == (packed->Bot & 1));
return true; return true;
} }
bool Pack_P10001(wiegand_card_t* card, wiegand_message_t* packed){ bool Pack_P10001(wiegand_card_t *card, wiegand_message_t *packed) {
memset(packed, 0, sizeof(wiegand_message_t)); memset(packed, 0, sizeof(wiegand_message_t));
@ -529,7 +529,7 @@ bool Pack_P10001(wiegand_card_t* card, wiegand_message_t* packed){
return add_HID_header(packed); return add_HID_header(packed);
} }
bool Unpack_P10001(wiegand_message_t* packed, wiegand_card_t* card){ bool Unpack_P10001(wiegand_message_t *packed, wiegand_card_t *card) {
memset(card, 0, sizeof(wiegand_card_t)); memset(card, 0, sizeof(wiegand_card_t));
@ -546,7 +546,7 @@ bool Unpack_P10001(wiegand_message_t* packed, wiegand_card_t* card){
return true; return true;
} }
bool Pack_C1k48s(wiegand_card_t* card, wiegand_message_t* packed){ bool Pack_C1k48s(wiegand_card_t *card, wiegand_message_t *packed) {
memset(packed, 0, sizeof(wiegand_message_t)); memset(packed, 0, sizeof(wiegand_message_t));
@ -560,12 +560,12 @@ bool Pack_C1k48s(wiegand_card_t* card, wiegand_message_t* packed){
packed->Bot |= (card->FacilityCode & 0x000000FF) << 24; packed->Bot |= (card->FacilityCode & 0x000000FF) << 24;
packed->Mid |= (card->FacilityCode & 0x003FFF00) >> 8; packed->Mid |= (card->FacilityCode & 0x003FFF00) >> 8;
packed->Mid |= (evenparity32((packed->Mid & 0x00001B6D) ^ (packed->Bot & 0xB6DB6DB6)) & 1) << 14; packed->Mid |= (evenparity32((packed->Mid & 0x00001B6D) ^ (packed->Bot & 0xB6DB6DB6)) & 1) << 14;
packed->Bot |= ( oddparity32((packed->Mid & 0x000036DB) ^ (packed->Bot & 0x6DB6DB6C)) & 1); packed->Bot |= (oddparity32((packed->Mid & 0x000036DB) ^ (packed->Bot & 0x6DB6DB6C)) & 1);
packed->Mid |= ( oddparity32((packed->Mid & 0x00007FFF) ^ (packed->Bot & 0xFFFFFFFF)) & 1) << 15; packed->Mid |= (oddparity32((packed->Mid & 0x00007FFF) ^ (packed->Bot & 0xFFFFFFFF)) & 1) << 15;
return add_HID_header(packed); return add_HID_header(packed);
} }
bool Unpack_C1k48s(wiegand_message_t* packed, wiegand_card_t* card){ bool Unpack_C1k48s(wiegand_message_t *packed, wiegand_card_t *card) {
memset(card, 0, sizeof(wiegand_card_t)); memset(card, 0, sizeof(wiegand_card_t));
if (packed->Length != 48) return false; // Wrong length? Stop here. if (packed->Length != 48) return false; // Wrong length? Stop here.
@ -574,8 +574,8 @@ bool Unpack_C1k48s(wiegand_message_t* packed, wiegand_card_t* card){
card->FacilityCode = ((packed->Mid & 0x00003FFF) << 8) | ((packed->Bot >> 24)); card->FacilityCode = ((packed->Mid & 0x00003FFF) << 8) | ((packed->Bot >> 24));
card->ParityValid = card->ParityValid =
(evenparity32((packed->Mid & 0x00001B6D) ^ (packed->Bot & 0xB6DB6DB6)) == ((packed->Mid >> 14) & 1)) && (evenparity32((packed->Mid & 0x00001B6D) ^ (packed->Bot & 0xB6DB6DB6)) == ((packed->Mid >> 14) & 1)) &&
( oddparity32((packed->Mid & 0x000036DB) ^ (packed->Bot & 0x6DB6DB6C)) == ((packed->Bot >> 0) & 1)) && (oddparity32((packed->Mid & 0x000036DB) ^ (packed->Bot & 0x6DB6DB6C)) == ((packed->Bot >> 0) & 1)) &&
( oddparity32((packed->Mid & 0x00007FFF) ^ (packed->Bot & 0xFFFFFFFF)) == ((packed->Mid >> 15) & 1)); (oddparity32((packed->Mid & 0x00007FFF) ^ (packed->Bot & 0xFFFFFFFF)) == ((packed->Mid >> 15) & 1));
return true; return true;
} }
@ -601,7 +601,7 @@ static const cardformat_t FormatTable[] = {
{NULL, NULL, NULL, NULL, {0, 0, 0, 0, 0}} // Must null terminate array {NULL, NULL, NULL, NULL, {0, 0, 0, 0, 0}} // Must null terminate array
}; };
void HIDListFormats(){ void HIDListFormats() {
if (FormatTable[0].Name == NULL) if (FormatTable[0].Name == NULL)
return; return;
@ -617,7 +617,7 @@ void HIDListFormats(){
return; return;
} }
cardformat_t HIDGetCardFormat(int idx){ cardformat_t HIDGetCardFormat(int idx) {
return FormatTable[idx]; return FormatTable[idx];
} }
@ -640,7 +640,7 @@ int HIDFindCardFormat(const char *format) {
return -1; return -1;
} }
bool HIDPack(int format_idx, wiegand_card_t* card, wiegand_message_t* packed){ bool HIDPack(int format_idx, wiegand_card_t *card, wiegand_message_t *packed) {
memset(packed, 0, sizeof(wiegand_message_t)); memset(packed, 0, sizeof(wiegand_message_t));
if (format_idx < 0 || format_idx >= (sizeof(FormatTable) / sizeof(FormatTable[0]))) if (format_idx < 0 || format_idx >= (sizeof(FormatTable) / sizeof(FormatTable[0])))
@ -649,9 +649,9 @@ bool HIDPack(int format_idx, wiegand_card_t* card, wiegand_message_t* packed){
return FormatTable[format_idx].Pack(card, packed); return FormatTable[format_idx].Pack(card, packed);
} }
void HIDDisplayUnpackedCard(wiegand_card_t* card, const cardformat_t format){ void HIDDisplayUnpackedCard(wiegand_card_t *card, const cardformat_t format) {
/* /*
PrintAndLogEx(SUCCESS, " Format: %s (%s)", format.Name, format.Descrp); PrintAndLogEx(SUCCESS, " Format: %s (%s)", format.Name, format.Descrp);
if (format.Fields.hasFacilityCode) if (format.Fields.hasFacilityCode)
@ -668,7 +668,7 @@ void HIDDisplayUnpackedCard(wiegand_card_t* card, const cardformat_t format){
if (format.Fields.hasParity) if (format.Fields.hasParity)
PrintAndLogEx(SUCCESS, " Parity: %s",card->ParityValid ? "Valid" : "Invalid"); PrintAndLogEx(SUCCESS, " Parity: %s",card->ParityValid ? "Valid" : "Invalid");
*/ */
char s[80] = {0}; char s[80] = {0};
if (format.Fields.hasFacilityCode) if (format.Fields.hasFacilityCode)
@ -681,7 +681,7 @@ void HIDDisplayUnpackedCard(wiegand_card_t* card, const cardformat_t format){
snprintf(s + strlen(s), sizeof(s) - strlen(s), " Issue %d", card->IssueLevel); snprintf(s + strlen(s), sizeof(s) - strlen(s), " Issue %d", card->IssueLevel);
if (format.Fields.hasOEMCode) if (format.Fields.hasOEMCode)
snprintf(s + strlen(s), sizeof(s) - strlen(s), " OEM: %d",card->OEM); snprintf(s + strlen(s), sizeof(s) - strlen(s), " OEM: %d", card->OEM);
if (format.Fields.hasParity) if (format.Fields.hasParity)
snprintf(s + strlen(s), sizeof(s) - strlen(s), " parity: %s", card->ParityValid ? "valid" : "invalid"); snprintf(s + strlen(s), sizeof(s) - strlen(s), " parity: %s", card->ParityValid ? "valid" : "invalid");
@ -689,7 +689,7 @@ void HIDDisplayUnpackedCard(wiegand_card_t* card, const cardformat_t format){
PrintAndLogEx(SUCCESS, "%s [%s - %s]", s, format.Name, format.Descrp); PrintAndLogEx(SUCCESS, "%s [%s - %s]", s, format.Name, format.Descrp);
} }
bool HIDTryUnpack(wiegand_message_t* packed, bool ignore_parity){ bool HIDTryUnpack(wiegand_message_t *packed, bool ignore_parity) {
if (FormatTable[0].Name == NULL) if (FormatTable[0].Name == NULL)
return false; return false;
@ -707,7 +707,7 @@ bool HIDTryUnpack(wiegand_message_t* packed, bool ignore_parity){
} }
++i; ++i;
} }
if ( result == false ) { if (result == false) {
PrintAndLogEx(SUCCESS, "Unknown. Bit len %d", packed->Length); PrintAndLogEx(SUCCESS, "Unknown. Bit len %d", packed->Length);
} }

View file

@ -32,17 +32,17 @@ typedef struct {
// 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,7 +15,7 @@
#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;
@ -29,7 +29,7 @@ bool get_bit_by_position(wiegand_message_t* data, uint8_t pos){
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) {
@ -64,7 +64,7 @@ bool set_bit_by_position(wiegand_message_t* data, bool value, uint8_t pos){
* 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;
@ -77,18 +77,18 @@ void message_datacopy(wiegand_message_t* src, wiegand_message_t* dest){
* 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; wiegand_message_t tmpdata;
message_datacopy(data, &tmpdata); message_datacopy(data, &tmpdata);
bool result = true; bool result = true;
for (int i = 0; i < length; i++){ for (int i = 0; i < length; i++) {
result &= set_bit_by_position(&tmpdata, (value >> ((length - i) - 1)) & 1, firstBit + i); result &= set_bit_by_position(&tmpdata, (value >> ((length - i) - 1)) & 1, firstBit + i);
} }
if (result) if (result)
@ -97,20 +97,20 @@ bool set_linear_field(wiegand_message_t* data, uint64_t value, uint8_t firstBit,
return result; return result;
} }
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) {
uint64_t result = 0; uint64_t result = 0;
for (int i = 0; i < numBits; i++){ for (int i = 0; i < numBits; i++) {
result = (result << 1) | (get_bit_by_position(data, *(bits+i)) & 1); result = (result << 1) | (get_bit_by_position(data, *(bits + i)) & 1);
} }
return result; return result;
} }
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 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 < numBits; i++) {
result &= set_bit_by_position(&tmpdata, (value >> ((numBits - i) - 1)) & 1, *(bits + i)); result &= set_bit_by_position(&tmpdata, (value >> ((numBits - i) - 1)) & 1, *(bits + i));
} }
@ -120,7 +120,7 @@ bool set_nonlinear_field(wiegand_message_t* data, uint64_t value, uint8_t numBit
return result; return result;
} }
uint8_t get_length_from_header(wiegand_message_t* data) { uint8_t get_length_from_header(wiegand_message_t *data) {
uint8_t len = 0; uint8_t len = 0;
uint32_t hfmt = 0; // for calculating card length uint32_t hfmt = 0; // for calculating card length
@ -133,7 +133,7 @@ uint8_t get_length_from_header(wiegand_message_t* data) {
} else if (data->Mid && (data->Mid & 0x00000020) == 0) { // 37 bits; } else if (data->Mid && (data->Mid & 0x00000020) == 0) { // 37 bits;
hfmt = 0; hfmt = 0;
len = 37; len = 37;
} else if ((data->Mid & 0x0000001F) > 0){ // 36-32 bits } else if ((data->Mid & 0x0000001F) > 0) { // 36-32 bits
printf("a\n"); printf("a\n");
hfmt = data->Mid & 0x0000001F; hfmt = data->Mid & 0x0000001F;
len = 32; len = 32;
@ -152,7 +152,7 @@ uint8_t get_length_from_header(wiegand_message_t* data) {
return len; return len;
} }
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) {
wiegand_message_t result; wiegand_message_t result;
memset(&result, 0, sizeof(wiegand_message_t)); memset(&result, 0, sizeof(wiegand_message_t));
@ -163,18 +163,18 @@ wiegand_message_t initialize_message_object(uint32_t top, uint32_t mid, uint32_t
return result; return result;
} }
bool add_HID_header(wiegand_message_t* data){ bool add_HID_header(wiegand_message_t *data) {
if (data->Length > 84 || data->Length == 0) return false; // Invalid value if (data->Length > 84 || data->Length == 0) return false; // Invalid value
if (data->Length >= 64){ if (data->Length >= 64) {
data->Top |= 1 << (data->Length - 64); // leading 1: start bit data->Top |= 1 << (data->Length - 64); // leading 1: start bit
data->Top |= 0x09e00000; // Extended-length header data->Top |= 0x09e00000; // Extended-length header
} else if (data->Length > 37){ } else if (data->Length > 37) {
data->Mid |= 1 << (data->Length - 32); // leading 1: start bit data->Mid |= 1 << (data->Length - 32); // leading 1: start bit
data->Top |= 0x09e00000; // Extended-length header data->Top |= 0x09e00000; // Extended-length header
} else if (data->Length == 37){ } else if (data->Length == 37) {
// No header bits added to 37-bit cards // No header bits added to 37-bit cards
} else if (data->Length >= 32){ } else if (data->Length >= 32) {
data->Mid |= 0x20; // Bit 37; standard header data->Mid |= 0x20; // Bit 37; standard header
data->Mid |= 1 << (data->Length - 32); // leading 1: start bit data->Mid |= 1 << (data->Length - 32); // leading 1: start bit
} else { } else {

View file

@ -33,17 +33,17 @@ typedef struct {
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