From ed67936892f4996572100cca57883249686d5e43 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 12 Jan 2020 17:28:12 +0100 Subject: [PATCH] style --- armsrc/appmain.c | 2 +- armsrc/fpgaloader.c | 14 +++---- armsrc/hfsnoop.c | 54 +++++++++++++------------- client/cliparser/argtable3.c | 44 ++++++++++----------- client/cmdhf.c | 24 ++++++------ client/cmdhfmfu.c | 12 +++--- client/cmdlf.c | 28 +++++++------- client/cmdlfindala.c | 74 ++++++++++++++++++------------------ client/cmdlfkeri.c | 4 +- common/generator.c | 74 ++++++++++++++++++------------------ common/iso15693tools.h | 24 ++++++------ 11 files changed, 177 insertions(+), 177 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 73b9fc4a6..8661ffccb 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -930,7 +930,7 @@ static void PacketReceived(PacketCommandNG *packet) { #ifdef WITH_HITAG case CMD_LF_HITAG_SNIFF: { // Eavesdrop Hitag tag, args = type - SniffHitag(); + SniffHitag(); // SniffHitag(packet->oldarg[0]); break; } diff --git a/armsrc/fpgaloader.c b/armsrc/fpgaloader.c index a441163e1..a5ca3f6d1 100644 --- a/armsrc/fpgaloader.c +++ b/armsrc/fpgaloader.c @@ -141,16 +141,16 @@ void FpgaSetupSsc(void) { // Now set up the SSC proper, starting from a known state. AT91C_BASE_SSC->SSC_CR = AT91C_SSC_SWRST; - // RX clock comes from TX clock, RX starts on Transmit Start, - // data and frame signal is sampled on falling edge of RK + // RX clock comes from TX clock, RX starts on Transmit Start, + // data and frame signal is sampled on falling edge of RK AT91C_BASE_SSC->SSC_RCMR = SSC_CLOCK_MODE_SELECT(1) | SSC_CLOCK_MODE_START(1); // 8 bits per transfer, no loopback, MSB first, 1 transfer per sync // pulse, no output sync AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(8) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0); - // TX clock comes from TK pin, no clock output, outputs change on falling - // edge of TK, frame sync is sampled on rising edge of TK, start TX on rising edge of TF + // TX clock comes from TK pin, no clock output, outputs change on falling + // edge of TK, frame sync is sampled on rising edge of TK, start TX on rising edge of TF AT91C_BASE_SSC->SSC_TCMR = SSC_CLOCK_MODE_SELECT(2) | SSC_CLOCK_MODE_START(5); // tx framing is the same as the rx framing @@ -439,7 +439,7 @@ void FpgaDownloadAndGo(int bitstream_version) { // Send a 16 bit command/data pair to the FPGA. // The bit format is: C3 C2 C1 C0 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 // where C is the 4 bit command and D is the 12 bit data -// +// // @params cmd and v gets or over eachother. Take careful note of overlapping bits. //----------------------------------------------------------------------------- void FpgaSendCommand(uint16_t cmd, uint16_t v) { @@ -461,11 +461,11 @@ void FpgaWriteConfWord(uint16_t v) { // enable/disable FPGA internal tracing //----------------------------------------------------------------------------- void FpgaEnableTracing(void) { - FpgaSendCommand(FPGA_CMD_TRACE_ENABLE, 1); + FpgaSendCommand(FPGA_CMD_TRACE_ENABLE, 1); } void FpgaDisableTracing(void) { - FpgaSendCommand(FPGA_CMD_TRACE_ENABLE, 0); + FpgaSendCommand(FPGA_CMD_TRACE_ENABLE, 0); } //----------------------------------------------------------------------------- diff --git a/armsrc/hfsnoop.c b/armsrc/hfsnoop.c index 4ab03cd22..770280b9b 100644 --- a/armsrc/hfsnoop.c +++ b/armsrc/hfsnoop.c @@ -91,40 +91,40 @@ void HfSniff(int samplesToSkip, int triggersToSkip) { } void HfPlotDownload(void) { - uint8_t *buf = ToSend; - uint8_t *this_buf = buf; + uint8_t *buf = ToSend; + uint8_t *this_buf = buf; - FpgaDownloadAndGo(FPGA_BITSTREAM_HF); + FpgaDownloadAndGo(FPGA_BITSTREAM_HF); - FpgaSetupSsc(); + FpgaSetupSsc(); - AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS; // Disable DMA Transfer - AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) this_buf; // start transfer to this memory address - AT91C_BASE_PDC_SSC->PDC_RCR = PM3_CMD_DATA_SIZE; // transfer this many samples - buf[0] = (uint8_t)AT91C_BASE_SSC->SSC_RHR; // clear receive register - AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN; // Start DMA transfer + AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS; // Disable DMA Transfer + AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) this_buf; // start transfer to this memory address + AT91C_BASE_PDC_SSC->PDC_RCR = PM3_CMD_DATA_SIZE; // transfer this many samples + buf[0] = (uint8_t)AT91C_BASE_SSC->SSC_RHR; // clear receive register + AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN; // Start DMA transfer - FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_GET_TRACE); // let FPGA transfer its internal Block-RAM + FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_GET_TRACE); // let FPGA transfer its internal Block-RAM - LED_B_ON(); - for(size_t i = 0; i < FPGA_TRACE_SIZE; i += PM3_CMD_DATA_SIZE) { - // prepare next DMA transfer: - uint8_t *next_buf = buf + ((i + PM3_CMD_DATA_SIZE) % (2 * PM3_CMD_DATA_SIZE)); - - AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t)next_buf; - AT91C_BASE_PDC_SSC->PDC_RNCR = PM3_CMD_DATA_SIZE; + LED_B_ON(); + for (size_t i = 0; i < FPGA_TRACE_SIZE; i += PM3_CMD_DATA_SIZE) { + // prepare next DMA transfer: + uint8_t *next_buf = buf + ((i + PM3_CMD_DATA_SIZE) % (2 * PM3_CMD_DATA_SIZE)); - size_t len = MIN(FPGA_TRACE_SIZE - i, PM3_CMD_DATA_SIZE); + AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t)next_buf; + AT91C_BASE_PDC_SSC->PDC_RNCR = PM3_CMD_DATA_SIZE; - while (!(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_ENDRX))) {}; // wait for DMA transfer to complete + size_t len = MIN(FPGA_TRACE_SIZE - i, PM3_CMD_DATA_SIZE); - reply_old(CMD_FPGAMEM_DOWNLOADED, i, len, FPGA_TRACE_SIZE, this_buf, len); - this_buf = next_buf; - } + while (!(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_ENDRX))) {}; // wait for DMA transfer to complete - FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); - - // Trigger a finish downloading signal with an ACK frame - reply_mix(CMD_ACK, 1, 0, FPGA_TRACE_SIZE, 0, 0); - LED_B_OFF(); + reply_old(CMD_FPGAMEM_DOWNLOADED, i, len, FPGA_TRACE_SIZE, this_buf, len); + this_buf = next_buf; + } + + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); + + // Trigger a finish downloading signal with an ACK frame + reply_mix(CMD_ACK, 1, 0, FPGA_TRACE_SIZE, 0, 0); + LED_B_OFF(); } diff --git a/client/cliparser/argtable3.c b/client/cliparser/argtable3.c index a5fb7a023..3acbce48e 100644 --- a/client/cliparser/argtable3.c +++ b/client/cliparser/argtable3.c @@ -3421,7 +3421,7 @@ TRexBool trex_searchrange(TRex *exp, const TRexChar *text_begin, const TRexChar if (!cur) break; node = exp->_nodes[node].next; - } + } text_begin++; } while (cur == NULL && text_begin != text_end); @@ -3675,7 +3675,7 @@ void arg_register_error(struct arg_end *end, * Return index of first table entry with a matching short option * or -1 if no match was found. */ -static int find_shortoption(struct arg_hdr** table, char shortopt) { +static int find_shortoption(struct arg_hdr **table, char shortopt) { int tabindex; for (tabindex = 0; !(table[tabindex]->flag & ARG_TERMINATOR); tabindex++) { if (table[tabindex]->shortopts && @@ -3708,7 +3708,7 @@ void dump_longoptions(struct longoptions *longoptions) { } #endif -static struct longoptions* alloc_longoptions(struct arg_hdr** table) { +static struct longoptions *alloc_longoptions(struct arg_hdr **table) { struct longoptions *result; size_t nbytes; int noptions = 1; @@ -3790,7 +3790,7 @@ static struct longoptions* alloc_longoptions(struct arg_hdr** table) { return result; } -static char* alloc_shortoptions(struct arg_hdr** table) { +static char *alloc_shortoptions(struct arg_hdr **table) { char *result; size_t len = 2; int tabindex; @@ -3830,7 +3830,7 @@ static char* alloc_shortoptions(struct arg_hdr** table) { /* return index of the table terminator entry */ -static int arg_endindex(struct arg_hdr** table) { +static int arg_endindex(struct arg_hdr **table) { int tabindex = 0; while (!(table[tabindex]->flag & ARG_TERMINATOR)) tabindex++; @@ -3839,9 +3839,9 @@ static int arg_endindex(struct arg_hdr** table) { static void arg_parse_tagged(int argc, - char **argv, - struct arg_hdr **table, - struct arg_end *endtable) { + char **argv, + struct arg_hdr **table, + struct arg_end *endtable) { struct longoptions *longoptions; char *shortoptions; int copt; @@ -3952,9 +3952,9 @@ static void arg_parse_tagged(int argc, static void arg_parse_untagged(int argc, - char **argv, - struct arg_hdr **table, - struct arg_end *endtable) { + char **argv, + struct arg_hdr **table, + struct arg_end *endtable) { int tabindex = 0; int errorlast = 0; const char *optarglast = NULL; @@ -4154,11 +4154,11 @@ static void arg_cat(char **pdest, const char *src, size_t *pndest) { static void arg_cat_option(char *dest, - size_t ndest, - const char *shortopts, - const char *longopts, - const char *datatype, - int optvalue) { + size_t ndest, + const char *shortopts, + const char *longopts, + const char *datatype, + int optvalue) { if (shortopts) { char option[3]; @@ -4212,12 +4212,12 @@ static void arg_cat_option(char *dest, } static void arg_cat_optionv(char *dest, - size_t ndest, - const char *shortopts, - const char *longopts, - const char *datatype, - int optvalue, - const char *separator) { + size_t ndest, + const char *shortopts, + const char *longopts, + const char *datatype, + int optvalue, + const char *separator) { separator = separator ? separator : ""; if (shortopts) { diff --git a/client/cmdhf.c b/client/cmdhf.c index 05d52af5e..52ad853fa 100644 --- a/client/cmdhf.c +++ b/client/cmdhf.c @@ -230,18 +230,18 @@ int CmdHFSniff(const char *Cmd) { } int CmdHFPlot(const char *Cmd) { - CLIParserInit("hf plot", - "Plots HF signal after RF signal path and A/D conversion.", - "This can be used after any hf command and will show the last few milliseconds of the HF signal.\n" - "Note: If the last hf command terminated because of a timeout you will most probably see nothing.\n"); - void* argtable[] = { - arg_param_begin, - arg_param_end - }; - CLIExecWithReturn(Cmd, argtable, true); + CLIParserInit("hf plot", + "Plots HF signal after RF signal path and A/D conversion.", + "This can be used after any hf command and will show the last few milliseconds of the HF signal.\n" + "Note: If the last hf command terminated because of a timeout you will most probably see nothing.\n"); + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(Cmd, argtable, true); + + uint8_t buf[FPGA_TRACE_SIZE]; - uint8_t buf[FPGA_TRACE_SIZE]; - PacketResponseNG response; if (!GetFromDevice(FPGA_MEM, buf, FPGA_TRACE_SIZE, 0, NULL, 0, &response, 4000, true)) { PrintAndLogEx(WARNING, "timeout while waiting for reply."); @@ -262,7 +262,7 @@ int CmdHFPlot(const char *Cmd) { setClockGrid(0, 0); DemodBufferLen = 0; RepaintGraphWindow(); - return PM3_SUCCESS; + return PM3_SUCCESS; } static command_t CommandTable[] = { diff --git a/client/cmdhfmfu.c b/client/cmdhfmfu.c index b761494f5..5387cc855 100644 --- a/client/cmdhfmfu.c +++ b/client/cmdhfmfu.c @@ -2469,12 +2469,12 @@ static int CmdHF14AMfUGenDiverseKeys(const char *Cmd) { PrintAndLogEx(WARNING, "iso14443a card select failed"); return PM3_ESOFT; } -/* - if (card.uidlen != 4) { - PrintAndLogEx(WARNING, "Wrong sized UID, expected 4bytes got %d", card.uidlen); - return PM3_ESOFT; - } -*/ + /* + if (card.uidlen != 4) { + PrintAndLogEx(WARNING, "Wrong sized UID, expected 4bytes got %d", card.uidlen); + return PM3_ESOFT; + } + */ memcpy(uid, card.uid, card.uidlen); } else { if (param_gethex(Cmd, 0, uid, 8)) return usage_hf_mfu_gendiverse(); diff --git a/client/cmdlf.c b/client/cmdlf.c index 337444f1e..48f1cd235 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -458,9 +458,9 @@ int lf_config(sample_config *config) { clearCommandBuffer(); if (config != NULL) SendCommandNG(CMD_LF_SAMPLING_SET_CONFIG, (uint8_t *)config, sizeof(sample_config)); - else + else SendCommandNG(CMD_LF_SAMPLING_GET_CONFIG, NULL, 0); - + return PM3_SUCCESS; } @@ -474,15 +474,15 @@ int CmdLFConfig(const char *Cmd) { } sample_config config = { - .decimation = -1, - .bits_per_sample = -1, - .averaging = -1, - .divisor = -1, - .trigger_threshold = -1, - .samples_to_skip = -1, - .verbose = true + .decimation = -1, + .bits_per_sample = -1, + .averaging = -1, + .divisor = -1, + .trigger_threshold = -1, + .samples_to_skip = -1, + .verbose = true }; - + bool errors = false; uint8_t cmdp = 0; @@ -527,20 +527,20 @@ int CmdLFConfig(const char *Cmd) { break; } case 'b': { - config.bits_per_sample = param_get8ex(Cmd, cmdp + 1, 8, 10); + config.bits_per_sample = param_get8ex(Cmd, cmdp + 1, 8, 10); // bps is limited to 8 - if (config.bits_per_sample >> 4) + if (config.bits_per_sample >> 4) config.bits_per_sample = 8; cmdp += 2; break; } case 'd': { - config.decimation = param_get8ex(Cmd, cmdp + 1, 1, 10); + config.decimation = param_get8ex(Cmd, cmdp + 1, 1, 10); // decimation is limited to 255 - if (config.decimation >> 4) + if (config.decimation >> 4) config.decimation = 8; cmdp += 2; diff --git a/client/cmdlfindala.c b/client/cmdlfindala.c index 11950a0c5..368e182d7 100644 --- a/client/cmdlfindala.c +++ b/client/cmdlfindala.c @@ -73,19 +73,19 @@ static int usage_lf_indala_sim(void) { static void encodeHeden2L(uint8_t *dest, uint32_t cardnumber) { uint8_t template[] = { - 1,0,1,0,0,0,0,0, - 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, - 1,0,0,0,1,0,0,0, - 1,0,0,0,0,0,0,0, - 0,0,0,0,1,0,0,1, - 0,0,0,0,0,0,1,0 + 1, 0, 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 1, 0 }; uint8_t cardbits[32]; num_to_bytebits(cardnumber, sizeof(cardbits), cardbits); - + if (cardbits[31] == 1) template[HEDEN2L_OFFSET + 8] = 0x1; if (cardbits[30] == 1) template[HEDEN2L_OFFSET + 10] = 0x1; if (cardbits[29] == 1) template[HEDEN2L_OFFSET + 14] = 0x1; @@ -105,14 +105,14 @@ static void encodeHeden2L(uint8_t *dest, uint32_t cardnumber) { // Parity uint8_t counter = 0; - for (int i=0; i< sizeof(template) - HEDEN2L_OFFSET; i++) { - if (template[i]) - counter++; - } + for (int i = 0; i < sizeof(template) - HEDEN2L_OFFSET; i++) { + if (template[i]) + counter++; + } template[63] = (counter & 0x1); - - for (int i = 0; i< sizeof(template); i += 8) { - dest[i/8] = bytebits_to_byte(template + i, 8); + + for (int i = 0; i < sizeof(template); i += 8) { + dest[i / 8] = bytebits_to_byte(template + i, 8); } PrintAndLogEx(INFO, "Heden-2L card number %u", cardnumber); @@ -123,22 +123,22 @@ static void decodeHeden2L(uint8_t *bits) { uint32_t cardnumber = 0; uint8_t offset = HEDEN2L_OFFSET; - if ( bits[offset + 8] ) cardnumber += 1; - if ( bits[offset + 10] ) cardnumber += 2; - if ( bits[offset + 14] ) cardnumber += 4; - if ( bits[offset + 15] ) cardnumber += 8; - if ( bits[offset + 12] ) cardnumber += 16; - if ( bits[offset + 28] ) cardnumber += 32; - if ( bits[offset + 3] ) cardnumber += 64; - if ( bits[offset + 11] ) cardnumber += 128; - if ( bits[offset + 19] ) cardnumber += 256; - if ( bits[offset + 26] ) cardnumber += 512; - if ( bits[offset + 17] ) cardnumber += 1024; - if ( bits[offset + 18] ) cardnumber += 2048; - if ( bits[offset + 20] ) cardnumber += 4096; - if ( bits[offset + 13] ) cardnumber += 8192; - if ( bits[offset + 7] ) cardnumber += 16384; - if ( bits[offset + 23] ) cardnumber += 32768; + if (bits[offset + 8]) cardnumber += 1; + if (bits[offset + 10]) cardnumber += 2; + if (bits[offset + 14]) cardnumber += 4; + if (bits[offset + 15]) cardnumber += 8; + if (bits[offset + 12]) cardnumber += 16; + if (bits[offset + 28]) cardnumber += 32; + if (bits[offset + 3]) cardnumber += 64; + if (bits[offset + 11]) cardnumber += 128; + if (bits[offset + 19]) cardnumber += 256; + if (bits[offset + 26]) cardnumber += 512; + if (bits[offset + 17]) cardnumber += 1024; + if (bits[offset + 18]) cardnumber += 2048; + if (bits[offset + 20]) cardnumber += 4096; + if (bits[offset + 13]) cardnumber += 8192; + if (bits[offset + 7]) cardnumber += 16384; + if (bits[offset + 23]) cardnumber += 32768; PrintAndLogEx(SUCCESS, "\tHeden-2L | %u", cardnumber); } @@ -576,7 +576,7 @@ static int CmdIndalaClone(const char *Cmd) { if (got_cn == false) { CLIGetHexWithReturn(3, data, &datalen); } - + is_t5555 = arg_get_lit(4); CLIParserFree(); @@ -585,12 +585,12 @@ static int CmdIndalaClone(const char *Cmd) { // 224 BIT UID // config for Indala (RF/32;PSK2 with RF/2;Maxblock=7) PrintAndLogEx(INFO, "Preparing to clone Indala 224bit tag with RawID %s", sprint_hex(data, datalen)); - + if (is_t5555) blocks[0] = T5555_SET_BITRATE(32) | T5555_MODULATION_PSK2 | (7 << T5555_MAXBLOCK_SHIFT); else blocks[0] = T55x7_BITRATE_RF_32 | T55x7_MODULATION_PSK2 | (7 << T55x7_MAXBLOCK_SHIFT); - + blocks[1] = bytes_to_num(data, 4); blocks[2] = bytes_to_num(data + 4, 4); blocks[3] = bytes_to_num(data + 8, 4); @@ -608,12 +608,12 @@ static int CmdIndalaClone(const char *Cmd) { // config for Indala 64 format (RF/32;PSK1 with RF/2;Maxblock=2) PrintAndLogEx(INFO, "Preparing to clone Indala 64bit tag with RawID %s", sprint_hex(data, datalen)); - + if (is_t5555) blocks[0] = T5555_SET_BITRATE(32) | T5555_MODULATION_PSK1 | (2 << T5555_MAXBLOCK_SHIFT); else blocks[0] = T55x7_BITRATE_RF_32 | T55x7_MODULATION_PSK1 | (2 << T55x7_MAXBLOCK_SHIFT); - + blocks[1] = bytes_to_num(data, 4); blocks[2] = bytes_to_num(data + 4, 4); max = 3; diff --git a/client/cmdlfkeri.c b/client/cmdlfkeri.c index 4846b5378..aadc8676d 100644 --- a/client/cmdlfkeri.c +++ b/client/cmdlfkeri.c @@ -128,8 +128,8 @@ static int CmdKeriClone(const char *Cmd) { T55x7_MODULATION_PSK1 | T55x7_PSKCF_RF_2 | 2 << T55x7_MAXBLOCK_SHIFT, - 0, - 0 + 0, + 0 }; // dynamic bitrate used diff --git a/common/generator.c b/common/generator.c index 22c63add5..6dbac2feb 100644 --- a/common/generator.c +++ b/common/generator.c @@ -36,13 +36,13 @@ //------------------------------------ static void transform_D(uint8_t *ru) { -const uint32_t c_D[] = { - 0x6D835AFC, 0x7D15CD97, 0x0942B409, 0x32F9C923, 0xA811FB02, 0x64F121E8, - 0xD1CC8B4E, 0xE8873E6F, 0x61399BBB, 0xF1B91926, 0xAC661520, 0xA21A31C9, - 0xD424808D, 0xFE118E07, 0xD18E728D, 0xABAC9E17, 0x18066433, 0x00E18E79, - 0x65A77305, 0x5AE9E297, 0x11FC628C, 0x7BB3431F, 0x942A8308, 0xB2F8FD20, - 0x5728B869, 0x30726D5A -}; + const uint32_t c_D[] = { + 0x6D835AFC, 0x7D15CD97, 0x0942B409, 0x32F9C923, 0xA811FB02, 0x64F121E8, + 0xD1CC8B4E, 0xE8873E6F, 0x61399BBB, 0xF1B91926, 0xAC661520, 0xA21A31C9, + 0xD424808D, 0xFE118E07, 0xD18E728D, 0xABAC9E17, 0x18066433, 0x00E18E79, + 0x65A77305, 0x5AE9E297, 0x11FC628C, 0x7BB3431F, 0x942A8308, 0xB2F8FD20, + 0x5728B869, 0x30726D5A + }; //Transform uint8_t i; @@ -197,9 +197,9 @@ int mfc_algo_ving_one(uint8_t *uid, uint8_t sector, uint8_t keytype, uint64_t *k int mfc_algo_ving_all(uint8_t *uid, uint8_t *keys) { if (keys == NULL) return PM3_EINVARG; for (int keytype = 0; keytype < 2; keytype++) { - for (int sector = 0; sector < 16; sector++){ + for (int sector = 0; sector < 16; sector++) { uint64_t key = 0; - mfc_algo_ving_one(uid, sector, keytype, &key ); + mfc_algo_ving_one(uid, sector, keytype, &key); num_to_bytes(key, 6, keys + (keytype * 16 * 6) + (sector * 6)); } } @@ -216,9 +216,9 @@ int mfc_algo_yale_one(uint8_t *uid, uint8_t sector, uint8_t keytype, uint64_t *k int mfc_algo_yale_all(uint8_t *uid, uint8_t *keys) { if (keys == NULL) return PM3_EINVARG; for (int keytype = 0; keytype < 2; keytype++) { - for (int sector = 0; sector < 16; sector++){ + for (int sector = 0; sector < 16; sector++) { uint64_t key = 0; - mfc_algo_yale_one(uid, sector, keytype, &key ); + mfc_algo_yale_one(uid, sector, keytype, &key); num_to_bytes(key, 6, keys + (keytype * 16 * 6) + (sector * 6)); } } @@ -236,9 +236,9 @@ int mfc_algo_saflok_all(uint8_t *uid, uint8_t *keys) { if (keys == NULL) return PM3_EINVARG; for (int keytype = 0; keytype < 2; keytype++) { - for (int sector = 0; sector < 16; sector++){ + for (int sector = 0; sector < 16; sector++) { uint64_t key = 0; - mfc_algo_saflok_one(uid, sector, keytype, &key ); + mfc_algo_saflok_one(uid, sector, keytype, &key); num_to_bytes(key, 6, keys + (keytype * 16 * 6) + (sector * 6)); } } @@ -253,15 +253,15 @@ int mfc_algo_mizip_one(uint8_t *uid, uint8_t sector, uint8_t keytype, uint64_t * if (sector == 0) { // A if (keytype == 0) - *key = 0xA0A1A2A3A4A5U; - else // B - *key = 0xB4C132439eef; + *key = 0xA0A1A2A3A4A5U; + else // B + *key = 0xB4C132439eef; } else { - uint8_t xor[6]; + uint8_t xor[6]; - if ( keytype == 0 ) { + if (keytype == 0) { uint64_t xor_tbl_a[] = { 0x09125a2589e5, @@ -273,7 +273,7 @@ int mfc_algo_mizip_one(uint8_t *uid, uint8_t sector, uint8_t keytype, uint64_t * num_to_bytes(xor_tbl_a[sector - 1], 6, xor); *key = - (uint64_t)(uid[0] ^ xor[0] ) << 40 | + (uint64_t)(uid[0] ^ xor[0]) << 40 | (uint64_t)(uid[1] ^ xor[1]) << 32 | (uint64_t)(uid[2] ^ xor[2]) << 24 | (uint64_t)(uid[3] ^ xor[3]) << 16 | @@ -311,11 +311,11 @@ int mfc_algo_mizip_all(uint8_t *uid, uint8_t *keys) { if (keys == NULL) return PM3_EINVARG; for (int keytype = 0; keytype < 2; keytype++) { - for (int sector = 0; sector < 5; sector++){ + for (int sector = 0; sector < 5; sector++) { uint64_t key = 0; mfc_algo_mizip_one(uid, sector, keytype, &key); num_to_bytes(key, 6, keys + (keytype * 5 * 6) + (sector * 6)); - } + } } return PM3_SUCCESS; } @@ -337,20 +337,20 @@ int mfc_algo_di_one(uint8_t *uid, uint8_t sector, uint8_t keytype, uint64_t *key mbedtls_sha1(input, sizeof(input), hash); *key = ( - (uint64_t)hash[3] << 40 | - (uint64_t)hash[2] << 32 | - (uint64_t)hash[1] << 24 | - (uint64_t)hash[0] << 16 | - (uint64_t)hash[7] << 8 | - hash[6] - ); + (uint64_t)hash[3] << 40 | + (uint64_t)hash[2] << 32 | + (uint64_t)hash[1] << 24 | + (uint64_t)hash[0] << 16 | + (uint64_t)hash[7] << 8 | + hash[6] + ); return PM3_SUCCESS; } int mfc_algo_di_all(uint8_t *uid, uint8_t *keys) { if (keys == NULL) return PM3_EINVARG; for (int keytype = 0; keytype < 2; keytype++) { - for (int sector = 0; sector < 5; sector++){ + for (int sector = 0; sector < 5; sector++) { uint64_t key = 0; mfc_algo_di_one(uid, sector, keytype, &key); num_to_bytes(key, 6, keys + (keytype * 5 * 6) + (sector * 6)); @@ -361,10 +361,10 @@ int mfc_algo_di_all(uint8_t *uid, uint8_t *keys) { // Skylanders static uint64_t sky_crc64_like(uint64_t result, uint8_t sector) { - #define SKY_POLY UINT64_C(0x42f0e1eba9ea3693) - #define SKY_TOP UINT64_C(0x800000000000) +#define SKY_POLY UINT64_C(0x42f0e1eba9ea3693) +#define SKY_TOP UINT64_C(0x800000000000) result ^= (uint64_t)sector << 40; - for(int i = 0; i < 8; i++) { + for (int i = 0; i < 8; i++) { result = (result & SKY_TOP) ? (result << 1) ^ SKY_POLY : result << 1; } return result; @@ -375,7 +375,7 @@ int mfc_algo_sky_one(uint8_t *uid, uint8_t sector, uint8_t keytype, uint64_t *ke if (sector > 15) return PM3_EINVARG; if (key == NULL) return PM3_EINVARG; - + if (sector == 0 && keytype == 0) { *key = 0x4B0B20107CCB; return PM3_SUCCESS; @@ -384,21 +384,21 @@ int mfc_algo_sky_one(uint8_t *uid, uint8_t sector, uint8_t keytype, uint64_t *ke *key = 0x000000000000; return PM3_SUCCESS; } - + // hash UID uint64_t hash = 0x9AE903260CC4; - for(int i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { hash = sky_crc64_like(hash, uid[i]); } - uint64_t sectorhash = sky_crc64_like(hash, sector); + uint64_t sectorhash = sky_crc64_like(hash, sector); *key = BSWAP_64(sectorhash & SKY_KEY_MASK) >> 16; return PM3_SUCCESS; } int mfc_algo_sky_all(uint8_t *uid, uint8_t *keys) { if (keys == NULL) return PM3_EINVARG; for (int keytype = 0; keytype < 2; keytype++) { - for (int sector = 0; sector < 16; sector++){ + for (int sector = 0; sector < 16; sector++) { uint64_t key = 0; mfc_algo_sky_one(uid, sector, keytype, &key); num_to_bytes(key, 6, keys + (keytype * 16 * 6) + (sector * 6)); diff --git a/common/iso15693tools.h b/common/iso15693tools.h index 7c5380904..62ad85499 100644 --- a/common/iso15693tools.h +++ b/common/iso15693tools.h @@ -106,14 +106,14 @@ static const int Iso15693FrameSOF[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - -1, -1, -1, -1, - -1, -1, -1, -1, - 1, 1, 1, 1, - 1, 1, 1, 1 -}; + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + -1, -1, -1, -1, + -1, -1, -1, -1, + 1, 1, 1, 1, + 1, 1, 1, 1 + }; static const int Iso15693Logic0[] = { 1, 1, 1, 1, 1, 1, 1, 1, @@ -122,10 +122,10 @@ static const int Iso15693Logic0[] = { }; static const int Iso15693Logic1[] = { -1, -1, -1, -1, - -1, -1, -1, -1, - 1, 1, 1, 1, - 1, 1, 1, 1 -}; + -1, -1, -1, -1, + 1, 1, 1, 1, + 1, 1, 1, 1 + }; // EOF defined as // 1) logic '0' (8 pulses of 423.75kHz followed by unmodulated for 18.88us)