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

@@ -12,7 +12,8 @@
static int CmdHelp(const char *Cmd);
int usage_lf_io_read(void) {
int usage_lf_io_read(void)
{
PrintAndLogEx(NORMAL, "Enables IOProx compatible reader mode printing details of scanned 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 card.");
@@ -28,7 +29,8 @@ int usage_lf_io_read(void) {
return 0;
}
int usage_lf_io_sim(void) {
int usage_lf_io_sim(void)
{
PrintAndLogEx(NORMAL, "Enables simulation of IOProx 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, "");
@@ -44,7 +46,8 @@ int usage_lf_io_sim(void) {
return 0;
}
int usage_lf_io_clone(void) {
int usage_lf_io_clone(void)
{
PrintAndLogEx(NORMAL, "Enables cloning of IOProx 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, "");
@@ -62,15 +65,17 @@ int usage_lf_io_clone(void) {
}
// this read is the "normal" read, which download lf signal and tries to demod here.
int CmdIOProxRead(const char *Cmd) {
int CmdIOProxRead(const char *Cmd)
{
lf_read(true, 12000);
return CmdIOProxDemod(Cmd);
}
// this read loops on device side.
// uses the demod in lfops.c
int CmdIOProxRead_device(const char *Cmd) {
int CmdIOProxRead_device(const char *Cmd)
{
if (Cmd[0] == 'h' || Cmd[0] == 'H') return usage_lf_io_read();
int findone = (Cmd[0]=='1') ? 1 : 0;
int findone = (Cmd[0] == '1') ? 1 : 0;
UsbCommand c = {CMD_IO_DEMOD_FSK, {findone, 0, 0}};
clearCommandBuffer();
SendCommand(&c);
@@ -80,7 +85,8 @@ int CmdIOProxRead_device(const char *Cmd) {
//by marshmellow
//IO-Prox demod - FSK RF/64 with preamble of 000000001
//print ioprox ID and some format details
int CmdIOProxDemod(const char *Cmd) {
int CmdIOProxDemod(const char *Cmd)
{
int retval = 0;
int idx = 0;
uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0};
@@ -113,7 +119,7 @@ int CmdIOProxDemod(const char *Cmd) {
return 0;
}
setDemodBuf(bits, size, idx);
setClockGrid(64, waveIdx + (idx*64));
setClockGrid(64, waveIdx + (idx * 64));
if (idx == 0) {
if (g_debugMode) {
@@ -132,30 +138,30 @@ int CmdIOProxDemod(const char *Cmd) {
//
//XSF(version)facility:codeone+codetwo (raw)
PrintAndLogEx(DEBUG, "%d%d%d%d%d%d%d%d %d", bits[idx], bits[idx+1], bits[idx+2], bits[idx+3], bits[idx+4], bits[idx+5], bits[idx+6], bits[idx+7], bits[idx+8]);
PrintAndLogEx(DEBUG, "%d%d%d%d%d%d%d%d %d", bits[idx+9], bits[idx+10], bits[idx+11],bits[idx+12],bits[idx+13],bits[idx+14],bits[idx+15],bits[idx+16],bits[idx+17]);
PrintAndLogEx(DEBUG, "%d%d%d%d%d%d%d%d %d facility", bits[idx+18], bits[idx+19], bits[idx+20],bits[idx+21],bits[idx+22],bits[idx+23],bits[idx+24],bits[idx+25],bits[idx+26]);
PrintAndLogEx(DEBUG, "%d%d%d%d%d%d%d%d %d version", bits[idx+27], bits[idx+28], bits[idx+29],bits[idx+30],bits[idx+31],bits[idx+32],bits[idx+33],bits[idx+34],bits[idx+35]);
PrintAndLogEx(DEBUG, "%d%d%d%d%d%d%d%d %d code1", bits[idx+36], bits[idx+37], bits[idx+38],bits[idx+39],bits[idx+40],bits[idx+41],bits[idx+42],bits[idx+43],bits[idx+44]);
PrintAndLogEx(DEBUG, "%d%d%d%d%d%d%d%d %d code2", bits[idx+45], bits[idx+46], bits[idx+47],bits[idx+48],bits[idx+49],bits[idx+50],bits[idx+51],bits[idx+52],bits[idx+53]);
PrintAndLogEx(DEBUG, "%d%d%d%d%d%d%d%d %d%d checksum", bits[idx+54],bits[idx+55],bits[idx+56],bits[idx+57],bits[idx+58],bits[idx+59],bits[idx+60],bits[idx+61],bits[idx+62],bits[idx+63]);
PrintAndLogEx(DEBUG, "%d%d%d%d%d%d%d%d %d", bits[idx], bits[idx + 1], bits[idx + 2], bits[idx + 3], bits[idx + 4], bits[idx + 5], bits[idx + 6], bits[idx + 7], bits[idx + 8]);
PrintAndLogEx(DEBUG, "%d%d%d%d%d%d%d%d %d", bits[idx + 9], bits[idx + 10], bits[idx + 11], bits[idx + 12], bits[idx + 13], bits[idx + 14], bits[idx + 15], bits[idx + 16], bits[idx + 17]);
PrintAndLogEx(DEBUG, "%d%d%d%d%d%d%d%d %d facility", bits[idx + 18], bits[idx + 19], bits[idx + 20], bits[idx + 21], bits[idx + 22], bits[idx + 23], bits[idx + 24], bits[idx + 25], bits[idx + 26]);
PrintAndLogEx(DEBUG, "%d%d%d%d%d%d%d%d %d version", bits[idx + 27], bits[idx + 28], bits[idx + 29], bits[idx + 30], bits[idx + 31], bits[idx + 32], bits[idx + 33], bits[idx + 34], bits[idx + 35]);
PrintAndLogEx(DEBUG, "%d%d%d%d%d%d%d%d %d code1", bits[idx + 36], bits[idx + 37], bits[idx + 38], bits[idx + 39], bits[idx + 40], bits[idx + 41], bits[idx + 42], bits[idx + 43], bits[idx + 44]);
PrintAndLogEx(DEBUG, "%d%d%d%d%d%d%d%d %d code2", bits[idx + 45], bits[idx + 46], bits[idx + 47], bits[idx + 48], bits[idx + 49], bits[idx + 50], bits[idx + 51], bits[idx + 52], bits[idx + 53]);
PrintAndLogEx(DEBUG, "%d%d%d%d%d%d%d%d %d%d checksum", bits[idx + 54], bits[idx + 55], bits[idx + 56], bits[idx + 57], bits[idx + 58], bits[idx + 59], bits[idx + 60], bits[idx + 61], bits[idx + 62], bits[idx + 63]);
uint32_t code = bytebits_to_byte(bits+idx,32);
uint32_t code2 = bytebits_to_byte(bits+idx+32,32);
uint8_t version = bytebits_to_byte(bits+idx+27,8); //14,4
uint8_t facilitycode = bytebits_to_byte(bits+idx+18,8) ;
uint16_t number = (bytebits_to_byte(bits+idx+36,8)<<8)|(bytebits_to_byte(bits+idx+45,8)); //36,9
uint8_t crc = bytebits_to_byte(bits+idx+54,8);
uint32_t code = bytebits_to_byte(bits + idx, 32);
uint32_t code2 = bytebits_to_byte(bits + idx + 32, 32);
uint8_t version = bytebits_to_byte(bits + idx + 27, 8); //14,4
uint8_t facilitycode = bytebits_to_byte(bits + idx + 18, 8) ;
uint16_t number = (bytebits_to_byte(bits + idx + 36, 8) << 8) | (bytebits_to_byte(bits + idx + 45, 8)); //36,9
uint8_t crc = bytebits_to_byte(bits + idx + 54, 8);
uint8_t calccrc = 0;
for (uint8_t i = 1; i < 6; ++i){
calccrc += bytebits_to_byte(bits + idx + 9 * i ,8);
for (uint8_t i = 1; i < 6; ++i) {
calccrc += bytebits_to_byte(bits + idx + 9 * i, 8);
}
calccrc &= 0xff;
calccrc = 0xff - calccrc;
char crcStr[30];
memset(crcStr, 0x00, sizeof(crcStr) );
memset(crcStr, 0x00, sizeof(crcStr));
if (crc == calccrc) {
snprintf(crcStr, 3, "ok");
@@ -169,7 +175,7 @@ int CmdIOProxDemod(const char *Cmd) {
PrintAndLogEx(SUCCESS, "IO Prox XSF(%02d)%02x:%05d (%08x%08x) [crc %s]", version, facilitycode, number, code, code2, crcStr);
if (g_debugMode){
if (g_debugMode) {
PrintAndLogEx(DEBUG, "DEBUG: IO prox idx: %d, Len: %d, Printing demod buffer:", idx, size);
printDemodBuff();
}
@@ -183,9 +189,10 @@ int CmdIOProxDemod(const char *Cmd) {
//-----------------------------------------------------------------------------
//00000000 0 11110000 1 facility 1 version* 1 code*one 1 code*two 1 ???????? 11
//XSF(version)facility:codeone+codetwo (raw)
int getIOProxBits(uint8_t version, uint8_t fc, uint16_t cn, uint8_t *bits) {
#define SEPARATOR 1
uint8_t pos=0;
int getIOProxBits(uint8_t version, uint8_t fc, uint16_t cn, uint8_t *bits)
{
#define SEPARATOR 1
uint8_t pos = 0;
// the return bits, preamble 0000 0000 0
uint8_t pre[64];
memset(pre, 0, sizeof(pre));
@@ -194,43 +201,43 @@ int getIOProxBits(uint8_t version, uint8_t fc, uint16_t cn, uint8_t *bits) {
pos = 9;
// another fixed byte 11110000 = 0xF0
num_to_bytebits(0xF0, 8, pre+pos);
num_to_bytebits(0xF0, 8, pre + pos);
pos += 8;
pre[pos] = SEPARATOR;
pos++;
// add facilitycode
num_to_bytebits(fc, 8, pre+pos);
num_to_bytebits(fc, 8, pre + pos);
pos += 8;
pre[pos] = SEPARATOR;
pos++;
// add version
num_to_bytebits(version, 8, pre+pos);
num_to_bytebits(version, 8, pre + pos);
pos += 8;
pre[pos] = SEPARATOR;
pos++;
// cardnumber high byte
num_to_bytebits( ((cn & 0xFF00)>>8), 8, pre+pos);
num_to_bytebits(((cn & 0xFF00) >> 8), 8, pre + pos);
pos += 8;
pre[pos] = SEPARATOR;
pos++;
// cardnumber low byte
num_to_bytebits( (cn & 0xFF), 8, pre+pos);
num_to_bytebits((cn & 0xFF), 8, pre + pos);
pos += 8;
pre[pos] = SEPARATOR;
pos++;
// calculate and add CRC
uint16_t crc = 0;
for (uint8_t i=1; i<6; ++i)
crc += bytebits_to_byte(pre+9*i, 8);
for (uint8_t i = 1; i < 6; ++i)
crc += bytebits_to_byte(pre + 9 * i, 8);
crc &= 0xFF;
crc = 0xff - crc;
num_to_bytebits(crc, 8, pre+pos);
num_to_bytebits(crc, 8, pre + pos);
pos += 8;
// Final two ONES
@@ -243,7 +250,8 @@ int getIOProxBits(uint8_t version, uint8_t fc, uint16_t cn, uint8_t *bits) {
return 1;
}
int CmdIOProxSim(const char *Cmd) {
int CmdIOProxSim(const char *Cmd)
{
uint16_t cn = 0;
uint8_t version = 0, fc = 0;
uint8_t bits[64];
@@ -257,7 +265,7 @@ int CmdIOProxSim(const char *Cmd) {
fc = param_get8(Cmd, 1);
cn = param_get32ex(Cmd, 2, 0, 10);
if ( !version | !fc || !cn) return usage_lf_io_sim();
if (!version | !fc || !cn) return usage_lf_io_sim();
if ((cn & 0xFFFF) != cn) {
cn &= 0xFFFF;
@@ -273,7 +281,7 @@ int CmdIOProxSim(const char *Cmd) {
PrintAndLogEx(SUCCESS, "Simulating IOProx version: %u FC: %u; CN: %u\n", version, fc, cn);
PrintAndLogEx(SUCCESS, "Press pm3-button to abort simulation or run another command");
if ( !getIOProxBits(version, fc, cn, bits)) {
if (!getIOProxBits(version, fc, cn, bits)) {
PrintAndLogEx(WARNING, "Error with tag bitstream generation.");
return 1;
}
@@ -288,13 +296,14 @@ int CmdIOProxSim(const char *Cmd) {
return 0;
}
int CmdIOProxClone(const char *Cmd) {
int CmdIOProxClone(const char *Cmd)
{
uint32_t blocks[3] = {T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_64 | 2 << T55x7_MAXBLOCK_SHIFT, 0, 0};
uint16_t cn = 0;
uint8_t version = 0, fc = 0;
uint8_t bits[64];
memset(bits,0,sizeof(bits));
memset(bits, 0, sizeof(bits));
char cmdp = param_getchar(Cmd, 0);
if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_io_clone();
@@ -303,14 +312,14 @@ int CmdIOProxClone(const char *Cmd) {
fc = param_get8(Cmd, 1);
cn = param_get32ex(Cmd, 2, 0, 10);
if ( !version | !fc || !cn) return usage_lf_io_clone();
if (!version | !fc || !cn) return usage_lf_io_clone();
if ((cn & 0xFFFF) != cn) {
cn &= 0xFFFF;
PrintAndLogEx(INFO, "Card Number Truncated to 16-bits (IOProx): %u", cn);
}
if ( !getIOProxBits(version, fc, cn, bits)) {
if (!getIOProxBits(version, fc, cn, bits)) {
PrintAndLogEx(WARNING, "Error with tag bitstream generation.");
return 1;
}
@@ -325,7 +334,7 @@ int CmdIOProxClone(const char *Cmd) {
print_blocks(blocks, 3);
//UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}};
UsbCommand c = {CMD_IO_CLONE_TAG, {blocks[1],blocks[2],0}};
UsbCommand c = {CMD_IO_CLONE_TAG, {blocks[1], blocks[2], 0}};
clearCommandBuffer();
SendCommand(&c);
return 0;
@@ -340,13 +349,15 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFIO(const char *Cmd){
int CmdLFIO(const char *Cmd)
{
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd) {
int CmdHelp(const char *Cmd)
{
CmdsHelp(CommandTable);
return 0;
}