make style

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

View File

@@ -15,7 +15,8 @@
static int CmdHelp(const char *Cmd);
int usage_lf_visa2k_clone(void){
int usage_lf_visa2k_clone(void)
{
PrintAndLogEx(NORMAL, "clone a Visa2000 tag to a T55x7 tag.");
PrintAndLogEx(NORMAL, "Usage: lf visa2000 clone [h] <card ID> <Q5>");
PrintAndLogEx(NORMAL, "Options:");
@@ -28,7 +29,8 @@ int usage_lf_visa2k_clone(void){
return 0;
}
int usage_lf_visa2k_sim(void) {
int usage_lf_visa2k_sim(void)
{
PrintAndLogEx(NORMAL, "Enables simulation of visa2k card with specified card number.");
PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued.");
PrintAndLogEx(NORMAL, "");
@@ -42,39 +44,42 @@ int usage_lf_visa2k_sim(void) {
return 0;
}
static uint8_t visa_chksum( uint32_t id ) {
static uint8_t visa_chksum(uint32_t id)
{
uint8_t sum = 0;
for (uint8_t i = 0; i < 32; i += 4)
sum ^= (id >> i) & 0xF;
sum ^= (id >> i) & 0xF;
return sum & 0xF;
}
static uint8_t visa_parity( uint32_t id) {
static uint8_t visa_parity(uint32_t id)
{
// 4bit parity LUT
uint8_t par_lut[] = {
0,1,1,0
,1,0,0,1
,1,0,0,1
,0,1,1,0
0, 1, 1, 0
, 1, 0, 0, 1
, 1, 0, 0, 1
, 0, 1, 1, 0
};
uint8_t par = 0;
par |= par_lut[ (id >> 28) & 0xF ] << 7;
par |= par_lut[ (id >> 24) & 0xF ] << 6;
par |= par_lut[ (id >> 20) & 0xF ] << 5;
par |= par_lut[ (id >> 16) & 0xF ] << 4;
par |= par_lut[ (id >> 12) & 0xF ] << 3;
par |= par_lut[ (id >> 8) & 0xF ] << 2;
par |= par_lut[ (id >> 4) & 0xF ] << 1;
par |= par_lut[ (id & 0xF) ];
par |= par_lut[(id >> 28) & 0xF ] << 7;
par |= par_lut[(id >> 24) & 0xF ] << 6;
par |= par_lut[(id >> 20) & 0xF ] << 5;
par |= par_lut[(id >> 16) & 0xF ] << 4;
par |= par_lut[(id >> 12) & 0xF ] << 3;
par |= par_lut[(id >> 8) & 0xF ] << 2;
par |= par_lut[(id >> 4) & 0xF ] << 1;
par |= par_lut[(id & 0xF) ];
return par;
}
// by iceman
// find Visa2000 preamble in already demoded data
int detectVisa2k(uint8_t *dest, size_t *size) {
int detectVisa2k(uint8_t *dest, size_t *size)
{
if (*size < 96) return -1; //make sure buffer has data
size_t startIdx = 0;
uint8_t preamble[] = {0,1,0,1,0,1,1,0,0,1,0,0,1,0,0,1,0,1,0,1,0,0,1,1,0,0,1,1,0,0,1,0};
uint8_t preamble[] = {0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0};
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
return -2; //preamble not found
if (*size != 96) return -3; //wrong demoded size
@@ -94,7 +99,8 @@ int detectVisa2k(uint8_t *dest, size_t *size) {
*
**/
//see ASKDemod for what args are accepted
int CmdVisa2kDemod(const char *Cmd) {
int CmdVisa2kDemod(const char *Cmd)
{
save_restoreGB(GRAPH_SAVE);
@@ -109,7 +115,7 @@ int CmdVisa2kDemod(const char *Cmd) {
}
size_t size = DemodBufferLen;
int ans = detectVisa2k(DemodBuffer, &size);
if (ans < 0){
if (ans < 0) {
if (ans == -1)
PrintAndLogEx(DEBUG, "DEBUG: Error - Visa2k: too few bits found");
else if (ans == -2)
@@ -123,19 +129,19 @@ int CmdVisa2kDemod(const char *Cmd) {
return 0;
}
setDemodBuf(DemodBuffer, 96, ans);
setClockGrid(g_DemodClock, g_DemodStartIdx + (ans*g_DemodClock));
setClockGrid(g_DemodClock, g_DemodStartIdx + (ans * g_DemodClock));
//got a good demod
uint32_t raw1 = bytebits_to_byte(DemodBuffer, 32);
uint32_t raw2 = bytebits_to_byte(DemodBuffer+32, 32);
uint32_t raw3 = bytebits_to_byte(DemodBuffer+64, 32);
uint32_t raw2 = bytebits_to_byte(DemodBuffer + 32, 32);
uint32_t raw3 = bytebits_to_byte(DemodBuffer + 64, 32);
// chksum
uint8_t calc = visa_chksum(raw2);
uint8_t chk = raw3 & 0xF;
// test checksums
if ( chk != calc ) {
if (chk != calc) {
PrintAndLogEx(DEBUG, "DEBUG: error: Visa2000 checksum failed %x - %x\n", chk, calc);
save_restoreGB(GRAPH_RESTORE);
return 0;
@@ -143,22 +149,24 @@ int CmdVisa2kDemod(const char *Cmd) {
// parity
uint8_t calc_par = visa_parity(raw2);
uint8_t chk_par = (raw3 & 0xFF0) >> 4;
if ( calc_par != chk_par) {
if (calc_par != chk_par) {
PrintAndLogEx(DEBUG, "DEBUG: error: Visa2000 parity failed %x - %x\n", chk_par, calc_par);
save_restoreGB(GRAPH_RESTORE);
return 0;
}
PrintAndLogEx(SUCCESS, "Visa2000 Tag Found: Card ID %u, Raw: %08X%08X%08X", raw2, raw1 ,raw2, raw3);
PrintAndLogEx(SUCCESS, "Visa2000 Tag Found: Card ID %u, Raw: %08X%08X%08X", raw2, raw1, raw2, raw3);
return 1;
}
// 64*96*2=12288 samples just in case we just missed the first preamble we can still catch 2 of them
int CmdVisa2kRead(const char *Cmd) {
int CmdVisa2kRead(const char *Cmd)
{
lf_read(true, 20000);
return CmdVisa2kDemod(Cmd);
}
int CmdVisa2kClone(const char *Cmd) {
int CmdVisa2kClone(const char *Cmd)
{
uint64_t id = 0;
uint32_t blocks[4] = {T55x7_MODULATION_MANCHESTER | T55x7_BITRATE_RF_64 | T55x7_ST_TERMINATOR | 3 << T55x7_MAXBLOCK_SHIFT, BL0CK1, 0};
@@ -173,20 +181,20 @@ int CmdVisa2kClone(const char *Cmd) {
blocks[0] = T5555_MODULATION_MANCHESTER | T5555_SET_BITRATE(64) | T5555_ST_TERMINATOR | 3 << T5555_MAXBLOCK_SHIFT;
blocks[2] = id;
blocks[3] = (visa_parity(id) << 4) | visa_chksum(id);
blocks[3] = (visa_parity(id) << 4) | visa_chksum(id);
PrintAndLogEx(INFO, "Preparing to clone Visa2000 to T55x7 with CardId: %u", id);
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++) {
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;
}
@@ -194,7 +202,8 @@ int CmdVisa2kClone(const char *Cmd) {
return 0;
}
int CmdVisa2kSim(const char *Cmd) {
int CmdVisa2kSim(const char *Cmd)
{
uint32_t id = 0;
char cmdp = param_getchar(Cmd, 0);
@@ -214,8 +223,8 @@ int CmdVisa2kSim(const char *Cmd) {
uint32_t blocks[3] = { BL0CK1, id, (visa_parity(id) << 4) | visa_chksum(id) };
for(int i = 0; i < 3; ++i)
num_to_bytebits(blocks[i], 32, c.d.asBytes + i*32);
for (int i = 0; i < 3; ++i)
num_to_bytebits(blocks[i], 32, c.d.asBytes + i * 32);
clearCommandBuffer();
SendCommand(&c);
@@ -231,13 +240,15 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFVisa2k(const char *Cmd) {
int CmdLFVisa2k(const char *Cmd)
{
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd) {
int CmdHelp(const char *Cmd)
{
CmdsHelp(CommandTable);
return 0;
}