make style

This commit is contained in:
Philippe Teuwen 2019-03-10 00:00:59 +01:00
commit 0373696662
483 changed files with 56514 additions and 52451 deletions

View file

@ -14,7 +14,8 @@
static int CmdHelp(const char *Cmd);
int usage_lf_awid_read(void) {
int usage_lf_awid_read(void)
{
PrintAndLogEx(NORMAL, "Enables AWID compatible reader mode printing details of scanned AWID26 or AWID50 tags.");
PrintAndLogEx(NORMAL, "By default, values are printed and logged until the button is pressed or another USB command is issued.");
PrintAndLogEx(NORMAL, "If the [1] option is provided, reader mode is exited after reading a single AWID card.");
@ -30,7 +31,8 @@ int usage_lf_awid_read(void) {
return 0;
}
int usage_lf_awid_sim(void) {
int usage_lf_awid_sim(void)
{
PrintAndLogEx(NORMAL, "Enables simulation of AWID card with specified facility-code and card number.");
PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued.");
PrintAndLogEx(NORMAL, "");
@ -47,7 +49,8 @@ int usage_lf_awid_sim(void) {
return 0;
}
int usage_lf_awid_clone(void) {
int usage_lf_awid_clone(void)
{
PrintAndLogEx(NORMAL, "Enables cloning of AWID card with specified facility-code and card number onto T55x7.");
PrintAndLogEx(NORMAL, "The T55x7 must be on the antenna when issuing this command. T55x7 blocks are calculated and printed in the process.");
PrintAndLogEx(NORMAL, "");
@ -65,7 +68,8 @@ int usage_lf_awid_clone(void) {
return 0;
}
int usage_lf_awid_brute(void){
int usage_lf_awid_brute(void)
{
PrintAndLogEx(NORMAL, "Enables bruteforce of AWID reader with specified facility-code.");
PrintAndLogEx(NORMAL, "This is a attack against reader. if cardnumber is given, it starts with it and goes up / down one step");
PrintAndLogEx(NORMAL, "if cardnumber is not given, it starts with 1 and goes up to 65535");
@ -86,7 +90,8 @@ int usage_lf_awid_brute(void){
return 0;
}
static bool sendPing(void){
static bool sendPing(void)
{
UsbCommand ping = {CMD_PING, {1, 2, 3}};
SendCommand(&ping);
SendCommand(&ping);
@ -98,12 +103,13 @@ static bool sendPing(void){
return true;
}
static bool sendTry(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint32_t delay, uint8_t *bits, size_t bs_len, bool verbose){
static bool sendTry(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint32_t delay, uint8_t *bits, size_t bs_len, bool verbose)
{
if ( verbose )
if (verbose)
PrintAndLogEx(INFO, "Trying FC: %u; CN: %u", fc, cn);
if ( !getAWIDBits(fmtlen, fc, cn, bits)) {
if (!getAWIDBits(fmtlen, fc, cn, bits)) {
PrintAndLogEx(WARNING, "Error with tag bitstream generation.");
return false;
}
@ -123,7 +129,8 @@ static bool sendTry(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint32_t delay, ui
}
//refactored by marshmellow
int getAWIDBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *bits) {
int getAWIDBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *bits)
{
// the return bits, preamble 0000 0001
bits[7] = 1;
@ -136,38 +143,38 @@ int getAWIDBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *bits) {
// add facilitycode, cardnumber and wiegand parity bits
switch (fmtlen) {
case 26:{
case 26: {
uint8_t wiegand[24];
num_to_bytebits(fc, 8, wiegand);
num_to_bytebits(cn, 16, wiegand+8);
wiegand_add_parity(pre+8, wiegand, sizeof(wiegand));
num_to_bytebits(cn, 16, wiegand + 8);
wiegand_add_parity(pre + 8, wiegand, sizeof(wiegand));
break;
}
case 34:{
case 34: {
uint8_t wiegand[32];
num_to_bytebits(fc, 8, wiegand);
num_to_bytebits(cn, 24, wiegand+8);
wiegand_add_parity(pre+8, wiegand, sizeof(wiegand));
num_to_bytebits(cn, 24, wiegand + 8);
wiegand_add_parity(pre + 8, wiegand, sizeof(wiegand));
break;
}
case 37:{
case 37: {
uint8_t wiegand[31];
num_to_bytebits(fc, 13, wiegand);
num_to_bytebits(cn, 18, wiegand+13);
wiegand_add_parity(pre+8, wiegand, sizeof(wiegand));
num_to_bytebits(cn, 18, wiegand + 13);
wiegand_add_parity(pre + 8, wiegand, sizeof(wiegand));
break;
}
case 50: {
uint8_t wiegand[48];
num_to_bytebits(fc, 16, wiegand);
num_to_bytebits(cn, 32, wiegand+16);
wiegand_add_parity(pre+8, wiegand, sizeof(wiegand));
num_to_bytebits(cn, 32, wiegand + 16);
wiegand_add_parity(pre + 8, wiegand, sizeof(wiegand));
break;
}
}
// add AWID 4bit parity
size_t bitLen = addParity(pre, bits+8, 66, 4, 1);
size_t bitLen = addParity(pre, bits + 8, 66, 4, 1);
if (bitLen != 88) return 0;
@ -176,7 +183,8 @@ int getAWIDBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *bits) {
return 1;
}
static void verify_values(uint8_t *fmtlen, uint32_t *fc, uint32_t *cn){
static void verify_values(uint8_t *fmtlen, uint32_t *fc, uint32_t *cn)
{
switch (*fmtlen) {
case 50:
if ((*fc & 0xFFFF) != *fc) {
@ -220,13 +228,15 @@ static void verify_values(uint8_t *fmtlen, uint32_t *fc, uint32_t *cn){
}
// this read is the "normal" read, which download lf signal and tries to demod here.
int CmdAWIDRead(const char *Cmd) {
int CmdAWIDRead(const char *Cmd)
{
lf_read(true, 12000);
return CmdAWIDDemod(Cmd);
}
// this read loops on device side.
// uses the demod in lfops.c
int CmdAWIDRead_device(const char *Cmd) {
int CmdAWIDRead_device(const char *Cmd)
{
if (Cmd[0] == 'h' || Cmd[0] == 'H') return usage_lf_awid_read();
uint8_t findone = (Cmd[0] == '1') ? 1 : 0;
@ -239,8 +249,9 @@ int CmdAWIDRead_device(const char *Cmd) {
//by marshmellow
//AWID Prox demod - FSK2a RF/50 with preamble of 00000001 (always a 96 bit data stream)
//print full AWID Prox ID and some bit format details if found
int CmdAWIDDemod(const char *Cmd) {
uint8_t bits[MAX_GRAPH_TRACE_LEN]={0};
int CmdAWIDDemod(const char *Cmd)
{
uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0};
size_t size = getFromGraphBuf(bits);
if (size == 0) {
PrintAndLogEx(DEBUG, "DEBUG: Error - AWID not enough samples");
@ -249,7 +260,7 @@ int CmdAWIDDemod(const char *Cmd) {
//get binary from fsk wave
int waveIdx = 0;
int idx = detectAWID(bits, &size, &waveIdx);
if (idx <= 0){
if (idx <= 0) {
if (idx == -1)
PrintAndLogEx(DEBUG, "DEBUG: Error - AWID not enough samples");
@ -262,13 +273,13 @@ int CmdAWIDDemod(const char *Cmd) {
else if (idx == -5)
PrintAndLogEx(DEBUG, "DEBUG: Error - AWID size not correct, size %d", size);
else
PrintAndLogEx(DEBUG, "DEBUG: Error - AWID error demoding fsk %d",idx);
PrintAndLogEx(DEBUG, "DEBUG: Error - AWID error demoding fsk %d", idx);
return 0;
}
setDemodBuf(bits, size, idx);
setClockGrid(50, waveIdx + (idx*50));
setClockGrid(50, waveIdx + (idx * 50));
// Index map
@ -289,7 +300,7 @@ int CmdAWIDDemod(const char *Cmd) {
uint32_t rawHi = bytebits_to_byte(bits + idx + 32, 32);
uint32_t rawHi2 = bytebits_to_byte(bits + idx, 32);
size = removeParity(bits, idx+8, 4, 1, 88);
size = removeParity(bits, idx + 8, 4, 1, 88);
if (size != 66) {
PrintAndLogEx(DEBUG, "DEBUG: Error - AWID at parity check-tag size does not match AWID format");
return 0;
@ -318,25 +329,25 @@ int CmdAWIDDemod(const char *Cmd) {
uint32_t code2 = 0;
uint8_t fmtLen = bytebits_to_byte(bits, 8);
switch(fmtLen) {
switch (fmtLen) {
case 26:
fc = bytebits_to_byte(bits + 9, 8);
cardnum = bytebits_to_byte(bits + 17, 16);
code1 = bytebits_to_byte(bits + 8,fmtLen);
code1 = bytebits_to_byte(bits + 8, fmtLen);
PrintAndLogEx(SUCCESS, "AWID Found - BitLength: %d, FC: %d, Card: %u - Wiegand: %x, Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, rawHi2, rawHi, rawLo);
break;
case 34:
fc = bytebits_to_byte(bits + 9, 8);
cardnum = bytebits_to_byte(bits + 17, 24);
code1 = bytebits_to_byte(bits + 8, (fmtLen-32) );
code2 = bytebits_to_byte(bits + 8 + (fmtLen-32), 32);
code1 = bytebits_to_byte(bits + 8, (fmtLen - 32));
code2 = bytebits_to_byte(bits + 8 + (fmtLen - 32), 32);
PrintAndLogEx(SUCCESS, "AWID Found - BitLength: %d, FC: %d, Card: %u - Wiegand: %x%08x, Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, code2, rawHi2, rawHi, rawLo);
break;
case 37:
fc = bytebits_to_byte(bits + 9, 13);
cardnum = bytebits_to_byte(bits + 22, 18);
code1 = bytebits_to_byte(bits + 8, (fmtLen-32) );
code2 = bytebits_to_byte(bits + 8 + (fmtLen-32), 32);
code1 = bytebits_to_byte(bits + 8, (fmtLen - 32));
code2 = bytebits_to_byte(bits + 8 + (fmtLen - 32), 32);
PrintAndLogEx(SUCCESS, "AWID Found - BitLength: %d, FC: %d, Card: %u - Wiegand: %x%08x, Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, code2, rawHi2, rawHi, rawLo);
break;
// case 40:
@ -344,18 +355,18 @@ int CmdAWIDDemod(const char *Cmd) {
case 50:
fc = bytebits_to_byte(bits + 9, 16);
cardnum = bytebits_to_byte(bits + 25, 32);
code1 = bytebits_to_byte(bits + 8, (fmtLen-32) );
code2 = bytebits_to_byte(bits + 8 + (fmtLen-32), 32);
code1 = bytebits_to_byte(bits + 8, (fmtLen - 32));
code2 = bytebits_to_byte(bits + 8 + (fmtLen - 32), 32);
PrintAndLogEx(SUCCESS, "AWID Found - BitLength: %d, FC: %d, Card: %u - Wiegand: %x%08x, Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, code2, rawHi2, rawHi, rawLo);
break;
default:
if (fmtLen > 32 ) {
cardnum = bytebits_to_byte(bits + 8 + (fmtLen-17), 16);
code1 = bytebits_to_byte(bits + 8, fmtLen-32);
code2 = bytebits_to_byte(bits + 8 + (fmtLen-32), 32);
if (fmtLen > 32) {
cardnum = bytebits_to_byte(bits + 8 + (fmtLen - 17), 16);
code1 = bytebits_to_byte(bits + 8, fmtLen - 32);
code2 = bytebits_to_byte(bits + 8 + (fmtLen - 32), 32);
PrintAndLogEx(SUCCESS, "AWID Found - BitLength: %d -unknown BitLength- (%u) - Wiegand: %x%08x, Raw: %08x%08x%08x", fmtLen, cardnum, code1, code2, rawHi2, rawHi, rawLo);
} else {
cardnum = bytebits_to_byte(bits + 8 + (fmtLen-17), 16);
cardnum = bytebits_to_byte(bits + 8 + (fmtLen - 17), 16);
code1 = bytebits_to_byte(bits + 8, fmtLen);
PrintAndLogEx(SUCCESS, "AWID Found - BitLength: %d -unknown BitLength- (%u) - Wiegand: %x, Raw: %08x%08x%08x", fmtLen, cardnum, code1, rawHi2, rawHi, rawLo);
}
@ -369,7 +380,8 @@ int CmdAWIDDemod(const char *Cmd) {
return 1;
}
int CmdAWIDSim(const char *Cmd) {
int CmdAWIDSim(const char *Cmd)
{
uint32_t fc = 0, cn = 0;
uint8_t fmtlen = 0;
uint8_t bits[96];
@ -382,7 +394,7 @@ int CmdAWIDSim(const char *Cmd) {
fmtlen = param_get8(Cmd, 0);
fc = param_get32ex(Cmd, 1, 0, 10);
cn = param_get32ex(Cmd, 2, 0, 10);
if ( !fc || !cn) return usage_lf_awid_sim();
if (!fc || !cn) return usage_lf_awid_sim();
verify_values(&fmtlen, &fc, &cn);
@ -409,13 +421,14 @@ int CmdAWIDSim(const char *Cmd) {
return 0;
}
int CmdAWIDClone(const char *Cmd) {
uint32_t blocks[4] = {T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_50 | 3<<T55x7_MAXBLOCK_SHIFT, 0, 0, 0};
int CmdAWIDClone(const char *Cmd)
{
uint32_t blocks[4] = {T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_50 | 3 << T55x7_MAXBLOCK_SHIFT, 0, 0, 0};
uint32_t fc = 0, cn = 0;
uint8_t fmtlen = 0;
uint8_t bits[96];
uint8_t *bs=bits;
memset(bs,0,sizeof(bits));
uint8_t *bs = bits;
memset(bs, 0, sizeof(bits));
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) == 0 || cmdp == 'h') return usage_lf_awid_clone();
@ -424,15 +437,15 @@ int CmdAWIDClone(const char *Cmd) {
fc = param_get32ex(Cmd, 1, 0, 10);
cn = param_get32ex(Cmd, 2, 0, 10);
if ( !fc || !cn) return usage_lf_awid_clone();
if (!fc || !cn) return usage_lf_awid_clone();
if (tolower(param_getchar(Cmd, 3)) == 'q')
//t5555 (Q5) BITRATE = (RF-2)/2 (iceman)
blocks[0] = T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | T5555_SET_BITRATE(50) | 3<<T5555_MAXBLOCK_SHIFT;
blocks[0] = T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | T5555_SET_BITRATE(50) | 3 << T5555_MAXBLOCK_SHIFT;
verify_values(&fmtlen, &fc, &cn);
if ( !getAWIDBits(fmtlen, fc, cn, bs)) {
if (!getAWIDBits(fmtlen, fc, cn, bs)) {
PrintAndLogEx(WARNING, "Error with tag bitstream generation.");
return 1;
}
@ -445,14 +458,14 @@ int CmdAWIDClone(const char *Cmd) {
print_blocks(blocks, 4);
UsbCommand resp;
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}};
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0, 0, 0}};
for (uint8_t i=0; i<4; i++) {
for (uint8_t i = 0; i < 4; i++) {
c.arg[0] = blocks[i];
c.arg[1] = i;
clearCommandBuffer();
SendCommand(&c);
if (!WaitForResponseTimeout(CMD_ACK, &resp, T55XX_WRITE_TIMEOUT)){
if (!WaitForResponseTimeout(CMD_ACK, &resp, T55XX_WRITE_TIMEOUT)) {
PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation.");
return -1;
}
@ -460,7 +473,8 @@ int CmdAWIDClone(const char *Cmd) {
return 0;
}
int CmdAWIDBrute(const char *Cmd) {
int CmdAWIDBrute(const char *Cmd)
{
bool errors = false, verbose = false;
uint32_t fc = 0, cn = 0, delay = 1000;
@ -471,45 +485,45 @@ int CmdAWIDBrute(const char *Cmd) {
uint8_t cmdp = 0;
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch ( tolower(param_getchar(Cmd, cmdp))) {
case 'h':
return usage_lf_awid_brute();
case 'f':
fc = param_get32ex(Cmd ,cmdp+1, 0, 10);
if ( !fc )
switch (tolower(param_getchar(Cmd, cmdp))) {
case 'h':
return usage_lf_awid_brute();
case 'f':
fc = param_get32ex(Cmd, cmdp + 1, 0, 10);
if (!fc)
errors = true;
cmdp += 2;
break;
case 'd':
// delay between attemps, defaults to 1000ms.
delay = param_get32ex(Cmd, cmdp + 1, 1000, 10);
cmdp += 2;
break;
case 'c':
cn = param_get32ex(Cmd, cmdp + 1, 0, 10);
// truncate cardnumber.
cn &= 0xFFFF;
cmdp += 2;
break;
case 'a':
fmtlen = param_get8(Cmd, cmdp + 1);
cmdp += 2;
break;
case 'v':
verbose = true;
cmdp++;
break;
default:
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
errors = true;
cmdp += 2;
break;
case 'd':
// delay between attemps, defaults to 1000ms.
delay = param_get32ex(Cmd, cmdp+1, 1000, 10);
cmdp += 2;
break;
case 'c':
cn = param_get32ex(Cmd, cmdp+1, 0, 10);
// truncate cardnumber.
cn &= 0xFFFF;
cmdp += 2;
break;
case 'a':
fmtlen = param_get8(Cmd, cmdp+1);
cmdp += 2;
break;
case 'v':
verbose = true;
cmdp++;
break;
default:
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
errors = true;
break;
break;
}
}
if ( fc == 0 ) errors = true;
if ( errors ) return usage_lf_awid_brute();
if (fc == 0) errors = true;
if (errors) return usage_lf_awid_brute();
// limit fc according to selected format
switch(fmtlen) {
switch (fmtlen) {
case 50:
if ((fc & 0xFFFF) != fc) {
fc &= 0xFFFF;
@ -531,26 +545,27 @@ int CmdAWIDBrute(const char *Cmd) {
uint16_t down = cn;
// main loop
for (;;){
for (;;) {
if ( IsOffline() ) {
if (IsOffline()) {
PrintAndLogEx(WARNING, "Device offline\n");
return 2;
}
if (ukbhit()) {
int gc = getchar(); (void)gc;
int gc = getchar();
(void)gc;
PrintAndLogEx(INFO, "aborted via keyboard!");
return sendPing();
}
// Do one up
if ( up < 0xFFFF )
if ( !sendTry(fmtlen, fc, up++, delay, bits, size, verbose)) return 1;
if (up < 0xFFFF)
if (!sendTry(fmtlen, fc, up++, delay, bits, size, verbose)) return 1;
// Do one down (if cardnumber is given)
if ( cn > 1 )
if ( down > 1 )
if ( !sendTry(fmtlen, fc, --down, delay, bits, size, verbose)) return 1;
if (cn > 1)
if (down > 1)
if (!sendTry(fmtlen, fc, --down, delay, bits, size, verbose)) return 1;
}
return 0;
}
@ -565,13 +580,15 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFAWID(const char *Cmd) {
int CmdLFAWID(const char *Cmd)
{
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd) {
int CmdHelp(const char *Cmd)
{
CmdsHelp(CommandTable);
return 0;
}