diff --git a/.gitignore b/.gitignore index f5ee135e63..f61e85eb91 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,7 @@ client/ui/ui_overlays.h hardnested_stats.txt proxmark3 flasher +!flasher/ lua luac fpga_compress diff --git a/Makefile b/Makefile index d3305bb5e4..194b63b223 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ endif -include Makefile.platform -include .Makefile.options.cache -include common/Makefile.hal +include common_arm/Makefile.hal all clean: %: client/% bootrom/% armsrc/% recovery/% mfkey/% nonce2key/% diff --git a/armsrc/BigBuf.c b/armsrc/BigBuf.c index 7b199930a6..a0a25d1fe9 100644 --- a/armsrc/BigBuf.c +++ b/armsrc/BigBuf.c @@ -10,6 +10,9 @@ //----------------------------------------------------------------------------- #include "BigBuf.h" +#include "string.h" +#include "dbprint.h" + // BigBuf is the large multi-purpose buffer, typically used to hold A/D samples or traces. // Also used to hold various smaller buffers and the Mifare Emulator Memory. // declare it as uint32_t to achieve alignment to 4 Byte boundary diff --git a/armsrc/BigBuf.h b/armsrc/BigBuf.h index 12f2521c67..ad967c4c71 100644 --- a/armsrc/BigBuf.h +++ b/armsrc/BigBuf.h @@ -12,10 +12,7 @@ #ifndef __BIGBUF_H #define __BIGBUF_H -#include // for bool -#include "proxmark3.h" -#include "string.h" -#include "ticks.h" +#include "common.h" #define BIGBUF_SIZE 40000 #define MAX_FRAME_SIZE 256 // maximum allowed ISO14443 frame @@ -43,4 +40,5 @@ void set_tracelen(uint32_t value); bool get_tracing(void); bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_start, uint32_t timestamp_end, uint8_t *parity, bool readerToTag); uint8_t emlSet(uint8_t *data, uint32_t offset, uint32_t length); + #endif /* __BIGBUF_H */ diff --git a/armsrc/LCD.c b/armsrc/LCD_disabled.c similarity index 100% rename from armsrc/LCD.c rename to armsrc/LCD_disabled.c diff --git a/armsrc/LCD.h b/armsrc/LCD_disabled.h similarity index 98% rename from armsrc/LCD.h rename to armsrc/LCD_disabled.h index 968c902465..ed765298fa 100644 --- a/armsrc/LCD.h +++ b/armsrc/LCD_disabled.h @@ -9,10 +9,6 @@ #ifndef __LCD_H #define __LCD_H -#include "proxmark3.h" -#include "apps.h" -#include "fonts.h" - // The resolution of the LCD #define LCD_XRES 132 #define LCD_YRES 132 diff --git a/armsrc/Makefile b/armsrc/Makefile index 488bb0cac0..6a19f7a4dc 100644 --- a/armsrc/Makefile +++ b/armsrc/Makefile @@ -2,16 +2,14 @@ # at your option, any later version. See the LICENSE.txt file for the text of # the license. #----------------------------------------------------------------------------- -# Makefile for armsrc, see ../common/Makefile.common for common settings +# Makefile for armsrc, see ../common_arm/Makefile.common for common settings #----------------------------------------------------------------------------- -APP_INCLUDES = apps.h - # This Makefile might have been called directly, not via the root Makefile, so: ifeq ($(PLTNAME),) -include ../Makefile.platform -include ../.Makefile.options.cache - include ../common/Makefile.hal + include ../common_arm/Makefile.hal # detect if there were changes in the platform definitions, requiring a clean ifeq ($(PLATFORM_CHANGED), true) $(error platform definitions have been changed, please "make clean" at the root of the project) @@ -28,9 +26,10 @@ APP_CFLAGS = $(PLATFORM_DEFS) \ SRC_LF = lfops.c lfsampling.c pcf7931.c lfdemod.c SRC_ISO15693 = iso15693.c iso15693tools.c SRC_ISO14443a = iso14443a.c mifareutil.c mifarecmd.c epa.c mifaresim.c +#UNUSED: mifaresniff.c desfire_crypto.c SRC_ISO14443b = iso14443b.c SRC_FELICA = felica.c -SRC_CRAPTO1 = crypto1.c des.c desfire_key.c desfire_crypto.c mifaredesfire.c aes.c platform_util.c +SRC_CRAPTO1 = crypto1.c des.c desfire_key.c mifaredesfire.c aes.c platform_util.c SRC_CRC = crc.c crc16.c crc32.c SRC_ICLASS = iclass.c optimized_cipher.c SRC_LEGIC = legicrf.c legicrfsim.c legic_prng.c @@ -83,7 +82,7 @@ SRC_ZLIB = inflate.c inffast.c inftrees.c adler32.c zutil.c ZLIB_CFLAGS = -DZ_SOLO -DZ_PREFIX -DNO_GZIP -DZLIB_PM3_TUNED APP_CFLAGS += $(ZLIB_CFLAGS) # zlib includes: -APP_CFLAGS += -I../zlib +APP_CFLAGS += -I../common/zlib # stdint.h provided locally until GCC 4.5 becomes C99 compliant, # stack-protect , no-pie reduces size on Gentoo Hardened 8.2 gcc @@ -91,7 +90,6 @@ APP_CFLAGS += -I. -fno-stack-protector -fno-pie # Compile these in thumb mode (small size) THUMBSRC = start.c \ - protocols.c \ $(SRC_LCD) \ $(SRC_ISO15693) \ $(SRC_NFCBARCODE) \ @@ -105,6 +103,7 @@ THUMBSRC = start.c \ $(SRC_SPIFFS) \ appmain.c \ printf.c \ + dbprint.c \ commonutil.c \ util.c \ string.c \ @@ -131,7 +130,7 @@ VERSIONSRC = version.c \ fpga_version_info.c # Do not move this inclusion before the definition of {THUMB,ASM,ARM}SRC -include ../common/Makefile.common +include ../common_arm/Makefile.common COMMON_FLAGS = -Os @@ -220,3 +219,4 @@ help: @echo Possible targets: @echo + all - Build the full image $(OBJDIR)/fullimage.s19 @echo + clean - Clean $(OBJDIR) + diff --git a/armsrc/Standalone/hf_bog.c b/armsrc/Standalone/hf_bog.c index f8f8322204..6580af7fd5 100644 --- a/armsrc/Standalone/hf_bog.c +++ b/armsrc/Standalone/hf_bog.c @@ -19,7 +19,18 @@ you can simply run 'script run read_pwd_mem' or just 'mem dump p l 256' from the client to view the stored quadlets. */ -#include "hf_bog.h" +#include "standalone.h" // standalone definitions +#include "proxmark3_arm.h" +#include "iso14443a.h" +#include "protocols.h" +#include "util.h" +#include "spiffs.h" +#include "appmain.h" +#include "fpgaloader.h" +#include "dbprint.h" +#include "ticks.h" +#include "BigBuf.h" +#include "string.h" #define DELAY_READER_AIR2ARM_AS_SNIFFER (2 + 3 + 8) #define DELAY_TAG_AIR2ARM_AS_SNIFFER (3 + 14 + 8) @@ -62,10 +73,10 @@ void RAMFUNC SniffAndStore(uint8_t param) { bool ReaderIsActive = false; // Set up the demodulator for tag -> reader responses. - DemodInit(receivedResp, receivedRespPar); + Demod14aInit(receivedResp, receivedRespPar); // Set up the demodulator for the reader -> tag commands - UartInit(receivedCmd, receivedCmdPar); + Uart14aInit(receivedCmd, receivedCmdPar); // Setup and start DMA. if (!FpgaSetupSscDma((uint8_t *)dmaBuf, DMA_BUFFER_SIZE)) { @@ -74,8 +85,8 @@ void RAMFUNC SniffAndStore(uint8_t param) { return; } - tUart *uart = GetUart(); - tDemod *demod = GetDemod(); + tUart14a *uart = GetUart14a(); + tDemod14a *demod = GetDemod14a(); // We won't start recording the frames that we acquire until we trigger; // a good trigger condition to get started is probably when we see a @@ -153,13 +164,13 @@ void RAMFUNC SniffAndStore(uint8_t param) { break; } /* ready to receive another command. */ - UartReset(); + Uart14aReset(); /* reset the demod code, which might have been */ /* false-triggered by the commands from the reader. */ - DemodReset(); + Demod14aReset(); LED_B_OFF(); } - ReaderIsActive = (uart->state != STATE_UNSYNCD); + ReaderIsActive = (uart->state != STATE_14A_UNSYNCD); } // no need to try decoding tag data if the reader is sending - and we cannot afford the time @@ -176,13 +187,13 @@ void RAMFUNC SniffAndStore(uint8_t param) { triggered = true; // ready to receive another response. - DemodReset(); + Demod14aReset(); // reset the Miller decoder including its (now outdated) input buffer - UartReset(); + Uart14aReset(); // UartInit(receivedCmd, receivedCmdPar); LED_C_OFF(); } - TagIsActive = (demod->state != DEMOD_UNSYNCD); + TagIsActive = (demod->state != DEMOD_14A_UNSYNCD); } } diff --git a/armsrc/Standalone/hf_bog.h b/armsrc/Standalone/hf_bog.h deleted file mode 100644 index 50bdf2df8a..0000000000 --- a/armsrc/Standalone/hf_bog.h +++ /dev/null @@ -1,27 +0,0 @@ -//----------------------------------------------------------------------------- -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. -//----------------------------------------------------------------------------- -// StandAlone Mod -//----------------------------------------------------------------------------- - -#ifndef __HF_BOG_H -#define __HF_BOG_H - -#include "proxmark3.h" -#include "mifareutil.h" -#include "iso14443a.h" -#include "protocols.h" -#include "util.h" -#include "standalone.h" // standalone definitions -#include // for bool -#include -#include -#include "apps.h" -#include "printf.h" -#include "parity.h" -#include "spiffs.h" - - -#endif /* __HF_BOG_H */ diff --git a/armsrc/Standalone/hf_colin.c b/armsrc/Standalone/hf_colin.c index 1a461fe217..a45dd71c36 100644 --- a/armsrc/Standalone/hf_colin.c +++ b/armsrc/Standalone/hf_colin.c @@ -8,8 +8,27 @@ //----------------------------------------------------------------------------- // main code for HF Mifare aka ColinRun by Colin Brigato //----------------------------------------------------------------------------- +#include "standalone.h" // standalone definitions +#include // for bool +#include +#include #include "hf_colin.h" +#include "appmain.h" +#include "fpgaloader.h" +#include "dbprint.h" +#include "ticks.h" +#include "commonutil.h" +#include "crc16.h" +#include "BigBuf.h" #include "frozen.h" +#include "proxmark3_arm.h" +#include "mifaresim.h" // mifare1ksim +#include "mifareutil.h" +#include "iso14443a.h" +#include "util.h" +#include "vtsend.h" +#include "spiffs.h" +#include "string.h" #define MF1KSZ 1024 #define MF1KSZSIZE 64 diff --git a/armsrc/Standalone/hf_colin.h b/armsrc/Standalone/hf_colin.h index e669f0417f..ca65a6df4e 100644 --- a/armsrc/Standalone/hf_colin.h +++ b/armsrc/Standalone/hf_colin.h @@ -16,22 +16,6 @@ #ifndef __HF_COLIN_H #define __HF_COLIN_H -#include "proxmark3.h" -#include "mifaresim.h" // mifare1ksim -#include "mifareutil.h" -#include "iso14443a.h" -#include "protocols.h" -#include "util.h" -#include "pmflash.h" -#include "standalone.h" // standalone definitions -#include // for bool -#include -#include -#include "vtsend.h" -#include "apps.h" -#include "printf.h" -#include "spiffs.h" - #define _XRED_ "\x1b[31m" #define _XGREEN_ "\x1b[32m" #define _XYELLOW_ "\x1b[33m" diff --git a/armsrc/Standalone/hf_mattyrun.c b/armsrc/Standalone/hf_mattyrun.c index 485a7c072e..bf13a39c0a 100644 --- a/armsrc/Standalone/hf_mattyrun.c +++ b/armsrc/Standalone/hf_mattyrun.c @@ -33,7 +33,21 @@ on a blank card. ## Spanish full description of the project [here](http://bit.ly/2c9nZXR). */ -#include "hf_mattyrun.h" +#include "standalone.h" // standalone definitions +#include "proxmark3_arm.h" +#include "appmain.h" +#include "fpgaloader.h" +#include "util.h" +#include "dbprint.h" +#include "ticks.h" +#include "string.h" +#include "commonutil.h" +#include "iso14443a.h" +#include "mifarecmd.h" +#include "crc16.h" +#include "BigBuf.h" +#include "mifaresim.h" // mifare1ksim +#include "mifareutil.h" uint8_t uid[10]; uint32_t cuid; diff --git a/armsrc/Standalone/hf_mattyrun.h b/armsrc/Standalone/hf_mattyrun.h deleted file mode 100644 index 5577e298ac..0000000000 --- a/armsrc/Standalone/hf_mattyrun.h +++ /dev/null @@ -1,23 +0,0 @@ -//----------------------------------------------------------------------------- -// Matías A. Ré Medina 2016 -// Christian Herrmann, 2018 -// -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. -//----------------------------------------------------------------------------- -// StandAlone Mod -//----------------------------------------------------------------------------- - -#ifndef __HF_MATTYRUN_H -#define __HF_MATTYRUN_H - -#include "standalone.h" // standalone definitions -#include "apps.h" // debugstatements, lfops? -#include "pm3_cmd.h" // mifare1ksim flags -#include "mifaresim.h" // mifare1ksim -#include "mifareutil.h" - -#define OPTS 2 - -#endif /* __HF_MATTYRUN_H */ diff --git a/armsrc/Standalone/hf_young.c b/armsrc/Standalone/hf_young.c index 7948400ff0..fcf964a5e3 100644 --- a/armsrc/Standalone/hf_young.c +++ b/armsrc/Standalone/hf_young.c @@ -9,8 +9,21 @@ // main code for HF standalone mode Mifare /sniff/emulation by Craig Young //----------------------------------------------------------------------------- -#include "hf_young.h" -#include "common.h" +#include "standalone.h" // standalone definitions +#include +#include "proxmark3_arm.h" +#include "appmain.h" +#include "fpgaloader.h" +#include "util.h" +#include "dbprint.h" +#include "ticks.h" +#include "string.h" +#include "commonutil.h" +#include "mifarecmd.h" +#include "iso14443a.h" +#include "protocols.h" + +#define OPTS 2 typedef struct { uint8_t uid[10]; diff --git a/armsrc/Standalone/hf_young.h b/armsrc/Standalone/hf_young.h deleted file mode 100644 index dcd8b13e71..0000000000 --- a/armsrc/Standalone/hf_young.h +++ /dev/null @@ -1,22 +0,0 @@ -//----------------------------------------------------------------------------- -// Craig Young 2014 -// Christian Herrmann, 2017 -// -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. -//----------------------------------------------------------------------------- -// StandAlone Mod -//----------------------------------------------------------------------------- - -#ifndef __HF_YOUNG_H -#define __HF_YOUNG_H - -#include // for bool -#include "standalone.h" // standalone definitions -#include "iso14443a.h" -#include "protocols.h" - -#define OPTS 2 - -#endif /* __HF_YOUNG_H */ diff --git a/armsrc/Standalone/lf_hidbrute.c b/armsrc/Standalone/lf_hidbrute.c index 2c784c31a0..b659bbdf15 100644 --- a/armsrc/Standalone/lf_hidbrute.c +++ b/armsrc/Standalone/lf_hidbrute.c @@ -24,8 +24,19 @@ //----------------------------------------------------------------------------------- // main code for LF aka HID corporate brutefore by Federico Dotta & Maurizio Agazzini //----------------------------------------------------------------------------------- +#include "standalone.h" // standalone definitions #include "lf_hidbrute.h" +#include "proxmark3_arm.h" +#include "appmain.h" +#include "fpgaloader.h" +#include "util.h" +#include "dbprint.h" +#include "ticks.h" +#include "lfops.h" + +#define OPTS 3 + void ModInfo(void) { DbpString(" LF HID corporate 1000 bruteforce - aka Corporatebrute (Federico dotta & Maurizio Agazzini)"); } diff --git a/armsrc/Standalone/lf_hidbrute.h b/armsrc/Standalone/lf_hidbrute.h index 49b0af6c6c..72e12d305e 100644 --- a/armsrc/Standalone/lf_hidbrute.h +++ b/armsrc/Standalone/lf_hidbrute.h @@ -14,10 +14,7 @@ #ifndef __LF_HIDBRUTE_H #define __LF_HIDBRUTE_H -#include "standalone.h" // standalone definitions -#include "apps.h" // debugstatements, lfops? - -#define OPTS 3 +#include void hid_corporate_1000_calculate_checksum_and_set(uint32_t *high, uint32_t *low, uint32_t cardnum, uint32_t fc); diff --git a/armsrc/Standalone/lf_icerun.c b/armsrc/Standalone/lf_icerun.c index eafd4ca7d6..dad74a75b9 100644 --- a/armsrc/Standalone/lf_icerun.c +++ b/armsrc/Standalone/lf_icerun.c @@ -7,7 +7,12 @@ //----------------------------------------------------------------------------- // main code for skeleton aka IceRun by Iceman //----------------------------------------------------------------------------- -#include "lf_icerun.h" +#include "standalone.h" // standalone definitions +#include "proxmark3_arm.h" +#include "appmain.h" +#include "fpgaloader.h" +#include "util.h" +#include "dbprint.h" void ModInfo(void) { DbpString(" LF skeleton mode - aka IceRun (iceman)"); diff --git a/armsrc/Standalone/lf_proxbrute.c b/armsrc/Standalone/lf_proxbrute.c index 09ddb19896..8044cbde97 100644 --- a/armsrc/Standalone/lf_proxbrute.c +++ b/armsrc/Standalone/lf_proxbrute.c @@ -9,7 +9,16 @@ //----------------------------------------------------------------------------- // main code for LF aka Proxbrute by Brad antoniewicz //----------------------------------------------------------------------------- -#include "lf_proxbrute.h" +#include "standalone.h" // standalone definitions +#include "proxmark3_arm.h" +#include "appmain.h" +#include "fpgaloader.h" +#include "util.h" +#include "dbprint.h" +#include "ticks.h" +#include "lfops.h" + +#define OPTS 2 void ModInfo(void) { DbpString(" LF HID ProxII bruteforce - aka Proxbrute (Brad Antoniewicz)"); diff --git a/armsrc/Standalone/lf_samyrun.c b/armsrc/Standalone/lf_samyrun.c index 07fe8bae57..8228db5122 100644 --- a/armsrc/Standalone/lf_samyrun.c +++ b/armsrc/Standalone/lf_samyrun.c @@ -8,7 +8,16 @@ //----------------------------------------------------------------------------- // main code for LF aka SamyRun by Samy Kamkar //----------------------------------------------------------------------------- -#include "lf_samyrun.h" +#include "standalone.h" // standalone definitions +#include "proxmark3_arm.h" +#include "appmain.h" +#include "fpgaloader.h" +#include "lfops.h" +#include "util.h" +#include "dbprint.h" +#include "ticks.h" + +#define OPTS 2 void ModInfo(void) { DbpString(" LF HID26 standalone - aka SamyRun (Samy Kamkar)"); diff --git a/armsrc/Standalone/lf_samyrun.h b/armsrc/Standalone/lf_samyrun.h deleted file mode 100644 index 52c0bb9424..0000000000 --- a/armsrc/Standalone/lf_samyrun.h +++ /dev/null @@ -1,22 +0,0 @@ -//----------------------------------------------------------------------------- -// Samy Kamkar 2012 -// Christian Herrmann, 2017 -// -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. -//----------------------------------------------------------------------------- -// StandAlone Mod -//----------------------------------------------------------------------------- - -#ifndef __LF_SAMYRUN_H -#define __LF_SAMYRUN_H - -//#include // for bool -#include "standalone.h" // standalone definitions -#include "apps.h" // debugstatements, lfops? - - -#define OPTS 2 - -#endif /* __LF_SAMYRUN_H */ diff --git a/armsrc/Standalone/placeholder.c b/armsrc/Standalone/placeholder.c index b8a426e374..84f724920d 100644 --- a/armsrc/Standalone/placeholder.c +++ b/armsrc/Standalone/placeholder.c @@ -1,5 +1,6 @@ #include "standalone.h" // standalone definitions -#include "apps.h" // debug statements + +#include "dbprint.h" void ModInfo(void) { DbpString(" No standalone mode present"); diff --git a/armsrc/Standalone/standalone.h b/armsrc/Standalone/standalone.h index 217c7b4cfe..2dd35e94a6 100644 --- a/armsrc/Standalone/standalone.h +++ b/armsrc/Standalone/standalone.h @@ -11,9 +11,6 @@ #ifndef __STANDALONE_H #define __STANDALONE_H -#include // for bool -#include // PRIu64 - void RunMod(); void ModInfo(); diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 8f65bc892d..f163e579b5 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -9,26 +9,37 @@ // The main application code. This is the first thing called after start.c // executes. //----------------------------------------------------------------------------- -#include -#include +#include "appmain.h" + #include "usb_cdc.h" -#include "proxmark3.h" +#include "proxmark3_arm.h" +#include "dbprint.h" #include "pmflash.h" -#include "apps.h" #include "fpga.h" -#include "util.h" -#include "printf.h" +#include "fpgaloader.h" #include "string.h" #include "legicrf.h" +#include "BigBuf.h" +#include "iso14443a.h" +#include "iso14443b.h" +#include "iso15693.h" +#include "thinfilm.h" +#include "felica.h" +#include "hitag2.h" +#include "hitagS.h" +#include "iclass.h" #include "legicrfsim.h" +#include "epa.h" +#include "hfsnoop.h" +#include "lfops.h" #include "lfsampling.h" -#include "BigBuf.h" -#include "mifareutil.h" +#include "mifarecmd.h" +#include "mifaredesfire.h" #include "mifaresim.h" -#include "hitag.h" -#include "thinfilm.h" - -#define DEBUG 1 +#include "pcf7931.h" +#include "Standalone/standalone.h" +#include "util.h" +#include "ticks.h" #ifdef WITH_LCD #include "LCD.h" @@ -61,6 +72,12 @@ struct common_area common_area __attribute__((section(".commonarea"))); int button_status = BUTTON_NO_CLICK; bool allow_send_wtx = false; +inline void send_wtx(uint16_t wtx) { + if (allow_send_wtx) { + reply_ng(CMD_WTX, PM3_SUCCESS, (uint8_t *)&wtx, sizeof(wtx)); + } +} + void ToSendReset(void) { ToSendMax = -1; ToSendBit = 8; @@ -84,128 +101,6 @@ void ToSendStuffBit(int b) { } } -/* useful when debugging new protocol implementations like FeliCa -void PrintToSendBuffer(void) { - DbpString("Printing ToSendBuffer:"); - Dbhexdump(ToSendMax, ToSend, 0); -} -*/ - -void print_result(char *name, uint8_t *buf, size_t len) { - - uint8_t *p = buf; - uint16_t tmp = len & 0xFFF0; - - for (; p - buf < tmp; p += 16) { - Dbprintf("[%s: %02d/%02d] %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", - name, - p - buf, - len, - p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15] - ); - } - if (len % 16 != 0) { - char s[46] = {0}; - char *sp = s; - for (; p - buf < len; p++) { - sprintf(sp, "%02x ", p[0]); - sp += 3; - } - Dbprintf("[%s: %02d/%02d] %s", name, p - buf, len, s); - } -} - -//============================================================================= -// Debug print functions, to go out over USB, to the usual PC-side client. -//============================================================================= - -inline void send_wtx(uint16_t wtx) { - if (allow_send_wtx) { - reply_ng(CMD_WTX, PM3_SUCCESS, (uint8_t *)&wtx, sizeof(wtx)); - } -} - -void DbpStringEx(uint32_t flags, char *str) { -#if DEBUG - struct { - uint16_t flag; - uint8_t buf[PM3_CMD_DATA_SIZE - sizeof(uint16_t)]; - } PACKED data; - data.flag = flags; - uint16_t len = MIN(strlen(str), sizeof(data.buf)); - memcpy(data.buf, str, len); - reply_ng(CMD_DEBUG_PRINT_STRING, PM3_SUCCESS, (uint8_t *)&data, sizeof(data.flag) + len); -#endif -} - -void DbpString(char *str) { -#if DEBUG - DbpStringEx(FLAG_LOG, str); -#endif -} - -#if 0 -void DbpIntegers(int x1, int x2, int x3) { - reply_old(CMD_DEBUG_PRINT_INTEGERS, x1, x2, x3, 0, 0); -} -#endif -void DbprintfEx(uint32_t flags, const char *fmt, ...) { -#if DEBUG - // should probably limit size here; oh well, let's just use a big buffer - char output_string[128] = {0x00}; - va_list ap; - va_start(ap, fmt); - kvsprintf(fmt, output_string, 10, ap); - va_end(ap); - - DbpStringEx(flags, output_string); -#endif -} - -void Dbprintf(const char *fmt, ...) { -#if DEBUG - // should probably limit size here; oh well, let's just use a big buffer - char output_string[128] = {0x00}; - va_list ap; - - va_start(ap, fmt); - kvsprintf(fmt, output_string, 10, ap); - va_end(ap); - - DbpString(output_string); -#endif -} - -// prints HEX & ASCII -void Dbhexdump(int len, uint8_t *d, bool bAsci) { -#if DEBUG - char ascii[9]; - - while (len > 0) { - - int l = (len > 8) ? 8 : len; - - memcpy(ascii, d, l); - ascii[l] = 0; - - // filter safe ascii - for (int i = 0; i < l; i++) { - if (ascii[i] < 32 || ascii[i] > 126) { - ascii[i] = '.'; - } - } - - if (bAsci) - Dbprintf("%-8s %*D", ascii, l, d, " "); - else - Dbprintf("%*D", l, d, " "); - - len -= 8; - d += 8; - } -#endif -} - //----------------------------------------------------------------------------- // Read an ADC channel and block till it completes, then return the result // in ADC units (0 to 1023). Also a routine to average 32 samples and diff --git a/armsrc/appmain.h b/armsrc/appmain.h new file mode 100644 index 0000000000..fa35714e39 --- /dev/null +++ b/armsrc/appmain.h @@ -0,0 +1,45 @@ +//----------------------------------------------------------------------------- +// Jonathan Westhues, Aug 2005 +// Gerhard de Koning Gans, April 2008, May 2011 +// +// This code is licensed to you under the terms of the GNU GPL, version 2 or, +// at your option, any later version. See the LICENSE.txt file for the text of +// the license. +//----------------------------------------------------------------------------- +// Definitions internal to the app source. +//----------------------------------------------------------------------------- +#ifndef __APPMAIN_H +#define __APPMAIN_H + +#include "common.h" + +extern const uint8_t OddByteParity[256]; +extern int rsamples; // = 0; +extern uint8_t trigger; +extern bool allow_send_wtx; + +// ADC Vref = 3300mV, and an (10M+1M):1M voltage divider on the HF input can measure voltages up to 36300 mV +#define MAX_ADC_HF_VOLTAGE 36300 +// ADC Vref = 3300mV, (240k-10M):240k voltage divider, 140800 mV +#define MAX_ADC_HF_VOLTAGE_RDV40 140800 +// ADC Vref = 3300mV, and an (10000k+240k):240k voltage divider on the LF input can measure voltages up to 140800 mV +#define MAX_ADC_LF_VOLTAGE 140800 + +extern int ToSendMax; +extern uint8_t ToSend[]; + +void send_wtx(uint16_t wtx); +void ReadMem(int addr); +void __attribute__((noreturn)) AppMain(void); + +uint16_t AvgAdc(int ch); + +void print_result(char *name, uint8_t *buf, size_t len); +//void PrintToSendBuffer(void); +void ToSendStuffBit(int b); +void ToSendReset(void); +void ListenReaderField(uint8_t limit); +void StandAloneMode(void); +void printStandAloneModes(void); + +#endif diff --git a/armsrc/apps.h b/armsrc/apps.h deleted file mode 100644 index 7cc4018578..0000000000 --- a/armsrc/apps.h +++ /dev/null @@ -1,254 +0,0 @@ -//----------------------------------------------------------------------------- -// Jonathan Westhues, Aug 2005 -// Gerhard de Koning Gans, April 2008, May 2011 -// -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. -//----------------------------------------------------------------------------- -// Definitions internal to the app source. -//----------------------------------------------------------------------------- -#ifndef __APPS_H -#define __APPS_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include "common.h" -#include "usb_cdc.h" -#include "crc32.h" -#include "lfdemod.h" -#include "BigBuf.h" -#include "fpgaloader.h" -#include "hitag2.h" -#include "hitagS.h" -#include "mifare.h" -#include "pcf7931.h" -#include "desfire.h" -#include "iso14443b.h" -#include "Standalone/standalone.h" -#include "flashmem.h" - -extern const uint8_t OddByteParity[256]; -extern int rsamples; // = 0; -extern uint8_t trigger; - -// This may be used (sparingly) to declare a function to be copied to -// and executed from RAM -#define RAMFUNC __attribute((long_call, section(".ramfunc"))) - -/// appmain.h -void ReadMem(int addr); -void __attribute__((noreturn)) AppMain(void); -void send_wtx(uint16_t wtx); -//void DbpIntegers(int a, int b, int c); -void DbpString(char *str); -void DbpStringEx(uint32_t flags, char *str); -void Dbprintf(const char *fmt, ...); -void DbprintfEx(uint32_t flags, const char *fmt, ...); -void Dbhexdump(int len, uint8_t *d, bool bAsci); - -// ADC Vref = 3300mV, and an (10M+1M):1M voltage divider on the HF input can measure voltages up to 36300 mV -#define MAX_ADC_HF_VOLTAGE 36300 -// ADC Vref = 3300mV, (240k-10M):240k voltage divider, 140800 mV -#define MAX_ADC_HF_VOLTAGE_RDV40 140800 -// ADC Vref = 3300mV, and an (10000k+240k):240k voltage divider on the LF input can measure voltages up to 140800 mV -#define MAX_ADC_LF_VOLTAGE 140800 -uint16_t AvgAdc(int ch); - -void print_result(char *name, uint8_t *buf, size_t len); -//void PrintToSendBuffer(void); -void ToSendStuffBit(int b); -void ToSendReset(void); -void ListenReaderField(uint8_t limit); -extern int ToSendMax; -extern uint8_t ToSend[]; - -void StandAloneMode(void); -void printStandAloneModes(void); - -/// lfops.h -extern uint8_t decimation; -extern uint8_t bits_per_sample ; -extern bool averaging; - -void AcquireRawAdcSamples125k(int divisor); -void ModThenAcquireRawAdcSamples125k(uint32_t delay_off, uint32_t period_0, uint32_t period_1, uint8_t *command); -void ReadTItag(void); -void WriteTItag(uint32_t idhi, uint32_t idlo, uint16_t crc); - -void AcquireTiType(void); -void AcquireRawBitsTI(void); -void SimulateTagLowFrequencyEx(int period, int gap, bool ledcontrol, int numcycles); -void SimulateTagLowFrequency(int period, int gap, bool ledcontrol); -void SimulateTagLowFrequencyBidir(int divisor, int max_bitlen); - -void CmdHIDsimTAGEx(uint32_t hi, uint32_t lo, bool ledcontrol, int numcycles); -void CmdHIDsimTAG(uint32_t hi, uint32_t lo, bool ledcontrol); - -void CmdFSKsimTAG(uint8_t fchigh, uint8_t fclow, uint8_t separator, uint8_t clk, uint16_t bitslen, uint8_t *bits, bool ledcontrol); -void CmdASKsimTAG(uint8_t encoding, uint8_t invert, uint8_t separator, uint8_t clk, uint16_t size, uint8_t *bits, bool ledcontrol); -void CmdPSKsimTag(uint8_t carrier, uint8_t invert, uint8_t clk, uint16_t size, uint8_t *bits, bool ledcontrol); - -void CmdHIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol); -void CmdAWIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol); // Realtime demodulation mode for AWID26 -void CmdEM410xdemod(int findone, uint32_t *high, uint64_t *low, int ledcontrol); -void CmdIOdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol); -void CopyIOtoT55x7(uint32_t hi, uint32_t lo); // Clone an ioProx card to T5557/T5567 -void CopyHIDtoT55x7(uint32_t hi2, uint32_t hi, uint32_t lo, uint8_t longFMT); // Clone an HID card to T5557/T5567 -void CopyVikingtoT55xx(uint32_t block1, uint32_t block2, uint8_t Q5); -void WriteEM410x(uint32_t card, uint32_t id_hi, uint32_t id_lo); -void CopyIndala64toT55x7(uint32_t hi, uint32_t lo); // Clone Indala 64-bit tag by UID to T55x7 -void CopyIndala224toT55x7(uint32_t uid1, uint32_t uid2, uint32_t uid3, uint32_t uid4, uint32_t uid5, uint32_t uid6, uint32_t uid7); // Clone Indala 224-bit tag by UID to T55x7 -void T55xxResetRead(uint8_t flags); -//id T55xxWriteBlock(uint32_t data, uint8_t blockno, uint32_t pwd, uint8_t flags); -void T55xxWriteBlock(uint8_t *data); -// void T55xxWriteBlockExt(uint32_t data, uint8_t blockno, uint32_t pwd, uint8_t flags); -void T55xxReadBlock(uint8_t page, bool pwd_mode, bool brute_mem, uint8_t block, uint32_t pwd, uint8_t downlink_mode); -void T55xxWakeUp(uint32_t pwd, uint8_t flags); -void T55xx_ChkPwds(uint8_t flags); - -void TurnReadLFOn(uint32_t delay); - -void EM4xReadWord(uint8_t addr, uint32_t pwd, uint8_t usepwd); -void EM4xWriteWord(uint8_t addr, uint32_t data, uint32_t pwd, uint8_t usepwd); - -void Cotag(uint32_t arg0); -void setT55xxConfig(uint8_t arg0, t55xx_configurations_t *c); -t55xx_configurations_t *getT55xxConfig(void); -void printT55xxConfig(void); -void loadT55xxConfig(void); - -/// iso14443b.h -void SimulateIso14443bTag(uint32_t pupi); -void AcquireRawAdcSamplesIso14443b(uint32_t parameter); -void ReadSTMemoryIso14443b(uint8_t numofblocks); -void RAMFUNC SniffIso14443b(void); -void SendRawCommand14443B(uint32_t, uint32_t, uint8_t, uint8_t[]); -void SendRawCommand14443B_Ex(PacketCommandNG *c); -void ClearFpgaShiftingRegisters(void); - -// iso14443a.h -void RAMFUNC SniffIso14443a(uint8_t param); -void ReaderIso14443a(PacketCommandNG *c); - -// Also used in iclass.c -//bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t len, uint32_t timestamp_start, uint32_t timestamp_end, uint8_t *parity, bool readerToTag); -void GetParity(const uint8_t *pbtCmd, uint16_t len, uint8_t *par); -void iso14a_set_trigger(bool enable); -// also used in emv -//bool prepare_allocated_tag_modulation(tag_response_info_t *response_info); -//int GetIso14443aCommandFromReader(uint8_t *received, uint8_t *parity, int *len); - -// epa.h -void EPA_PACE_Collect_Nonce(PacketCommandNG *c); -void EPA_PACE_Replay(PacketCommandNG *c); - -// mifarecmd.h -void MifareReadBlock(uint8_t blockNo, uint8_t keyType, uint8_t *datain); - -void MifareUReadBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain); -void MifareUC_Auth(uint8_t arg0, uint8_t *keybytes); -void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain); -void MifareReadSector(uint8_t arg0, uint8_t arg1, uint8_t *datain); -void MifareWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain); -//void MifareUWriteBlockCompat(uint8_t arg0,uint8_t *datain); -void MifareUWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain); -void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain); -void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags, uint8_t *datain); -void MifareAcquireNonces(uint32_t arg0, uint32_t flags); -void MifareChkKeys(uint8_t *datain); -void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain); - -void MifareEMemClr(void); -void MifareEMemSet(uint8_t blockno, uint8_t blockcnt, uint8_t blockwidth, uint8_t *datain); -void MifareEMemGet(uint8_t blockno, uint8_t blockcnt); -int MifareECardLoad(uint32_t arg0, uint32_t arg1); - -void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain); // Work with "magic Chinese" card -void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain); -void MifareCIdent(); // is "magic chinese" card? - -void MifareSetMod(uint8_t *datain); -void MifareUSetPwd(uint8_t arg0, uint8_t *datain); -void OnSuccessMagic(); -void OnErrorMagic(uint8_t reason); - -int32_t dist_nt(uint32_t nt1, uint32_t nt2); -void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype); -//void RAMFUNC SniffMifare(uint8_t param); - -//desfire -void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain); -void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain); - -// mifaredesfire.h -bool InitDesfireCard(); -void MifareSendCommand(uint8_t arg0, uint8_t arg1, uint8_t *datain); -void MifareDesfireGetInformation(); -void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain); -void ReaderMifareDES(uint32_t param, uint32_t param2, uint8_t *datain); -int DesfireAPDU(uint8_t *cmd, size_t cmd_len, uint8_t *dataout); -size_t CreateAPDU(uint8_t *datain, size_t len, uint8_t *dataout); -void OnSuccess(); -void OnError(uint8_t reason); - -// desfire_crypto.h -void *mifare_cryto_preprocess_data(desfiretag_t tag, void *data, size_t *nbytes, size_t offset, int communication_settings); -void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes, int communication_settings); -void mifare_cypher_single_block(desfirekey_t key, uint8_t *data, uint8_t *ivect, MifareCryptoDirection direction, MifareCryptoOperation operation, size_t block_size); -void mifare_cypher_blocks_chained(desfiretag_t tag, desfirekey_t key, uint8_t *ivect, uint8_t *data, size_t data_size, MifareCryptoDirection direction, MifareCryptoOperation operation); -size_t key_block_size(const desfirekey_t key); -size_t padded_data_length(const size_t nbytes, const size_t block_size); -size_t maced_data_length(const desfirekey_t key, const size_t nbytes); -size_t enciphered_data_length(const desfiretag_t tag, const size_t nbytes, int communication_settings); -void cmac_generate_subkeys(desfirekey_t key); -void cmac(const desfirekey_t key, uint8_t *ivect, const uint8_t *data, size_t len, uint8_t *cmac); - -// iso15693.h -void RecordRawAdcSamplesIso15693(void); -void AcquireRawAdcSamplesIso15693(void); -void ReaderIso15693(uint32_t parameter); // Simulate an ISO15693 reader - greg -void SimTagIso15693(uint32_t parameter, uint8_t *uid); // simulate an ISO15693 tag - greg -void BruteforceIso15693Afi(uint32_t speed); // find an AFI of a tag - atrox -void DirectTag15693Command(uint32_t datalen, uint32_t speed, uint32_t recv, uint8_t *data); // send arbitrary commands from CLI - atrox -void Iso15693InitReader(void); - -// iclass.h -void RAMFUNC SniffIClass(void); -void SimulateIClass(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain); -void ReaderIClass(uint8_t arg0); -void ReaderIClass_Replay(uint8_t arg0, uint8_t *mac); -void iClass_Authentication(uint8_t *mac); -void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain); -void iClass_WriteBlock(uint8_t blockno, uint8_t *data); -void iClass_ReadBlk(uint8_t blockno); -bool iClass_ReadBlock(uint8_t blockno, uint8_t *data, uint8_t len); -void iClass_Dump(uint8_t blockno, uint8_t numblks); -void iClass_Clone(uint8_t startblock, uint8_t endblock, uint8_t *data); -void iClass_ReadCheck(uint8_t blockno, uint8_t keytype); - -// cmd.h -int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len); -int reply_mix(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len); -int reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len); -int receive_ng(PacketCommandNG *rx); - -// util.h -void HfSniff(int, int); - -//felica.c -void felica_sendraw(PacketCommandNG *c); -void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip); -void felica_sim_lite(uint64_t uid); -void felica_dump_lite_s(); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/armsrc/buzzer.c b/armsrc/buzzer_disabled.c similarity index 100% rename from armsrc/buzzer.c rename to armsrc/buzzer_disabled.c diff --git a/armsrc/buzzer.h b/armsrc/buzzer_disabled.h similarity index 84% rename from armsrc/buzzer.h rename to armsrc/buzzer_disabled.h index 082450f043..c8b6e44721 100644 --- a/armsrc/buzzer.h +++ b/armsrc/buzzer_disabled.h @@ -5,10 +5,7 @@ #ifndef __BUZZER_H #define __BUZZER_H -#include -#include "proxmark3.h" -#include "apps.h" -#include "util.h" +#include "common.h" #define n_2_7khz 185 #define note_1 956 @@ -27,24 +24,3 @@ void Ring_ALL(uint16_t count); void Ring_Little_Star(uint16_t count); #endif - - - - - - - - - - - - - - - - - - - - - diff --git a/common/cmd.c b/armsrc/cmd.c similarity index 99% rename from common/cmd.c rename to armsrc/cmd.c index 6af0437d10..4b6dd3c1c4 100644 --- a/common/cmd.c +++ b/armsrc/cmd.c @@ -30,7 +30,10 @@ * @brief */ #include "cmd.h" +#include "usb_cdc.h" +#include "usart.h" #include "crc16.h" +#include "string.h" // Flags to tell where to add CRC on sent replies bool reply_with_crc_on_usb = false; diff --git a/common/cmd.h b/armsrc/cmd.h similarity index 71% rename from common/cmd.h rename to armsrc/cmd.h index 261a1e1a06..e04f397a32 100644 --- a/common/cmd.h +++ b/armsrc/cmd.h @@ -35,14 +35,6 @@ #include "common.h" #include "pm3_cmd.h" -#include "usb_cdc.h" -#include "usart.h" -#include "proxmark3.h" - -int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len); -int reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len); -int reply_mix(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len); -int receive_ng(PacketCommandNG *rx); // Flags to tell where to add CRC on sent replies extern bool reply_with_crc_on_usb; @@ -51,33 +43,10 @@ extern bool reply_with_crc_on_fpc; extern bool reply_via_fpc; extern bool reply_via_usb; -extern void Dbprintf(const char *fmt, ...); -#define Dbprintf_usb(...) {\ - bool tmpfpc = reply_via_fpc;\ - bool tmpusb = reply_via_usb;\ - reply_via_fpc = false;\ - reply_via_usb = true;\ - Dbprintf(__VA_ARGS__);\ - reply_via_fpc = tmpfpc;\ - reply_via_usb = tmpusb;} - -#define Dbprintf_fpc(...) {\ - bool tmpfpc = reply_via_fpc;\ - bool tmpusb = reply_via_usb;\ - reply_via_fpc = true;\ - reply_via_usb = false;\ - Dbprintf(__VA_ARGS__);\ - reply_via_fpc = tmpfpc;\ - reply_via_usb = tmpusb;} - -#define Dbprintf_all(...) {\ - bool tmpfpc = reply_via_fpc;\ - bool tmpusb = reply_via_usb;\ - reply_via_fpc = true;\ - reply_via_usb = true;\ - Dbprintf(__VA_ARGS__);\ - reply_via_fpc = tmpfpc;\ - reply_via_usb = tmpusb;} +int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len); +int reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len); +int reply_mix(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len); +int receive_ng(PacketCommandNG *rx); #endif // _PROXMARK_CMD_H_ diff --git a/armsrc/dbprint.c b/armsrc/dbprint.c new file mode 100644 index 0000000000..a26b7ba8b6 --- /dev/null +++ b/armsrc/dbprint.c @@ -0,0 +1,130 @@ +//----------------------------------------------------------------------------- +// Jonathan Westhues, Mar 2006 +// Edits by Gerhard de Koning Gans, Sep 2007 (##) +// +// This code is licensed to you under the terms of the GNU GPL, version 2 or, +// at your option, any later version. See the LICENSE.txt file for the text of +// the license. +//----------------------------------------------------------------------------- +// The main application code. This is the first thing called after start.c +// executes. +//----------------------------------------------------------------------------- + +#include "dbprint.h" + +#include "string.h" +#include "cmd.h" +#include "printf.h" + +#define DEBUG 1 + +//============================================================================= +// Debug print functions, to go out over USB, to the usual PC-side client. +//============================================================================= + +void DbpStringEx(uint32_t flags, char *str) { +#if DEBUG + struct { + uint16_t flag; + uint8_t buf[PM3_CMD_DATA_SIZE - sizeof(uint16_t)]; + } PACKED data; + data.flag = flags; + uint16_t len = MIN(strlen(str), sizeof(data.buf)); + memcpy(data.buf, str, len); + reply_ng(CMD_DEBUG_PRINT_STRING, PM3_SUCCESS, (uint8_t *)&data, sizeof(data.flag) + len); +#endif +} + +void DbpString(char *str) { +#if DEBUG + DbpStringEx(FLAG_LOG, str); +#endif +} + +void DbprintfEx(uint32_t flags, const char *fmt, ...) { +#if DEBUG + // should probably limit size here; oh well, let's just use a big buffer + char output_string[128] = {0x00}; + va_list ap; + va_start(ap, fmt); + kvsprintf(fmt, output_string, 10, ap); + va_end(ap); + + DbpStringEx(flags, output_string); +#endif +} + +void Dbprintf(const char *fmt, ...) { +#if DEBUG + // should probably limit size here; oh well, let's just use a big buffer + char output_string[128] = {0x00}; + va_list ap; + + va_start(ap, fmt); + kvsprintf(fmt, output_string, 10, ap); + va_end(ap); + + DbpString(output_string); +#endif +} + +// prints HEX & ASCII +void Dbhexdump(int len, uint8_t *d, bool bAsci) { +#if DEBUG + char ascii[9]; + + while (len > 0) { + + int l = (len > 8) ? 8 : len; + + memcpy(ascii, d, l); + ascii[l] = 0; + + // filter safe ascii + for (int i = 0; i < l; i++) { + if (ascii[i] < 32 || ascii[i] > 126) { + ascii[i] = '.'; + } + } + + if (bAsci) + Dbprintf("%-8s %*D", ascii, l, d, " "); + else + Dbprintf("%*D", l, d, " "); + + len -= 8; + d += 8; + } +#endif +} + +void print_result(char *name, uint8_t *buf, size_t len) { + + uint8_t *p = buf; + uint16_t tmp = len & 0xFFF0; + + for (; p - buf < tmp; p += 16) { + Dbprintf("[%s: %02d/%02d] %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", + name, + p - buf, + len, + p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15] + ); + } + if (len % 16 != 0) { + char s[46] = {0}; + char *sp = s; + for (; p - buf < len; p++) { + sprintf(sp, "%02x ", p[0]); + sp += 3; + } + Dbprintf("[%s: %02d/%02d] %s", name, p - buf, len, s); + } +} + +/* useful when debugging new protocol implementations like FeliCa +void PrintToSendBuffer(void) { + DbpString("Printing ToSendBuffer:"); + Dbhexdump(ToSendMax, ToSend, 0); +} +*/ diff --git a/armsrc/dbprint.h b/armsrc/dbprint.h new file mode 100644 index 0000000000..54b813218b --- /dev/null +++ b/armsrc/dbprint.h @@ -0,0 +1,53 @@ +//----------------------------------------------------------------------------- +// Jonathan Westhues, Aug 2005 +// Gerhard de Koning Gans, April 2008, May 2011 +// +// This code is licensed to you under the terms of the GNU GPL, version 2 or, +// at your option, any later version. See the LICENSE.txt file for the text of +// the license. +//----------------------------------------------------------------------------- +// Definitions internal to the app source. +//----------------------------------------------------------------------------- +#ifndef __DBPRINT_H +#define __DBPRINT_H + +#include "common.h" +#include "ansi.h" + +#define Dbprintf_usb(...) {\ + bool tmpfpc = reply_via_fpc;\ + bool tmpusb = reply_via_usb;\ + reply_via_fpc = false;\ + reply_via_usb = true;\ + Dbprintf(__VA_ARGS__);\ + reply_via_fpc = tmpfpc;\ + reply_via_usb = tmpusb;} + +#define Dbprintf_fpc(...) {\ + bool tmpfpc = reply_via_fpc;\ + bool tmpusb = reply_via_usb;\ + reply_via_fpc = true;\ + reply_via_usb = false;\ + Dbprintf(__VA_ARGS__);\ + reply_via_fpc = tmpfpc;\ + reply_via_usb = tmpusb;} + +#define Dbprintf_all(...) {\ + bool tmpfpc = reply_via_fpc;\ + bool tmpusb = reply_via_usb;\ + reply_via_fpc = true;\ + reply_via_usb = true;\ + Dbprintf(__VA_ARGS__);\ + reply_via_fpc = tmpfpc;\ + reply_via_usb = tmpusb;} + + +void DbpString(char *str); +void DbpStringEx(uint32_t flags, char *str); +void Dbprintf(const char *fmt, ...); +void DbprintfEx(uint32_t flags, const char *fmt, ...); +void Dbhexdump(int len, uint8_t *d, bool bAsci); +void print_result(char *name, uint8_t *buf, size_t len); +//void PrintToSendBuffer(void); + +#endif diff --git a/armsrc/des.c b/armsrc/des.c index 41b30734c7..b84bc4c303 100644 --- a/armsrc/des.c +++ b/armsrc/des.c @@ -27,6 +27,7 @@ */ #include "des.h" +#include "string.h" const uint8_t sbox[256] = { /* S-box 1 */ diff --git a/armsrc/des.h b/armsrc/des.h index 0d2cceefbc..8cf41b8ae2 100644 --- a/armsrc/des.h +++ b/armsrc/des.h @@ -27,8 +27,7 @@ #ifndef __DES_H_ #define __DES_H_ -#include -#include +#include "common.h" /* the FIPS 46-3 (1999-10-25) name for triple DES is triple data encryption algorithm so TDEA. * Also we only implement the three key mode */ diff --git a/common/desfire.h b/armsrc/desfire.h similarity index 98% rename from common/desfire.h rename to armsrc/desfire.h index 41e5b6e12a..5fa7e8d486 100644 --- a/common/desfire.h +++ b/armsrc/desfire.h @@ -1,9 +1,7 @@ #ifndef __DESFIRE_H #define __DESFIRE_H -#include -#include -#include "mbedtls/aes.h" +#include "common.h" #include "mifare.h" #define MAX_CRYPTO_BLOCK_SIZE 16 diff --git a/armsrc/desfire_crypto.h b/armsrc/desfire_crypto.h deleted file mode 100644 index 9964d094ff..0000000000 --- a/armsrc/desfire_crypto.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef __DESFIRE_CRYPTO_H -#define __DESFIRE_CRYPTO_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include "crc32.h" -#include "printf.h" -#include "desfire.h" -#include "iso14443a.h" - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/armsrc/desfire_crypto.c b/armsrc/desfire_crypto_disabled.c similarity index 99% rename from armsrc/desfire_crypto.c rename to armsrc/desfire_crypto_disabled.c index 2e9d5a8d3f..d835a55d46 100644 --- a/armsrc/desfire_crypto.c +++ b/armsrc/desfire_crypto_disabled.c @@ -25,8 +25,16 @@ * Recommendation for Block Cipher Modes of Operation: The CMAC Mode for Authentication * May 2005 */ +#include + #include "desfire_crypto.h" +#include "crc32.h" +#include "printf.h" +#include "desfire.h" +#include "iso14443a.h" +#include "mbedtls/aes.h" + static void xor(const uint8_t *ivect, uint8_t *data, const size_t len); static size_t key_macing_length(desfirekey_t key); diff --git a/armsrc/desfire_crypto_disabled.h b/armsrc/desfire_crypto_disabled.h new file mode 100644 index 0000000000..23043b30d1 --- /dev/null +++ b/armsrc/desfire_crypto_disabled.h @@ -0,0 +1,18 @@ +#ifndef __DESFIRE_CRYPTO_H +#define __DESFIRE_CRYPTO_H + +#include "common.h" +#include "desfire.h" + +void *mifare_cryto_preprocess_data(desfiretag_t tag, void *data, size_t *nbytes, size_t offset, int communication_settings); +void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes, int communication_settings); +void mifare_cypher_single_block(desfirekey_t key, uint8_t *data, uint8_t *ivect, MifareCryptoDirection direction, MifareCryptoOperation operation, size_t block_size); +void mifare_cypher_blocks_chained(desfiretag_t tag, desfirekey_t key, uint8_t *ivect, uint8_t *data, size_t data_size, MifareCryptoDirection direction, MifareCryptoOperation operation); +size_t key_block_size(const desfirekey_t key); +size_t padded_data_length(const size_t nbytes, const size_t block_size); +size_t maced_data_length(const desfirekey_t key, const size_t nbytes); +size_t enciphered_data_length(const desfiretag_t tag, const size_t nbytes, int communication_settings); +void cmac_generate_subkeys(desfirekey_t key); +void cmac(const desfirekey_t key, uint8_t *ivect, const uint8_t *data, size_t len, uint8_t *cmac); + +#endif diff --git a/armsrc/desfire_key.c b/armsrc/desfire_key.c index e1f880c8ba..272f18562b 100644 --- a/armsrc/desfire_key.c +++ b/armsrc/desfire_key.c @@ -18,6 +18,7 @@ */ #include "desfire_key.h" +#include "string.h" static inline void update_key_schedules(desfirekey_t key); diff --git a/armsrc/desfire_key.h b/armsrc/desfire_key.h index 4fc02854e4..603fd56638 100644 --- a/armsrc/desfire_key.h +++ b/armsrc/desfire_key.h @@ -1,11 +1,8 @@ #ifndef __DESFIRE_KEY_INCLUDED #define __DESFIRE_KEY_INCLUDED -#include -#include -#include "iso14443a.h" +#include "common.h" #include "desfire.h" -//#include "mifare.h" // iso14a_card_select_t struct void Desfire_des_key_new(const uint8_t value[8], desfirekey_t key); void Desfire_3des_key_new(const uint8_t value[16], desfirekey_t key); void Desfire_des_key_new_with_version(const uint8_t value[8], desfirekey_t key); @@ -17,4 +14,5 @@ void Desfire_aes_key_new_with_version(const uint8_t value[16], uint8_t version, uint8_t Desfire_key_get_version(desfirekey_t key); void Desfire_key_set_version(desfirekey_t key, uint8_t version); void Desfire_session_key_new(const uint8_t rnda[], const uint8_t rndb[], desfirekey_t authkey, desfirekey_t key); + #endif diff --git a/common/emvtags.h b/armsrc/emvtags.h similarity index 99% rename from common/emvtags.h rename to armsrc/emvtags.h index 9315258fcd..c64b248a3a 100644 --- a/common/emvtags.h +++ b/armsrc/emvtags.h @@ -12,8 +12,7 @@ #ifndef __EMVCARD_H #define __EMVCARD_H -#include -#include +#include "common.h" //structure to hold received/set tag values //variable data inputs have length specifiers diff --git a/armsrc/epa.c b/armsrc/epa.c index 7ccb0a8f6a..c43b35c98a 100644 --- a/armsrc/epa.c +++ b/armsrc/epa.c @@ -12,6 +12,16 @@ //----------------------------------------------------------------------------- #include "epa.h" +#include "cmd.h" +#include "fpgaloader.h" +#include "iso14443a.h" +#include "iso14443b.h" +#include "string.h" +#include "util.h" +#include "dbprint.h" +#include "commonutil.h" +#include "ticks.h" + // Protocol and Parameter Selection Request for ISO 14443 type A cards // use regular (1x) speed in both directions // CRC is already included diff --git a/armsrc/epa.h b/armsrc/epa.h index a0701ab578..66a95c0595 100644 --- a/armsrc/epa.h +++ b/armsrc/epa.h @@ -11,9 +11,8 @@ #ifndef __EPA_H #define __EPA_H -#include "cmd.h" -#include "iso14443a.h" -#include "iso14443b.h" +#include "common.h" +#include "pm3_cmd.h" // this struct is used by EPA_Parse_CardAccess and contains info about the // PACE protocol supported by the chip @@ -23,8 +22,6 @@ typedef struct { uint8_t parameter_id; } pace_version_info_t; -// note: EPA_PACE_Collect_Nonce and EPA_PACE_Replay are declared in apps.h - // general functions void EPA_Finish(); size_t EPA_Parse_CardAccess(uint8_t *data, @@ -37,4 +34,7 @@ int EPA_Setup(); int EPA_PACE_MSE_Set_AT(pace_version_info_t pace_version_info, uint8_t password); int EPA_PACE_Get_Nonce(uint8_t requested_length, uint8_t *nonce); +void EPA_PACE_Collect_Nonce(PacketCommandNG *c); +void EPA_PACE_Replay(PacketCommandNG *c); + #endif /* __EPA_H */ diff --git a/armsrc/felica.c b/armsrc/felica.c index b732683e58..322d113277 100644 --- a/armsrc/felica.c +++ b/armsrc/felica.c @@ -1,10 +1,15 @@ -#include "proxmark3.h" -#include "apps.h" +#include "felica.h" +#include "proxmark3_arm.h" #include "BigBuf.h" #include "util.h" -#include "usb_cdc.h" // for usb_poll_validate_length #include "protocols.h" #include "crc16.h" // crc16 ccitt +#include "fpgaloader.h" +#include "string.h" +#include "commonutil.h" +#include "dbprint.h" +#include "ticks.h" +#include "mifare.h" // FeliCa timings // minimum time between the start bits of consecutive transfers from reader to tag: 6800 carrier (13.56MHz) cycles diff --git a/armsrc/Standalone/lf_proxbrute.h b/armsrc/felica.h similarity index 52% rename from armsrc/Standalone/lf_proxbrute.h rename to armsrc/felica.h index 3a9e1ce292..ef34dc108d 100644 --- a/armsrc/Standalone/lf_proxbrute.h +++ b/armsrc/felica.h @@ -1,21 +1,22 @@ //----------------------------------------------------------------------------- -// Samy Kamkar, 2011, 2012 -// Brad antoniewicz 2011 -// Christian Herrmann, 2017 +// Jonathan Westhues, Aug 2005 +// Gerhard de Koning Gans, April 2008, May 2011 // // This code is licensed to you under the terms of the GNU GPL, version 2 or, // at your option, any later version. See the LICENSE.txt file for the text of // the license. //----------------------------------------------------------------------------- -// StandAlone Mod +// Definitions internal to the app source. //----------------------------------------------------------------------------- +#ifndef __FELICA_H +#define __FELICA_H -#ifndef __LF_PROXBRUTE_H -#define __LF_PROXBRUTE_H +#include "common.h" +#include "cmd.h" -#include "standalone.h" // standalone definitions -#include "apps.h" // debugstatements, lfops? +void felica_sendraw(PacketCommandNG *c); +void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip); +void felica_sim_lite(uint64_t uid); +void felica_dump_lite_s(); -#define OPTS 2 - -#endif /* __LF_PROXBRUTE_H */ +#endif diff --git a/armsrc/flashmem.c b/armsrc/flashmem.c index 19c249ffe1..fb69dee016 100644 --- a/armsrc/flashmem.c +++ b/armsrc/flashmem.c @@ -1,6 +1,11 @@ #include "flashmem.h" #include "pmflash.h" +#include "proxmark3_arm.h" +#include "ticks.h" +#include "dbprint.h" +#include "string.h" + /* here: use NCPS2 @ PA10: */ #define SPI_CSR_NUM 2 #define SPI_PCS(npcs) ((~(1 << (npcs)) & 0xF) << 16) diff --git a/armsrc/flashmem.h b/armsrc/flashmem.h index b332ec3f59..42fc3d2f05 100644 --- a/armsrc/flashmem.h +++ b/armsrc/flashmem.h @@ -28,9 +28,7 @@ #ifndef __FLASHMEM_H #define __FLASHMEM_H -#include "proxmark3.h" -#include "apps.h" -#include "ticks.h" +#include "common.h" // Used Command #define ID 0x90 @@ -111,7 +109,6 @@ #define FASTFLASH (FLASHMEM_SPIBAUDRATE > FLASH_MINFAST) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// -void Dbprintf(const char *fmt, ...); void FlashmemSetSpiBaudrate(uint32_t baudrate); bool FlashInit(); diff --git a/armsrc/fpgaloader.c b/armsrc/fpgaloader.c index b5543a7d2f..87213df96d 100644 --- a/armsrc/fpgaloader.c +++ b/armsrc/fpgaloader.c @@ -11,6 +11,15 @@ //----------------------------------------------------------------------------- #include "fpgaloader.h" +#include "proxmark3_arm.h" +#include "appmain.h" +#include "BigBuf.h" +#include "ticks.h" +#include "dbprint.h" +#include "util.h" +#include "zlib.h" +#include "fpga.h" +#include "string.h" // remember which version of the bitstream we have already downloaded to the FPGA static int downloaded_bitstream = 0; @@ -153,8 +162,7 @@ void FpgaSetupSsc(void) { //----------------------------------------------------------------------------- // Set up DMA to receive samples from the FPGA. We will use the PDC, with // a single buffer as a circular buffer (so that we just chain back to -// ourselves, not to another buffer). The stuff to manipulate those buffers -// is in apps.h, because it should be inlined, for speed. +// ourselves, not to another buffer). //----------------------------------------------------------------------------- bool FpgaSetupSscDma(uint8_t *buf, int len) { if (buf == NULL) return false; diff --git a/armsrc/fpgaloader.h b/armsrc/fpgaloader.h index f9b0e44b0f..83c5bb2e44 100644 --- a/armsrc/fpgaloader.h +++ b/armsrc/fpgaloader.h @@ -12,32 +12,10 @@ #ifndef __FPGALOADER_H #define __FPGALOADER_H -#include -#include -#include "apps.h" -#include "fpga.h" -#include "common.h" // standard definitions -#include "proxmark3.h" // common area -#include "string.h" -#include "BigBuf.h" // bigbuf mem -#include "zlib.h" // uncompress +#include "common.h" - -void FpgaSendCommand(uint16_t cmd, uint16_t v); -void FpgaWriteConfWord(uint8_t v); -void FpgaDownloadAndGo(int bitstream_version); -// void FpgaGatherVersion(int bitstream_version, char *dst, int len); -void FpgaSetupSsc(void); -void SetupSpi(int mode); -bool FpgaSetupSscDma(uint8_t *buf, int len); -void Fpga_print_status(void); -int FpgaGetCurrent(void); #define FpgaDisableSscDma(void) AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS; #define FpgaEnableSscDma(void) AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN; -void SetAdcMuxFor(uint32_t whichGpio); - -// extern and generel turn off the antenna method -void switch_off(void); // definitions for multiple FPGA config files support #define FPGA_BITSTREAM_LF 1 @@ -97,4 +75,18 @@ void switch_off(void); #define FPGA_HF_ISO18092_FLAG_424K (2<<0) // 0010 should enable 414k mode (untested). No autodetect #define FPGA_HF_ISO18092_FLAG_READER (4<<0) // 0100 enables antenna power, to act as a reader instead of tag +void FpgaSendCommand(uint16_t cmd, uint16_t v); +void FpgaWriteConfWord(uint8_t v); +void FpgaDownloadAndGo(int bitstream_version); +// void FpgaGatherVersion(int bitstream_version, char *dst, int len); +void FpgaSetupSsc(void); +void SetupSpi(int mode); +bool FpgaSetupSscDma(uint8_t *buf, int len); +void Fpga_print_status(void); +int FpgaGetCurrent(void); +void SetAdcMuxFor(uint32_t whichGpio); + +// extern and generel turn off the antenna method +void switch_off(void); + #endif diff --git a/armsrc/frozen.c b/armsrc/frozen.c index 5af6faad8f..220f51d6cf 100644 --- a/armsrc/frozen.c +++ b/armsrc/frozen.c @@ -20,9 +20,6 @@ #include "frozen.h" -//#include -#include -#include #include #include #include "nprintf.h" diff --git a/armsrc/frozen.h b/armsrc/frozen.h index 49183ee7df..beb6c5f446 100644 --- a/armsrc/frozen.h +++ b/armsrc/frozen.h @@ -19,21 +19,9 @@ #ifndef CS_FROZEN_FROZEN_H_ #define CS_FROZEN_FROZEN_H_ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - #include -#include #include -#if defined(_WIN32) && _MSC_VER < 1700 -typedef int bool; -enum { false = 0, true = 1 }; -#else -#include -#endif - /* JSON token type */ enum json_token_type { JSON_TYPE_INVALID = 0, /* memsetting to 0 should create INVALID value */ @@ -322,8 +310,4 @@ void *json_next_elem(const char *s, int len, void *handle, const char *path, #define JSON_ENABLE_HEX !JSON_MINIMAL #endif -#ifdef __cplusplus -} -#endif /* __cplusplus */ - #endif /* CS_FROZEN_FROZEN_H_ */ diff --git a/armsrc/hfsnoop.c b/armsrc/hfsnoop.c index bb5d8699c3..994d76e519 100644 --- a/armsrc/hfsnoop.c +++ b/armsrc/hfsnoop.c @@ -1,8 +1,9 @@ -#include "proxmark3.h" -#include "apps.h" +#include "proxmark3_arm.h" #include "BigBuf.h" +#include "fpgaloader.h" +#include "ticks.h" +#include "dbprint.h" #include "util.h" -#include "usb_cdc.h" // for usb_poll_validate_length static void RAMFUNC optimizedSniff(void); diff --git a/armsrc/Standalone/lf_icerun.h b/armsrc/hfsnoop.h similarity index 65% rename from armsrc/Standalone/lf_icerun.h rename to armsrc/hfsnoop.h index 50427320a1..b6fac7eb74 100644 --- a/armsrc/Standalone/lf_icerun.h +++ b/armsrc/hfsnoop.h @@ -1,17 +1,16 @@ //----------------------------------------------------------------------------- -// Iceman, Christian Herrmann, 2019 +// Jonathan Westhues, Aug 2005 +// Gerhard de Koning Gans, April 2008, May 2011 // // This code is licensed to you under the terms of the GNU GPL, version 2 or, // at your option, any later version. See the LICENSE.txt file for the text of // the license. //----------------------------------------------------------------------------- -// StandAlone Mod +// Definitions internal to the app source. //----------------------------------------------------------------------------- +#ifndef __HFSNOOP_H +#define __HFSNOOP_H -#ifndef __LF_ICERUN_H -#define __LF_ICERUN_H +void HfSniff(int, int); -#include "standalone.h" // standalone definitions -#include "apps.h" // debugstatements, lfops? - -#endif /* __LF_ICERUN_H */ +#endif diff --git a/armsrc/hitag2.c b/armsrc/hitag2.c index 14db91e911..c1fc7d8d48 100644 --- a/armsrc/hitag2.c +++ b/armsrc/hitag2.c @@ -20,12 +20,14 @@ #include "hitag2.h" #include "hitag2_crypto.h" -#include "hitag.h" -#include "proxmark3.h" -#include "apps.h" -#include "util.h" #include "string.h" +#include "proxmark3_arm.h" +#include "cmd.h" #include "BigBuf.h" +#include "fpgaloader.h" +#include "ticks.h" +#include "dbprint.h" +#include "util.h" // Successful crypto auth static bool bCrypto; diff --git a/armsrc/hitag2.h b/armsrc/hitag2.h index c62a2a2216..9e0fb84e6c 100644 --- a/armsrc/hitag2.h +++ b/armsrc/hitag2.h @@ -11,8 +11,7 @@ #ifndef _HITAG2_H_ #define _HITAG2_H_ -#include -#include +#include "common.h" #include "hitag.h" void SniffHitag(void); diff --git a/armsrc/hitag2_crypto.c b/armsrc/hitag2_crypto.c index 7d1e10d87c..91c04ef438 100644 --- a/armsrc/hitag2_crypto.c +++ b/armsrc/hitag2_crypto.c @@ -11,6 +11,9 @@ //----------------------------------------------------------------------------- #include "hitag2_crypto.h" +#include "util.h" +#include "string.h" + /* Following is a modified version of cryptolib.com/ciphers/hitag2/ */ // Software optimized 48-bit Philips/NXP Mifare Hitag2 PCF7936/46/47/52 stream cipher algorithm by I.C. Wiener 2006-2007. // For educational purposes only. diff --git a/armsrc/hitag2_crypto.h b/armsrc/hitag2_crypto.h index d874955e03..8544c7e1cc 100644 --- a/armsrc/hitag2_crypto.h +++ b/armsrc/hitag2_crypto.h @@ -1,12 +1,7 @@ #ifndef __HITAG2_CRYPTO_H #define __HITAG2_CRYPTO_H -#ifdef __cplusplus -extern "C" { -#endif - -#include "string.h" -#include "util.h" +#include "common.h" struct hitag2_tag { uint32_t uid; @@ -29,8 +24,5 @@ uint32_t _hitag2_byte(uint64_t *x); void hitag2_cipher_reset(struct hitag2_tag *tag, const uint8_t *iv); int hitag2_cipher_authenticate(uint64_t *cs, const uint8_t *authenticator_is); int hitag2_cipher_transcrypt(uint64_t *cs, uint8_t *data, uint16_t bytes, uint16_t bits) ; -#ifdef __cplusplus -} -#endif #endif diff --git a/armsrc/hitagS.c b/armsrc/hitagS.c index e3f1456aa2..98c3844e29 100644 --- a/armsrc/hitagS.c +++ b/armsrc/hitagS.c @@ -13,6 +13,17 @@ #include "hitagS.h" +#include "proxmark3_arm.h" +#include "cmd.h" +#include "BigBuf.h" +#include "fpgaloader.h" +#include "ticks.h" +#include "dbprint.h" +#include "util.h" +#include "string.h" +#include "commonutil.h" +#include "hitag2_crypto.h" + #define CRC_PRESET 0xFF #define CRC_POLYNOM 0x1D diff --git a/armsrc/hitagS.h b/armsrc/hitagS.h index 49a885c4ca..f4efd70a66 100644 --- a/armsrc/hitagS.h +++ b/armsrc/hitagS.h @@ -12,16 +12,9 @@ #ifndef _HITAGS_H_ #define _HITAGS_H_ -#include -#include -#include -#include "hitag2_crypto.h" +#include "common.h" + #include "hitag.h" -#include "proxmark3.h" -#include "apps.h" -#include "util.h" -#include "string.h" -#include "BigBuf.h" void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data); void ReadHitagS(hitag_function htf, hitag_data *htd); diff --git a/common/i2c.c b/armsrc/i2c.c similarity index 99% rename from common/i2c.c rename to armsrc/i2c.c index 62bd2bc56b..2cd3c6f3e9 100644 --- a/common/i2c.c +++ b/armsrc/i2c.c @@ -10,6 +10,14 @@ //----------------------------------------------------------------------------- #include "i2c.h" +#include "proxmark3_arm.h" +#include "cmd.h" +#include "BigBuf.h" +#include "ticks.h" +#include "dbprint.h" +#include "util.h" +#include "string.h" + #define GPIO_RST AT91C_PIO_PA1 #define GPIO_SCL AT91C_PIO_PA5 #define GPIO_SDA AT91C_PIO_PA7 diff --git a/common/i2c.h b/armsrc/i2c.h similarity index 95% rename from common/i2c.h rename to armsrc/i2c.h index 52be70ef01..7b17075028 100644 --- a/common/i2c.h +++ b/armsrc/i2c.h @@ -1,10 +1,7 @@ #ifndef __I2C_H #define __I2C_H -#include -#include "proxmark3.h" -#include "apps.h" -#include "BigBuf.h" +#include "common.h" #include "mifare.h" #define I2C_DEVICE_ADDRESS_BOOT 0xB0 @@ -18,7 +15,6 @@ #define I2C_DEVICE_CMD_GETVERSION 0x06 #define I2C_DEVICE_CMD_SEND_T0 0x07 - void I2C_recovery(void); void I2C_init(void); void I2C_Reset(void); @@ -48,4 +44,5 @@ void SmartCardSetBaud(uint64_t arg0); void SmartCardSetClock(uint64_t arg0); void I2C_print_status(void); int I2C_get_version(uint8_t *maj, uint8_t *min); + #endif diff --git a/armsrc/iclass.c b/armsrc/iclass.c index b1553f2dfe..26201842a3 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -36,15 +36,24 @@ // //----------------------------------------------------------------------------- -#include "apps.h" +#include "iclass.h" + +#include "proxmark3_arm.h" #include "cmd.h" // Needed for CRC in emulation mode; // same construction as in ISO 14443; // different initial value (CRC_ICLASS) #include "crc16.h" -#include "protocols.h" #include "optimized_cipher.h" -#include "usb_cdc.h" // for usb_poll_validate_length + +#include "appmain.h" +#include "BigBuf.h" +#include "fpgaloader.h" +#include "string.h" +#include "util.h" +#include "dbprint.h" +#include "protocols.h" +#include "ticks.h" static int timeout = 4096; static int SendIClassAnswer(uint8_t *resp, int respLen, uint16_t delay); @@ -92,21 +101,21 @@ typedef struct { int bitBuffer; int dropPosition; uint8_t *output; -} tUart; +} tUartIc; */ typedef struct { enum { - DEMOD_UNSYNCD, - DEMOD_START_OF_COMMUNICATION, - DEMOD_START_OF_COMMUNICATION2, - DEMOD_START_OF_COMMUNICATION3, - DEMOD_SOF_COMPLETE, - DEMOD_MANCHESTER_D, - DEMOD_MANCHESTER_E, - DEMOD_END_OF_COMMUNICATION, - DEMOD_END_OF_COMMUNICATION2, - DEMOD_MANCHESTER_F, - DEMOD_ERROR_WAIT + DEMOD_IC_UNSYNCD, + DEMOD_IC_START_OF_COMMUNICATION, + DEMOD_IC_START_OF_COMMUNICATION2, + DEMOD_IC_START_OF_COMMUNICATION3, + DEMOD_IC_SOF_COMPLETE, + DEMOD_IC_MANCHESTER_D, + DEMOD_IC_MANCHESTER_E, + DEMOD_IC_END_OF_COMMUNICATION, + DEMOD_IC_END_OF_COMMUNICATION2, + DEMOD_IC_MANCHESTER_F, + DEMOD_IC_ERROR_WAIT } state; int bitCount; int posCount; @@ -125,7 +134,7 @@ typedef struct { SUB_BOTH } sub; uint8_t *output; -} tDemod; +} tDemodIc; /* * Abrasive's uart implementation @@ -138,8 +147,13 @@ typedef struct { bool frame_done; uint8_t *buf; int len; -} tUart; -static tUart Uart; +} tUartIc; +static tUartIc Uart; + +static void OnError(uint8_t reason) { + reply_old(CMD_ACK, 0, reason, 0, 0, 0); + switch_off(); +} static void uart_reset(void) { Uart.frame_done = false; @@ -499,8 +513,8 @@ static RAMFUNC int OutOfNDecoding(int bit) { //============================================================================= // Manchester //============================================================================= -static tDemod Demod; -static void DemodReset() { +static tDemodIc Demod; +static void DemodIcReset() { Demod.bitCount = 0; Demod.posCount = 0; Demod.syncBit = 0; @@ -512,11 +526,11 @@ static void DemodReset() { Demod.samples = 0; Demod.len = 0; Demod.sub = SUB_NONE; - Demod.state = DEMOD_UNSYNCD; + Demod.state = DEMOD_IC_UNSYNCD; } -static void DemodInit(uint8_t *data) { +static void DemodIcInit(uint8_t *data) { Demod.output = data; - DemodReset(); + DemodIcReset(); } // UART debug @@ -592,7 +606,7 @@ static RAMFUNC int ManchesterDecoding_iclass(uint32_t v) { return false; } - if (Demod.state == DEMOD_UNSYNCD) { + if (Demod.state == DEMOD_IC_UNSYNCD) { Demod.output[Demod.len] = 0xfa; Demod.syncBit = 0; //Demod.samples = 0; @@ -620,7 +634,7 @@ static RAMFUNC int ManchesterDecoding_iclass(uint32_t v) { if (Demod.syncBit) { Demod.len = 0; - Demod.state = DEMOD_START_OF_COMMUNICATION; + Demod.state = DEMOD_IC_START_OF_COMMUNICATION; Demod.sub = SUB_FIRST_HALF; Demod.bitCount = 0; Demod.shiftReg = 0; @@ -644,12 +658,12 @@ static RAMFUNC int ManchesterDecoding_iclass(uint32_t v) { } // SOF must be long burst... otherwise stay unsynced!!! if (!(Demod.buffer & Demod.syncBit) || !(Demod.buffer2 & Demod.syncBit)) - Demod.state = DEMOD_UNSYNCD; + Demod.state = DEMOD_IC_UNSYNCD; } else { // SOF must be long burst... otherwise stay unsynced!!! if (!(Demod.buffer2 & Demod.syncBit) || !(Demod.buffer3 & Demod.syncBit)) { - Demod.state = DEMOD_UNSYNCD; + Demod.state = DEMOD_IC_UNSYNCD; error = 0x88; uart_debug(error, bit); return false; @@ -682,74 +696,74 @@ static RAMFUNC int ManchesterDecoding_iclass(uint32_t v) { } if (Demod.sub == SUB_NONE) { - if (Demod.state == DEMOD_SOF_COMPLETE) { + if (Demod.state == DEMOD_IC_SOF_COMPLETE) { Demod.output[Demod.len] = 0x0f; Demod.len++; - Demod.state = DEMOD_UNSYNCD; + Demod.state = DEMOD_IC_UNSYNCD; return true; } else { - Demod.state = DEMOD_ERROR_WAIT; + Demod.state = DEMOD_IC_ERROR_WAIT; error = 0x33; } } switch (Demod.state) { - case DEMOD_START_OF_COMMUNICATION: + case DEMOD_IC_START_OF_COMMUNICATION: if (Demod.sub == SUB_BOTH) { - Demod.state = DEMOD_START_OF_COMMUNICATION2; + Demod.state = DEMOD_IC_START_OF_COMMUNICATION2; Demod.posCount = 1; Demod.sub = SUB_NONE; } else { Demod.output[Demod.len] = 0xab; - Demod.state = DEMOD_ERROR_WAIT; + Demod.state = DEMOD_IC_ERROR_WAIT; error = 0xd2; } break; - case DEMOD_START_OF_COMMUNICATION2: + case DEMOD_IC_START_OF_COMMUNICATION2: if (Demod.sub == SUB_SECOND_HALF) { - Demod.state = DEMOD_START_OF_COMMUNICATION3; + Demod.state = DEMOD_IC_START_OF_COMMUNICATION3; } else { Demod.output[Demod.len] = 0xab; - Demod.state = DEMOD_ERROR_WAIT; + Demod.state = DEMOD_IC_ERROR_WAIT; error = 0xd3; } break; - case DEMOD_START_OF_COMMUNICATION3: + case DEMOD_IC_START_OF_COMMUNICATION3: if (Demod.sub == SUB_SECOND_HALF) { - Demod.state = DEMOD_SOF_COMPLETE; + Demod.state = DEMOD_IC_SOF_COMPLETE; } else { Demod.output[Demod.len] = 0xab; - Demod.state = DEMOD_ERROR_WAIT; + Demod.state = DEMOD_IC_ERROR_WAIT; error = 0xd4; } break; - case DEMOD_SOF_COMPLETE: - case DEMOD_MANCHESTER_D: - case DEMOD_MANCHESTER_E: + case DEMOD_IC_SOF_COMPLETE: + case DEMOD_IC_MANCHESTER_D: + case DEMOD_IC_MANCHESTER_E: // OPPOSITE FROM ISO14443 - 11110000 = 0 (1 in 14443) // 00001111 = 1 (0 in 14443) if (Demod.sub == SUB_SECOND_HALF) { // SUB_FIRST_HALF Demod.bitCount++; Demod.shiftReg = (Demod.shiftReg >> 1) ^ 0x100; - Demod.state = DEMOD_MANCHESTER_D; + Demod.state = DEMOD_IC_MANCHESTER_D; } else if (Demod.sub == SUB_FIRST_HALF) { // SUB_SECOND_HALF Demod.bitCount++; Demod.shiftReg >>= 1; - Demod.state = DEMOD_MANCHESTER_E; + Demod.state = DEMOD_IC_MANCHESTER_E; } else if (Demod.sub == SUB_BOTH) { - Demod.state = DEMOD_MANCHESTER_F; + Demod.state = DEMOD_IC_MANCHESTER_F; } else { - Demod.state = DEMOD_ERROR_WAIT; + Demod.state = DEMOD_IC_ERROR_WAIT; error = 0x55; } break; - case DEMOD_MANCHESTER_F: + case DEMOD_IC_MANCHESTER_F: // Tag response does not need to be a complete byte! if (Demod.len > 0 || Demod.bitCount > 0) { if (Demod.bitCount > 1) { // was > 0, do not interpret last closing bit, is part of EOF @@ -758,22 +772,22 @@ static RAMFUNC int ManchesterDecoding_iclass(uint32_t v) { Demod.len++; } - Demod.state = DEMOD_UNSYNCD; + Demod.state = DEMOD_IC_UNSYNCD; return true; } else { Demod.output[Demod.len] = 0xad; - Demod.state = DEMOD_ERROR_WAIT; + Demod.state = DEMOD_IC_ERROR_WAIT; error = 0x03; } break; - case DEMOD_ERROR_WAIT: - Demod.state = DEMOD_UNSYNCD; + case DEMOD_IC_ERROR_WAIT: + Demod.state = DEMOD_IC_UNSYNCD; break; default: Demod.output[Demod.len] = 0xdd; - Demod.state = DEMOD_UNSYNCD; + Demod.state = DEMOD_IC_UNSYNCD; break; } @@ -818,10 +832,10 @@ static void iclass_setup_sniff(void) { set_tracing(true); // Initialize Demod and Uart structs - DemodInit(BigBuf_malloc(ICLASS_BUFFER_SIZE)); + DemodIcInit(BigBuf_malloc(ICLASS_BUFFER_SIZE)); uart_init(BigBuf_malloc(ICLASS_BUFFER_SIZE)); - //UartInit(BigBuf_malloc(ICLASS_BUFFER_SIZE)); + //UartIcInit(BigBuf_malloc(ICLASS_BUFFER_SIZE)); if (DBGLEVEL > 1) { // Print debug information about the buffer sizes @@ -927,7 +941,7 @@ void RAMFUNC SniffIClass(void) { if (Uart.frame_done) { time_stop = GetCountSspClk() - time_0; LogTrace(Uart.buf, Uart.len, time_start, time_stop, NULL, true); - DemodReset(); + DemodIcReset(); uart_reset(); } else { time_start = GetCountSspClk() - time_0; @@ -959,12 +973,12 @@ void RAMFUNC SniffIClass(void) { if (ManchesterDecoding_iclass(foo)) { time_stop = GetCountSspClk() - time_0; LogTrace(Demod.output, Demod.len, time_start, time_stop, NULL, false); - DemodReset(); + DemodIcReset(); uart_reset(); } else { time_start = GetCountSspClk() - time_0; } - TagIsActive = (Demod.state != DEMOD_UNSYNCD); + TagIsActive = (Demod.state != DEMOD_IC_UNSYNCD); } tag_byte = 0; foo = 0; @@ -1821,7 +1835,7 @@ static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples, bool skip = false; // Setup UART/DEMOD to receive - DemodInit(receivedResponse); + DemodIcInit(receivedResponse); if (elapsed) *elapsed = 0; diff --git a/armsrc/iclass.h b/armsrc/iclass.h new file mode 100644 index 0000000000..a9edbdfed7 --- /dev/null +++ b/armsrc/iclass.h @@ -0,0 +1,29 @@ +//----------------------------------------------------------------------------- +// Jonathan Westhues, Aug 2005 +// Gerhard de Koning Gans, April 2008, May 2011 +// +// This code is licensed to you under the terms of the GNU GPL, version 2 or, +// at your option, any later version. See the LICENSE.txt file for the text of +// the license. +//----------------------------------------------------------------------------- +// Definitions internal to the app source. +//----------------------------------------------------------------------------- +#ifndef __ICLASS_H +#define __ICLASS_H + +#include "common.h" + +void RAMFUNC SniffIClass(void); +void SimulateIClass(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain); +void ReaderIClass(uint8_t arg0); +void ReaderIClass_Replay(uint8_t arg0, uint8_t *mac); +void iClass_Authentication(uint8_t *mac); +void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain); +void iClass_WriteBlock(uint8_t blockno, uint8_t *data); +void iClass_ReadBlk(uint8_t blockno); +bool iClass_ReadBlock(uint8_t blockno, uint8_t *data, uint8_t len); +void iClass_Dump(uint8_t blockno, uint8_t numblks); +void iClass_Clone(uint8_t startblock, uint8_t endblock, uint8_t *data); +void iClass_ReadCheck(uint8_t blockno, uint8_t keytype); + +#endif diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index 2e7aeebe35..786db50dce 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -11,6 +11,21 @@ //----------------------------------------------------------------------------- #include "iso14443a.h" +#include "string.h" +#include "proxmark3_arm.h" +#include "cmd.h" +#include "appmain.h" +#include "BigBuf.h" +#include "fpgaloader.h" +#include "ticks.h" +#include "dbprint.h" +#include "util.h" +#include "parity.h" +#include "mifareutil.h" +#include "commonutil.h" +#include "crc16.h" +#include "protocols.h" + #define MAX_ISO14A_TIMEOUT 524288 static uint32_t iso14a_timeout; // if iso14443a not active - transmit/receive dont try to execute @@ -161,7 +176,7 @@ void GetParity(const uint8_t *pbtCmd, uint16_t len, uint8_t *par) { // Note 1: the bitstream may start at any time. We therefore need to sync. // Note 2: the interpretation of Sequence Y and Z depends on the preceding sequence. //----------------------------------------------------------------------------- -static tUart Uart; +static tUart14a Uart; // Lookup-Table to decide if 4 raw bits are a modulation. // We accept the following: @@ -176,12 +191,12 @@ const bool Mod_Miller_LUT[] = { #define IsMillerModulationNibble1(b) (Mod_Miller_LUT[(b & 0x000000F0) >> 4]) #define IsMillerModulationNibble2(b) (Mod_Miller_LUT[(b & 0x0000000F)]) -tUart *GetUart() { +tUart14a *GetUart14a() { return &Uart; } -void UartReset(void) { - Uart.state = STATE_UNSYNCD; +void Uart14aReset(void) { + Uart.state = STATE_14A_UNSYNCD; Uart.bitCount = 0; Uart.len = 0; // number of decoded data bytes Uart.parityLen = 0; // number of decoded parity bytes @@ -194,17 +209,17 @@ void UartReset(void) { Uart.syncBit = 9999; } -void UartInit(uint8_t *data, uint8_t *par) { +void Uart14aInit(uint8_t *data, uint8_t *par) { Uart.output = data; Uart.parity = par; - UartReset(); + Uart14aReset(); } // use parameter non_real_time to provide a timestamp. Set to 0 if the decoder should measure real time RAMFUNC bool MillerDecoding(uint8_t bit, uint32_t non_real_time) { Uart.fourBits = (Uart.fourBits << 8) | bit; - if (Uart.state == STATE_UNSYNCD) { // not yet synced + if (Uart.state == STATE_14A_UNSYNCD) { // not yet synced Uart.syncBit = 9999; // not set // 00x11111 2|3 ticks pause followed by 6|5 ticks unmodulated Sequence Z (a "0" or "start of communication") @@ -230,20 +245,20 @@ RAMFUNC bool MillerDecoding(uint8_t bit, uint32_t non_real_time) { Uart.startTime = non_real_time ? non_real_time : (GetCountSspClk() & 0xfffffff8); Uart.startTime -= Uart.syncBit; Uart.endTime = Uart.startTime; - Uart.state = STATE_START_OF_COMMUNICATION; + Uart.state = STATE_14A_START_OF_COMMUNICATION; } } else { if (IsMillerModulationNibble1(Uart.fourBits >> Uart.syncBit)) { if (IsMillerModulationNibble2(Uart.fourBits >> Uart.syncBit)) { // Modulation in both halves - error - UartReset(); + Uart14aReset(); } else { // Modulation in first half = Sequence Z = logic "0" - if (Uart.state == STATE_MILLER_X) { // error - must not follow after X - UartReset(); + if (Uart.state == STATE_14A_MILLER_X) { // error - must not follow after X + Uart14aReset(); } else { Uart.bitCount++; Uart.shiftReg = (Uart.shiftReg >> 1); // add a 0 to the shiftreg - Uart.state = STATE_MILLER_Z; + Uart.state = STATE_14A_MILLER_Z; Uart.endTime = Uart.startTime + 8 * (9 * Uart.len + Uart.bitCount + 1) - 6; if (Uart.bitCount >= 9) { // if we decoded a full byte (including parity) Uart.output[Uart.len++] = (Uart.shiftReg & 0xff); @@ -262,7 +277,7 @@ RAMFUNC bool MillerDecoding(uint8_t bit, uint32_t non_real_time) { if (IsMillerModulationNibble2(Uart.fourBits >> Uart.syncBit)) { // Modulation second half = Sequence X = logic "1" Uart.bitCount++; Uart.shiftReg = (Uart.shiftReg >> 1) | 0x100; // add a 1 to the shiftreg - Uart.state = STATE_MILLER_X; + Uart.state = STATE_14A_MILLER_X; Uart.endTime = Uart.startTime + 8 * (9 * Uart.len + Uart.bitCount + 1) - 2; if (Uart.bitCount >= 9) { // if we decoded a full byte (including parity) Uart.output[Uart.len++] = (Uart.shiftReg & 0xff); @@ -276,8 +291,8 @@ RAMFUNC bool MillerDecoding(uint8_t bit, uint32_t non_real_time) { } } } else { // no modulation in both halves - Sequence Y - if (Uart.state == STATE_MILLER_Z || Uart.state == STATE_MILLER_Y) { // Y after logic "0" - End of Communication - Uart.state = STATE_UNSYNCD; + if (Uart.state == STATE_14A_MILLER_Z || Uart.state == STATE_14A_MILLER_Y) { // Y after logic "0" - End of Communication + Uart.state = STATE_14A_UNSYNCD; Uart.bitCount--; // last "0" was part of EOC sequence Uart.shiftReg <<= 1; // drop it if (Uart.bitCount > 0) { // if we decoded some bits @@ -294,15 +309,15 @@ RAMFUNC bool MillerDecoding(uint8_t bit, uint32_t non_real_time) { if (Uart.len) { return true; // we are finished with decoding the raw data sequence } else { - UartReset(); // Nothing received - start over + Uart14aReset(); // Nothing received - start over } } - if (Uart.state == STATE_START_OF_COMMUNICATION) { // error - must not follow directly after SOC - UartReset(); + if (Uart.state == STATE_14A_START_OF_COMMUNICATION) { // error - must not follow directly after SOC + Uart14aReset(); } else { // a logic "0" Uart.bitCount++; Uart.shiftReg = (Uart.shiftReg >> 1); // add a 0 to the shiftreg - Uart.state = STATE_MILLER_Y; + Uart.state = STATE_14A_MILLER_Y; if (Uart.bitCount >= 9) { // if we decoded a full byte (including parity) Uart.output[Uart.len++] = (Uart.shiftReg & 0xff); Uart.parityBits <<= 1; // make room for the parity bit @@ -336,7 +351,7 @@ RAMFUNC bool MillerDecoding(uint8_t bit, uint32_t non_real_time) { // 8 ticks modulated: A collision. Save the collision position and treat as Sequence D // Note 1: the bitstream may start at any time. We therefore need to sync. // Note 2: parameter offset is used to determine the position of the parity bits (required for the anticollision command only) -tDemod Demod; +tDemod14a Demod; // Lookup-Table to decide if 4 raw bits are a modulation. // We accept three or four "1" in any position @@ -348,11 +363,11 @@ const bool Mod_Manchester_LUT[] = { #define IsManchesterModulationNibble1(b) (Mod_Manchester_LUT[(b & 0x00F0) >> 4]) #define IsManchesterModulationNibble2(b) (Mod_Manchester_LUT[(b & 0x000F)]) -tDemod *GetDemod() { +tDemod14a *GetDemod14a() { return &Demod; } -void DemodReset(void) { - Demod.state = DEMOD_UNSYNCD; +void Demod14aReset(void) { + Demod.state = DEMOD_14A_UNSYNCD; Demod.len = 0; // number of decoded data bytes Demod.parityLen = 0; Demod.shiftReg = 0; // shiftreg to hold decoded data bits @@ -367,17 +382,17 @@ void DemodReset(void) { Demod.samples = 0; } -void DemodInit(uint8_t *data, uint8_t *par) { +void Demod14aInit(uint8_t *data, uint8_t *par) { Demod.output = data; Demod.parity = par; - DemodReset(); + Demod14aReset(); } // use parameter non_real_time to provide a timestamp. Set to 0 if the decoder should measure real time RAMFUNC int ManchesterDecoding(uint8_t bit, uint16_t offset, uint32_t non_real_time) { Demod.twoBits = (Demod.twoBits << 8) | bit; - if (Demod.state == DEMOD_UNSYNCD) { + if (Demod.state == DEMOD_14A_UNSYNCD) { if (Demod.highCnt < 2) { // wait for a stable unmodulated signal if (Demod.twoBits == 0x0000) { @@ -399,7 +414,7 @@ RAMFUNC int ManchesterDecoding(uint8_t bit, uint16_t offset, uint32_t non_real_t Demod.startTime = non_real_time ? non_real_time : (GetCountSspClk() & 0xfffffff8); Demod.startTime -= Demod.syncBit; Demod.bitCount = offset; // number of decoded data bits - Demod.state = DEMOD_MANCHESTER_DATA; + Demod.state = DEMOD_14A_MANCHESTER_DATA; } } } else { @@ -455,7 +470,7 @@ RAMFUNC int ManchesterDecoding(uint8_t bit, uint16_t offset, uint32_t non_real_t if (Demod.len) { return true; // we are finished with decoding the raw data sequence } else { // nothing received. Start over - DemodReset(); + Demod14aReset(); } } } @@ -468,7 +483,7 @@ RAMFUNC int ManchesterDecoding(uint8_t bit, uint16_t offset, uint32_t non_real_t RAMFUNC int ManchesterDecoding_Thinfilm(uint8_t bit) { Demod.twoBits = (Demod.twoBits << 8) | bit; - if (Demod.state == DEMOD_UNSYNCD) { + if (Demod.state == DEMOD_14A_UNSYNCD) { if (Demod.highCnt < 2) { // wait for a stable unmodulated signal if (Demod.twoBits == 0x0000) { @@ -491,7 +506,7 @@ RAMFUNC int ManchesterDecoding_Thinfilm(uint8_t bit) { Demod.startTime -= Demod.syncBit; Demod.bitCount = 1; // number of decoded data bits Demod.shiftReg = 1; - Demod.state = DEMOD_MANCHESTER_DATA; + Demod.state = DEMOD_14A_MANCHESTER_DATA; } } } else { @@ -529,7 +544,7 @@ RAMFUNC int ManchesterDecoding_Thinfilm(uint8_t bit) { if (Demod.len) { return true; // we are finished with decoding the raw data sequence } else { // nothing received. Start over - DemodReset(); + Demod14aReset(); } } } @@ -582,10 +597,10 @@ void RAMFUNC SniffIso14443a(uint8_t param) { bool ReaderIsActive = false; // Set up the demodulator for tag -> reader responses. - DemodInit(receivedResp, receivedRespPar); + Demod14aInit(receivedResp, receivedRespPar); // Set up the demodulator for the reader -> tag commands - UartInit(receivedCmd, receivedCmdPar); + Uart14aInit(receivedCmd, receivedCmdPar); DbpString("Starting to sniff"); @@ -659,13 +674,13 @@ void RAMFUNC SniffIso14443a(uint8_t param) { true)) break; } /* ready to receive another command. */ - UartReset(); + Uart14aReset(); /* reset the demod code, which might have been */ /* false-triggered by the commands from the reader. */ - DemodReset(); + Demod14aReset(); LED_B_OFF(); } - ReaderIsActive = (Uart.state != STATE_UNSYNCD); + ReaderIsActive = (Uart.state != STATE_14A_UNSYNCD); } // no need to try decoding tag data if the reader is sending - and we cannot afford the time @@ -684,13 +699,13 @@ void RAMFUNC SniffIso14443a(uint8_t param) { if ((!triggered) && (param & 0x01)) triggered = true; // ready to receive another response. - DemodReset(); + Demod14aReset(); // reset the Miller decoder including its (now outdated) input buffer - UartReset(); - //UartInit(receivedCmd, receivedCmdPar); + Uart14aReset(); + //Uart14aInit(receivedCmd, receivedCmdPar); LED_C_OFF(); } - TagIsActive = (Demod.state != DEMOD_UNSYNCD); + TagIsActive = (Demod.state != DEMOD_14A_UNSYNCD); } } @@ -830,7 +845,7 @@ static bool GetIso14443aCommandFromReader(uint8_t *received, uint8_t *par, int * FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_TAGSIM_LISTEN); // Now run a `software UART` on the stream of incoming samples. - UartInit(received, par); + Uart14aInit(received, par); // clear RXRDY: uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR; @@ -1795,7 +1810,7 @@ int EmGetCmd(uint8_t *received, uint16_t *len, uint8_t *par) { AT91C_BASE_ADC->ADC_CR = AT91C_ADC_START; // Now run a 'software UART' on the stream of incoming samples. - UartInit(received, par); + Uart14aInit(received, par); // Clear RXRDY: uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR; @@ -2024,7 +2039,7 @@ bool GetIso14443aAnswerFromTag_Thinfilm(uint8_t *receivedResponse, uint8_t *rec FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_READER_LISTEN); // Now get the answer from the card - DemodInit(receivedResponse, NULL); + Demod14aInit(receivedResponse, NULL); // clear RXRDY: uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR; @@ -2073,7 +2088,7 @@ static int GetIso14443aAnswerFromTag(uint8_t *receivedResponse, uint8_t *receive FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_READER_LISTEN); // Now get the answer from the card - DemodInit(receivedResponse, receivedResponsePar); + Demod14aInit(receivedResponse, receivedResponsePar); // clear RXRDY: uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR; @@ -2089,7 +2104,7 @@ static int GetIso14443aAnswerFromTag(uint8_t *receivedResponse, uint8_t *receive if (ManchesterDecoding(b, offset, 0)) { NextTransferTime = MAX(NextTransferTime, Demod.endTime - (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER) / 16 + FRAME_DELAY_TIME_PICC_TO_PCD); return true; - } else if (c++ > timeout && Demod.state == DEMOD_UNSYNCD) { + } else if (c++ > timeout && Demod.state == DEMOD_14A_UNSYNCD) { return false; } } @@ -2499,8 +2514,8 @@ void iso14443a_setup(uint8_t fpga_minor_mode) { StartCountSspClk(); // Prepare the demodulation functions - DemodReset(); - UartReset(); + Demod14aReset(); + Uart14aReset(); NextTransferTime = 2 * DELAY_ARM2AIR_AS_READER; iso14a_set_timeout(1060); // 106 * 10ms default diff --git a/armsrc/iso14443a.h b/armsrc/iso14443a.h index 323fb8a979..e4ea7f0df8 100644 --- a/armsrc/iso14443a.h +++ b/armsrc/iso14443a.h @@ -13,21 +13,9 @@ #ifndef __ISO14443A_H #define __ISO14443A_H -#ifdef __cplusplus -extern "C" { -#endif - +#include "common.h" +#include "mifare.h" // struct #include "pm3_cmd.h" -#include "cmd.h" -#include "apps.h" -#include "util.h" -#include "string.h" -#include "crc16.h" -#include "mifaresniff.h" -#include "crapto1/crapto1.h" -#include "mifareutil.h" -#include "parity.h" -#include "mifare.h" // structs // When the PM acts as tag and is receiving it takes // 2 ticks delay in the RF part (for the first falling edge), @@ -42,11 +30,11 @@ extern "C" { typedef struct { enum { - DEMOD_UNSYNCD, - // DEMOD_HALF_SYNCD, - // DEMOD_MOD_FIRST_HALF, - // DEMOD_NOMOD_FIRST_HALF, - DEMOD_MANCHESTER_DATA + DEMOD_14A_UNSYNCD, + // DEMOD_14A_HALF_SYNCD, + // DEMOD_14A_MOD_FIRST_HALF, + // DEMOD_14A_NOMOD_FIRST_HALF, + DEMOD_14A_MANCHESTER_DATA } state; uint16_t twoBits; uint16_t highCnt; @@ -61,7 +49,7 @@ typedef struct { uint32_t startTime, endTime; uint8_t *output; uint8_t *parity; -} tDemod; +} tDemod14a; /* typedef enum { MOD_NOMOD = 0, @@ -73,11 +61,11 @@ typedef enum { typedef struct { enum { - STATE_UNSYNCD, - STATE_START_OF_COMMUNICATION, - STATE_MILLER_X, - STATE_MILLER_Y, - STATE_MILLER_Z, + STATE_14A_UNSYNCD, + STATE_14A_START_OF_COMMUNICATION, + STATE_14A_MILLER_X, + STATE_14A_MILLER_Y, + STATE_14A_MILLER_Z, // DROP_NONE, // DROP_FIRST_HALF, } state; @@ -93,7 +81,7 @@ typedef struct { uint32_t startTime, endTime; uint8_t *output; uint8_t *parity; -} tUart; +} tUart14a; #ifndef AddCrc14A # define AddCrc14A(data, len) compute_crc(CRC_14443_A, (data), (len), (data)+(len), (data)+(len)+1) @@ -109,12 +97,12 @@ typedef struct { void GetParity(const uint8_t *pbtCmd, uint16_t len, uint8_t *par); -tDemod *GetDemod(void); -void DemodReset(void); -void DemodInit(uint8_t *data, uint8_t *par); -tUart *GetUart(void); -void UartReset(void); -void UartInit(uint8_t *data, uint8_t *par); +tDemod14a *GetDemod14a(void); +void Demod14aReset(void); +void Demod14aInit(uint8_t *data, uint8_t *par); +tUart14a *GetUart14a(void); +void Uart14aReset(void); +void Uart14aInit(uint8_t *data, uint8_t *par); RAMFUNC bool MillerDecoding(uint8_t bit, uint32_t non_real_time); RAMFUNC int ManchesterDecoding(uint8_t bit, uint16_t offset, uint32_t non_real_time); @@ -153,8 +141,4 @@ void DetectNACKbug(void); bool GetIso14443aAnswerFromTag_Thinfilm(uint8_t *receivedResponse, uint8_t *received_len); -#ifdef __cplusplus -} -#endif - #endif /* __ISO14443A_H */ diff --git a/armsrc/iso14443b.c b/armsrc/iso14443b.c index 241484d014..6f19def06e 100644 --- a/armsrc/iso14443b.c +++ b/armsrc/iso14443b.c @@ -10,6 +10,20 @@ //----------------------------------------------------------------------------- #include "iso14443b.h" +#include "proxmark3_arm.h" +#include "common.h" // access to global variable: DBGLEVEL +#include "util.h" +#include "string.h" +#include "crc16.h" +#include "protocols.h" +#include "appmain.h" +#include "BigBuf.h" +#include "cmd.h" +#include "fpgaloader.h" +#include "commonutil.h" +#include "dbprint.h" +#include "ticks.h" + #ifndef FWT_TIMEOUT_14B // defaults to 2000ms # define FWT_TIMEOUT_14B 35312 @@ -52,7 +66,7 @@ static uint32_t iso14b_timeout = FWT_TIMEOUT_14B; //============================================================================= // An ISO 14443 Type B tag. We listen for commands from the reader, using -// a UART kind of thing that's implemented in software. When we get a +// a kind of thing that's implemented in software. When we get a // frame (i.e., a group of bytes between SOF and EOF), we check the CRC. // If it's good, then we can do something appropriate with it, and send // a response. @@ -60,14 +74,14 @@ static uint32_t iso14b_timeout = FWT_TIMEOUT_14B; //----------------------------------------------------------------------------- -// The software UART that receives commands from the reader, and its state variables. +// The software that receives commands from the reader, and its state variables. //----------------------------------------------------------------------------- static struct { enum { - STATE_UNSYNCD, - STATE_GOT_FALLING_EDGE_OF_SOF, - STATE_AWAITING_START_BIT, - STATE_RECEIVING_DATA + STATE_14B_UNSYNCD, + STATE_14B_GOT_FALLING_EDGE_OF_SOF, + STATE_14B_AWAITING_START_BIT, + STATE_14B_RECEIVING_DATA } state; uint16_t shiftReg; int bitCnt; @@ -77,8 +91,8 @@ static struct { uint8_t *output; } Uart; -static void UartReset() { - Uart.state = STATE_UNSYNCD; +static void Uart14bReset() { + Uart.state = STATE_14B_UNSYNCD; Uart.shiftReg = 0; Uart.bitCnt = 0; Uart.byteCnt = 0; @@ -86,9 +100,9 @@ static void UartReset() { Uart.posCnt = 0; } -static void UartInit(uint8_t *data) { +static void Uart14bInit(uint8_t *data) { Uart.output = data; - UartReset(); + Uart14bReset(); // memset(Uart.output, 0x00, MAX_FRAME_SIZE); } @@ -120,7 +134,7 @@ static struct { } Demod; // Clear out the state of the "UART" that receives from the tag. -static void DemodReset() { +static void Demod14bReset() { Demod.state = DEMOD_UNSYNCD; Demod.bitCount = 0; Demod.posCount = 0; @@ -133,9 +147,9 @@ static void DemodReset() { Demod.endTime = 0; } -static void DemodInit(uint8_t *data) { +static void Demod14bInit(uint8_t *data) { Demod.output = data; - DemodReset(); + Demod14bReset(); // memset(Demod.output, 0x00, MAX_FRAME_SIZE); } @@ -315,16 +329,16 @@ static void CodeIso14443bAsTag(const uint8_t *cmd, int len) { */ static RAMFUNC int Handle14443bReaderUartBit(uint8_t bit) { switch (Uart.state) { - case STATE_UNSYNCD: + case STATE_14B_UNSYNCD: if (!bit) { // we went low, so this could be the beginning of an SOF - Uart.state = STATE_GOT_FALLING_EDGE_OF_SOF; + Uart.state = STATE_14B_GOT_FALLING_EDGE_OF_SOF; Uart.posCnt = 0; Uart.bitCnt = 0; } break; - case STATE_GOT_FALLING_EDGE_OF_SOF: + case STATE_14B_GOT_FALLING_EDGE_OF_SOF: Uart.posCnt++; if (Uart.posCnt == 2) { // sample every 4 1/fs in the middle of a bit if (bit) { @@ -333,11 +347,11 @@ static RAMFUNC int Handle14443bReaderUartBit(uint8_t bit) { // zeros that it's a valid SOF Uart.posCnt = 0; Uart.byteCnt = 0; - Uart.state = STATE_AWAITING_START_BIT; + Uart.state = STATE_14B_AWAITING_START_BIT; LED_A_ON(); // Indicate we got a valid SOF } else { // didn't stay down long enough before going high, error - Uart.state = STATE_UNSYNCD; + Uart.state = STATE_14B_UNSYNCD; } } else { // do nothing, keep waiting @@ -348,27 +362,27 @@ static RAMFUNC int Handle14443bReaderUartBit(uint8_t bit) { if (Uart.bitCnt > 12) { // Give up if we see too many zeros without a one, too. LED_A_OFF(); - Uart.state = STATE_UNSYNCD; + Uart.state = STATE_14B_UNSYNCD; } break; - case STATE_AWAITING_START_BIT: + case STATE_14B_AWAITING_START_BIT: Uart.posCnt++; if (bit) { if (Uart.posCnt > 50 / 2) { // max 57us between characters = 49 1/fs, max 3 etus after low phase of SOF = 24 1/fs // stayed high for too long between characters, error - Uart.state = STATE_UNSYNCD; + Uart.state = STATE_14B_UNSYNCD; } } else { // falling edge, this starts the data byte Uart.posCnt = 0; Uart.bitCnt = 0; Uart.shiftReg = 0; - Uart.state = STATE_RECEIVING_DATA; + Uart.state = STATE_14B_RECEIVING_DATA; } break; - case STATE_RECEIVING_DATA: + case STATE_14B_RECEIVING_DATA: Uart.posCnt++; if (Uart.posCnt == 2) { // time to sample a bit @@ -391,30 +405,30 @@ static RAMFUNC int Handle14443bReaderUartBit(uint8_t bit) { if (Uart.byteCnt >= Uart.byteCntMax) { // Buffer overflowed, give up LED_A_OFF(); - Uart.state = STATE_UNSYNCD; + Uart.state = STATE_14B_UNSYNCD; } else { // so get the next byte now Uart.posCnt = 0; - Uart.state = STATE_AWAITING_START_BIT; + Uart.state = STATE_14B_AWAITING_START_BIT; } } else if (Uart.shiftReg == 0x000) { // this is an EOF byte LED_A_OFF(); // Finished receiving - Uart.state = STATE_UNSYNCD; + Uart.state = STATE_14B_UNSYNCD; if (Uart.byteCnt != 0) return true; } else { // this is an error LED_A_OFF(); - Uart.state = STATE_UNSYNCD; + Uart.state = STATE_14B_UNSYNCD; } } break; default: LED_A_OFF(); - Uart.state = STATE_UNSYNCD; + Uart.state = STATE_14B_UNSYNCD; break; } return false; @@ -454,7 +468,7 @@ static int GetIso14443bCommandFromReader(uint8_t *received, uint16_t *len) { } */ // Now run a `software UART' on the stream of incoming samples. - UartInit(received); + Uart14bInit(received); uint8_t mask; while (!BUTTON_PRESS()) { @@ -949,7 +963,7 @@ static void GetTagSamplesFor14443bDemod() { BigBuf_free(); // Set up the demodulator for tag -> reader responses. - DemodInit(BigBuf_malloc(MAX_FRAME_SIZE)); + Demod14bInit(BigBuf_malloc(MAX_FRAME_SIZE)); // The DMA buffer, used to stream samples from the FPGA int8_t *dmaBuf = (int8_t *) BigBuf_malloc(ISO14443B_DMA_BUFFER_SIZE); @@ -1306,8 +1320,8 @@ void iso14443b_setup() { FpgaDownloadAndGo(FPGA_BITSTREAM_HF); // Initialize Demod and Uart structs - DemodInit(BigBuf_malloc(MAX_FRAME_SIZE)); - UartInit(BigBuf_malloc(MAX_FRAME_SIZE)); + Demod14bInit(BigBuf_malloc(MAX_FRAME_SIZE)); + Uart14bInit(BigBuf_malloc(MAX_FRAME_SIZE)); // connect Demodulated Signal to ADC: SetAdcMuxFor(GPIO_MUXSEL_HIPKD); @@ -1411,8 +1425,8 @@ static void iso1444b_setup_sniff(void) { set_tracing(true); // Initialize Demod and Uart structs - DemodInit(BigBuf_malloc(MAX_FRAME_SIZE)); - UartInit(BigBuf_malloc(MAX_FRAME_SIZE)); + Demod14bInit(BigBuf_malloc(MAX_FRAME_SIZE)); + Uart14bInit(BigBuf_malloc(MAX_FRAME_SIZE)); if (DBGLEVEL > 1) { // Print debug information about the buffer sizes @@ -1502,8 +1516,8 @@ void RAMFUNC SniffIso14443b(void) { if (Handle14443bReaderUartBit(ci & 0x01)) { time_stop = GetCountSspClk() - time_0; LogTrace(Uart.output, Uart.byteCnt, time_start, time_stop, NULL, true); - UartReset(); - DemodReset(); + Uart14bReset(); + Demod14bReset(); } else { time_start = GetCountSspClk() - time_0; } @@ -1511,12 +1525,12 @@ void RAMFUNC SniffIso14443b(void) { if (Handle14443bReaderUartBit(cq & 0x01)) { time_stop = GetCountSspClk() - time_0; LogTrace(Uart.output, Uart.byteCnt, time_start, time_stop, NULL, true); - UartReset(); - DemodReset(); + Uart14bReset(); + Demod14bReset(); } else { time_start = GetCountSspClk() - time_0; } - ReaderIsActive = (Uart.state > STATE_GOT_FALLING_EDGE_OF_SOF); + ReaderIsActive = (Uart.state > STATE_14B_GOT_FALLING_EDGE_OF_SOF); } // no need to try decoding tag data if the reader is sending - and we cannot afford the time @@ -1527,8 +1541,8 @@ void RAMFUNC SniffIso14443b(void) { if (Handle14443bTagSamplesDemod(ci, cq)) { time_stop = GetCountSspClk() - time_0; LogTrace(Demod.output, Demod.len, time_start, time_stop, NULL, false); - UartReset(); - DemodReset(); + Uart14bReset(); + Demod14bReset(); } else { time_start = GetCountSspClk() - time_0; } diff --git a/armsrc/iso14443b.h b/armsrc/iso14443b.h index 5ea3d530bd..12ee316e9f 100644 --- a/armsrc/iso14443b.h +++ b/armsrc/iso14443b.h @@ -13,18 +13,10 @@ #ifndef __ISO14443B_H #define __ISO14443B_H -#ifdef __cplusplus -extern "C" { -#endif +#include "common.h" -#include "proxmark3.h" -#include "common.h" // access to global variable: DBGLEVEL -#include "apps.h" -#include "util.h" -#include "string.h" -#include "crc16.h" #include "mifare.h" -#include "protocols.h" +#include "pm3_cmd.h" #ifndef AddCrc14A # define AddCrc14A(data, len) compute_crc(CRC_14443_A, (data), (len), (data)+(len), (data)+(len)+1) @@ -34,12 +26,18 @@ extern "C" { # define AddCrc14B(data, len) compute_crc(CRC_14443_B, (data), (len), (data)+(len), (data)+(len)+1) #endif -void SendRawCommand14443B_Ex(PacketCommandNG *c); void iso14443b_setup(); uint8_t iso14443b_apdu(uint8_t const *message, size_t message_length, uint8_t *response); uint8_t iso14443b_select_card(iso14b_card_select_t *card); uint8_t iso14443b_select_card_srx(iso14b_card_select_t *card); +void SimulateIso14443bTag(uint32_t pupi); +void AcquireRawAdcSamplesIso14443b(uint32_t parameter); +void ReadSTMemoryIso14443b(uint8_t numofblocks); +void RAMFUNC SniffIso14443b(void); +void SendRawCommand14443B(uint32_t, uint32_t, uint8_t, uint8_t[]); +void SendRawCommand14443B_Ex(PacketCommandNG *c); + // testfunctions void WaitForFpgaDelayQueueIsEmpty(uint16_t delay); void ClearFpgaShiftingRegisters(void); @@ -53,8 +51,4 @@ void ClearFpgaShiftingRegisters(void); #define SIM_ACKNOWLEDGE 5 #define SIM_WORK 6 -#ifdef __cplusplus -} -#endif - #endif /* __ISO14443B_H */ diff --git a/armsrc/iso15693.c b/armsrc/iso15693.c index c332300908..84de710218 100644 --- a/armsrc/iso15693.c +++ b/armsrc/iso15693.c @@ -58,12 +58,20 @@ // *) remove or refactor code under "depricated" // *) document all the functions -#include "proxmark3.h" +#include "iso15693.h" + +#include "proxmark3_arm.h" #include "util.h" -#include "apps.h" #include "string.h" #include "iso15693tools.h" #include "cmd.h" +#include "appmain.h" +#include "dbprint.h" +#include "fpgaloader.h" +#include "commonutil.h" +#include "ticks.h" +#include "BigBuf.h" +#include "crc16.h" /////////////////////////////////////////////////////////////////////// // ISO 15693 Part 2 - Air Interface diff --git a/armsrc/iso15693.h b/armsrc/iso15693.h new file mode 100644 index 0000000000..2233ba9fd8 --- /dev/null +++ b/armsrc/iso15693.h @@ -0,0 +1,26 @@ +//----------------------------------------------------------------------------- +// Jonathan Westhues, Aug 2005 +// Gerhard de Koning Gans, April 2008, May 2011 +// +// This code is licensed to you under the terms of the GNU GPL, version 2 or, +// at your option, any later version. See the LICENSE.txt file for the text of +// the license. +//----------------------------------------------------------------------------- +// Definitions internal to the app source. +//----------------------------------------------------------------------------- +#ifndef __ISO15693_H +#define __ISO15693_H + +#include "common.h" + +#include "pm3_cmd.h" // struct + +void RecordRawAdcSamplesIso15693(void); +void AcquireRawAdcSamplesIso15693(void); +void ReaderIso15693(uint32_t parameter); // Simulate an ISO15693 reader - greg +void SimTagIso15693(uint32_t parameter, uint8_t *uid); // simulate an ISO15693 tag - greg +void BruteforceIso15693Afi(uint32_t speed); // find an AFI of a tag - atrox +void DirectTag15693Command(uint32_t datalen, uint32_t speed, uint32_t recv, uint8_t *data); // send arbitrary commands from CLI - atrox +void Iso15693InitReader(void); + +#endif diff --git a/armsrc/ldscript b/armsrc/ldscript index 80c2a4aed9..4d48d99485 100644 --- a/armsrc/ldscript +++ b/armsrc/ldscript @@ -7,7 +7,7 @@ Linker script for the ARM binary ----------------------------------------------------------------------------- */ -INCLUDE ../common/ldscript.common +INCLUDE ../common_arm/ldscript.common PHDRS { diff --git a/armsrc/legicrf.c b/armsrc/legicrf.c index 1b689550dc..0665705b62 100644 --- a/armsrc/legicrf.c +++ b/armsrc/legicrf.c @@ -11,11 +11,20 @@ //----------------------------------------------------------------------------- #include "legicrf.h" -#include "ticks.h" /* timers */ #include "crc.h" /* legic crc-4 */ #include "legic_prng.h" /* legic PRNG impl */ #include "legic.h" /* legic_card_select_t struct */ +#include "proxmark3_arm.h" +#include "cmd.h" +#include "BigBuf.h" +#include "fpgaloader.h" +#include "ticks.h" +#include "dbprint.h" +#include "util.h" +#include "string.h" +#include "protocols.h" + static uint8_t *legic_mem; /* card memory, used for read, write */ static legic_card_select_t card;/* metadata of currently selected card */ static crc_t legic_crc; diff --git a/armsrc/legicrf.h b/armsrc/legicrf.h index 76c392257f..47a7f89d6d 100644 --- a/armsrc/legicrf.h +++ b/armsrc/legicrf.h @@ -12,7 +12,7 @@ #ifndef __LEGICRF_H #define __LEGICRF_H -#include "proxmark3.h" +#include "common.h" void LegicRfInfo(void); void LegicRfReader(uint16_t offset, uint16_t len, uint8_t iv); diff --git a/armsrc/legicrfsim.c b/armsrc/legicrfsim.c index 0500e3e32b..111c4940b3 100644 --- a/armsrc/legicrfsim.c +++ b/armsrc/legicrfsim.c @@ -11,11 +11,17 @@ //----------------------------------------------------------------------------- #include "legicrf.h" -#include "ticks.h" /* timers */ #include "crc.h" /* legic crc-4 */ #include "legic_prng.h" /* legic PRNG impl */ #include "legic.h" /* legic_card_select_t struct */ +#include "proxmark3_arm.h" +#include "BigBuf.h" +#include "fpgaloader.h" +#include "ticks.h" +#include "dbprint.h" +#include "util.h" + static uint8_t *legic_mem; /* card memory, used for sim */ static legic_card_select_t card;/* metadata of currently selected card */ static crc_t legic_crc; diff --git a/armsrc/legicrfsim.h b/armsrc/legicrfsim.h index 27fce129b9..3d25fae0c9 100644 --- a/armsrc/legicrfsim.h +++ b/armsrc/legicrfsim.h @@ -12,7 +12,7 @@ #ifndef __LEGICRFSIM_H #define __LEGICRFSIM_H -#include "proxmark3.h" +#include "common.h" void LegicRfSimulate(uint8_t tagtype); diff --git a/armsrc/lfops.c b/armsrc/lfops.c index 1ef366cfb0..bee1413fc5 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -8,18 +8,23 @@ // Also routines for raw mode reading/simulating of LF waveform //----------------------------------------------------------------------------- -#include "proxmark3.h" -#include "apps.h" +#include "lfops.h" + +#include "proxmark3_arm.h" +#include "cmd.h" +#include "BigBuf.h" +#include "fpgaloader.h" +#include "ticks.h" +#include "dbprint.h" #include "util.h" -#include "hitag2.h" +#include "commonutil.h" + #include "crc16.h" #include "string.h" #include "printf.h" #include "lfdemod.h" #include "lfsampling.h" #include "protocols.h" -#include "usb_cdc.h" // for usb_poll_validate_length -#include "common.h" #include "pmflash.h" #include "flashmem.h" // persistence on flash @@ -154,6 +159,30 @@ t55xx_configurations_t T55xx_Timing = { #define T55XX_DLMODE_1OF4 3 // 1 of 4 #define T55XX_LONGLEADINGREFERENCE 4 // Value to tell Write Bit to send long reference +// ATA55xx shared presets & routines +static uint32_t GetT55xxClockBit(uint32_t clock) { + switch (clock) { + case 128: + return T55x7_BITRATE_RF_128; + case 100: + return T55x7_BITRATE_RF_100; + case 64: + return T55x7_BITRATE_RF_64; + case 50: + return T55x7_BITRATE_RF_50; + case 40: + return T55x7_BITRATE_RF_40; + case 32: + return T55x7_BITRATE_RF_32; + case 16: + return T55x7_BITRATE_RF_16; + case 8: + return T55x7_BITRATE_RF_8; + default : + return 0; + } +} + void printT55xxConfig(void) { #define PRN_NA sprintf(s + strlen(s), _RED_("N/A") "| "); diff --git a/armsrc/lfops.h b/armsrc/lfops.h new file mode 100644 index 0000000000..186b41f909 --- /dev/null +++ b/armsrc/lfops.h @@ -0,0 +1,69 @@ +//----------------------------------------------------------------------------- +// Jonathan Westhues, Aug 2005 +// Gerhard de Koning Gans, April 2008, May 2011 +// +// This code is licensed to you under the terms of the GNU GPL, version 2 or, +// at your option, any later version. See the LICENSE.txt file for the text of +// the license. +//----------------------------------------------------------------------------- +// Definitions internal to the app source. +//----------------------------------------------------------------------------- +#ifndef __LFOPS_H +#define __LFOPS_H + +#include "common.h" + +#include "pm3_cmd.h" // struct + +extern uint8_t decimation; +extern uint8_t bits_per_sample ; +extern bool averaging; + +void AcquireRawAdcSamples125k(int divisor); +void ModThenAcquireRawAdcSamples125k(uint32_t delay_off, uint32_t period_0, uint32_t period_1, uint8_t *command); +void ReadTItag(void); +void WriteTItag(uint32_t idhi, uint32_t idlo, uint16_t crc); + +void AcquireTiType(void); +void AcquireRawBitsTI(void); +void SimulateTagLowFrequencyEx(int period, int gap, bool ledcontrol, int numcycles); +void SimulateTagLowFrequency(int period, int gap, bool ledcontrol); +void SimulateTagLowFrequencyBidir(int divisor, int max_bitlen); + +void CmdHIDsimTAGEx(uint32_t hi, uint32_t lo, bool ledcontrol, int numcycles); +void CmdHIDsimTAG(uint32_t hi, uint32_t lo, bool ledcontrol); + +void CmdFSKsimTAG(uint8_t fchigh, uint8_t fclow, uint8_t separator, uint8_t clk, uint16_t bitslen, uint8_t *bits, bool ledcontrol); +void CmdASKsimTAG(uint8_t encoding, uint8_t invert, uint8_t separator, uint8_t clk, uint16_t size, uint8_t *bits, bool ledcontrol); +void CmdPSKsimTag(uint8_t carrier, uint8_t invert, uint8_t clk, uint16_t size, uint8_t *bits, bool ledcontrol); + +void CmdHIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol); +void CmdAWIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol); // Realtime demodulation mode for AWID26 +void CmdEM410xdemod(int findone, uint32_t *high, uint64_t *low, int ledcontrol); +void CmdIOdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol); +void CopyIOtoT55x7(uint32_t hi, uint32_t lo); // Clone an ioProx card to T5557/T5567 +void CopyHIDtoT55x7(uint32_t hi2, uint32_t hi, uint32_t lo, uint8_t longFMT); // Clone an HID card to T5557/T5567 +void CopyVikingtoT55xx(uint32_t block1, uint32_t block2, uint8_t Q5); +void WriteEM410x(uint32_t card, uint32_t id_hi, uint32_t id_lo); +void CopyIndala64toT55x7(uint32_t hi, uint32_t lo); // Clone Indala 64-bit tag by UID to T55x7 +void CopyIndala224toT55x7(uint32_t uid1, uint32_t uid2, uint32_t uid3, uint32_t uid4, uint32_t uid5, uint32_t uid6, uint32_t uid7); // Clone Indala 224-bit tag by UID to T55x7 +void T55xxResetRead(uint8_t flags); +//id T55xxWriteBlock(uint32_t data, uint8_t blockno, uint32_t pwd, uint8_t flags); +void T55xxWriteBlock(uint8_t *data); +// void T55xxWriteBlockExt(uint32_t data, uint8_t blockno, uint32_t pwd, uint8_t flags); +void T55xxReadBlock(uint8_t page, bool pwd_mode, bool brute_mem, uint8_t block, uint32_t pwd, uint8_t downlink_mode); +void T55xxWakeUp(uint32_t pwd, uint8_t flags); +void T55xx_ChkPwds(uint8_t flags); + +void TurnReadLFOn(uint32_t delay); + +void EM4xReadWord(uint8_t addr, uint32_t pwd, uint8_t usepwd); +void EM4xWriteWord(uint8_t addr, uint32_t data, uint32_t pwd, uint8_t usepwd); + +void Cotag(uint32_t arg0); +void setT55xxConfig(uint8_t arg0, t55xx_configurations_t *c); +t55xx_configurations_t *getT55xxConfig(void); +void printT55xxConfig(void); +void loadT55xxConfig(void); + +#endif diff --git a/armsrc/lfsampling.c b/armsrc/lfsampling.c index 2e6ed88a48..498d8f747e 100644 --- a/armsrc/lfsampling.c +++ b/armsrc/lfsampling.c @@ -8,6 +8,14 @@ #include "lfsampling.h" +#include "proxmark3_arm.h" +#include "BigBuf.h" +#include "fpgaloader.h" +#include "ticks.h" +#include "dbprint.h" +#include "util.h" +#include "lfdemod.h" + /* Default LF config is set to: decimation = 1 (we keep 1 out of 1 samples) diff --git a/armsrc/lfsampling.h b/armsrc/lfsampling.h index e3c7a0b4de..b17a871ba1 100644 --- a/armsrc/lfsampling.h +++ b/armsrc/lfsampling.h @@ -1,12 +1,8 @@ #ifndef __LFSAMPLING_H #define __LFSAMPLING_H -#include "proxmark3.h" -#include "apps.h" -#include "util.h" -#include "string.h" -#include "usb_cdc.h" // for usb_poll_validate_length -#include "ticks.h" // for StartTicks +#include "common.h" +#include "pm3_cmd.h" typedef struct BitstreamOut BitstreamOut; @@ -82,5 +78,4 @@ sample_config *getSamplingConfig(); void printConfig(); - #endif // __LFSAMPLING_H diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index 3784f8febc..5e9de52dd0 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -15,9 +15,23 @@ #include "mifarecmd.h" -#include - #include "pmflash.h" +#include "proxmark3_arm.h" +#include "string.h" +#include "mifareutil.h" +#include "protocols.h" +#include "parity.h" +#include "BigBuf.h" +#include "cmd.h" +#include "flashmem.h" +#include "fpgaloader.h" +#include "iso14443a.h" +#include "mifaredesfire.h" +#include "util.h" +#include "commonutil.h" +#include "crc16.h" +#include "dbprint.h" +#include "ticks.h" #ifndef HARDNESTED_AUTHENTICATION_TIMEOUT # define HARDNESTED_AUTHENTICATION_TIMEOUT 848 // card times out 1ms after wrong authentication (according to NXP documentation) diff --git a/armsrc/mifarecmd.h b/armsrc/mifarecmd.h index 5e4a5cf97b..445b04130e 100644 --- a/armsrc/mifarecmd.h +++ b/armsrc/mifarecmd.h @@ -1,27 +1,52 @@ //----------------------------------------------------------------------------- -// Merlok - June 2011 -// Gerhard de Koning Gans - May 2008 -// Hagen Fritsch - June 2010 +// Jonathan Westhues, Aug 2005 +// Gerhard de Koning Gans, April 2008, May 2011 // // This code is licensed to you under the terms of the GNU GPL, version 2 or, // at your option, any later version. See the LICENSE.txt file for the text of // the license. //----------------------------------------------------------------------------- -// Routines to support ISO 14443 type A. +// Definitions internal to the app source. //----------------------------------------------------------------------------- - #ifndef __MIFARECMD_H #define __MIFARECMD_H -#include "proxmark3.h" -#include "apps.h" -#include "util.h" -#include "string.h" -#include "iso14443a.h" -#include "crapto1/crapto1.h" -#include "mifareutil.h" #include "common.h" -#include "crc.h" -#include "protocols.h" -#include "parity.h" + +void MifareReadBlock(uint8_t blockNo, uint8_t keyType, uint8_t *datain); + +void MifareUReadBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain); +void MifareUC_Auth(uint8_t arg0, uint8_t *keybytes); +void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain); +void MifareReadSector(uint8_t arg0, uint8_t arg1, uint8_t *datain); +void MifareWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain); +//void MifareUWriteBlockCompat(uint8_t arg0,uint8_t *datain); +void MifareUWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain); +void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain); +void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags, uint8_t *datain); +void MifareAcquireNonces(uint32_t arg0, uint32_t flags); +void MifareChkKeys(uint8_t *datain); +void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain); + +void MifareEMemClr(void); +void MifareEMemSet(uint8_t blockno, uint8_t blockcnt, uint8_t blockwidth, uint8_t *datain); +void MifareEMemGet(uint8_t blockno, uint8_t blockcnt); +int MifareECardLoad(uint32_t arg0, uint32_t arg1); + +void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain); // Work with "magic Chinese" card +void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain); +void MifareCIdent(); // is "magic chinese" card? + +void MifareSetMod(uint8_t *datain); +void MifareUSetPwd(uint8_t arg0, uint8_t *datain); +void OnSuccessMagic(); +void OnErrorMagic(uint8_t reason); + +int32_t dist_nt(uint32_t nt1, uint32_t nt2); +void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype); +//void RAMFUNC SniffMifare(uint8_t param); + +void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain); +void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain); + #endif diff --git a/armsrc/mifaredesfire.c b/armsrc/mifaredesfire.c index c57fed866b..e16c00ed18 100644 --- a/armsrc/mifaredesfire.c +++ b/armsrc/mifaredesfire.c @@ -1,5 +1,20 @@ #include "mifaredesfire.h" +#include "common.h" +#include "proxmark3_arm.h" +#include "string.h" +#include "BigBuf.h" +#include "desfire_key.h" +#include "mifareutil.h" +#include "des.h" +#include "cmd.h" +#include "dbprint.h" +#include "fpgaloader.h" +#include "iso14443a.h" +#include "crc16.h" +#include "mbedtls/aes.h" +#include "commonutil.h" + #define MAX_APPLICATION_COUNT 28 #define MAX_FILE_COUNT 16 #define MAX_DESFIRE_FRAME_SIZE 60 diff --git a/armsrc/mifaredesfire.h b/armsrc/mifaredesfire.h index 7547dfcb25..8daed69aac 100644 --- a/armsrc/mifaredesfire.h +++ b/armsrc/mifaredesfire.h @@ -1,13 +1,26 @@ +//----------------------------------------------------------------------------- +// Jonathan Westhues, Aug 2005 +// Gerhard de Koning Gans, April 2008, May 2011 +// +// This code is licensed to you under the terms of the GNU GPL, version 2 or, +// at your option, any later version. See the LICENSE.txt file for the text of +// the license. +//----------------------------------------------------------------------------- +// Definitions internal to the app source. +//----------------------------------------------------------------------------- #ifndef __MIFAREDESFIRE_H #define __MIFAREDESFIRE_H #include "common.h" -#include "proxmark3.h" -#include "apps.h" -#include "string.h" -#include "BigBuf.h" -#include "iso14443a.h" -#include "desfire_key.h" -#include "mifareutil.h" -#include "des.h" + +bool InitDesfireCard(); +void MifareSendCommand(uint8_t arg0, uint8_t arg1, uint8_t *datain); +void MifareDesfireGetInformation(); +void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain); +void ReaderMifareDES(uint32_t param, uint32_t param2, uint8_t *datain); +int DesfireAPDU(uint8_t *cmd, size_t cmd_len, uint8_t *dataout); +size_t CreateAPDU(uint8_t *datain, size_t len, uint8_t *dataout); +void OnSuccess(); +void OnError(uint8_t reason); + #endif diff --git a/armsrc/mifaresim.c b/armsrc/mifaresim.c index 5eadef0ea7..7edcec3982 100644 --- a/armsrc/mifaresim.c +++ b/armsrc/mifaresim.c @@ -20,19 +20,24 @@ // /!\ Printing Debug message is disrupting emulation, // Only use with caution during debugging +#include "mifaresim.h" + +#include #include "iso14443a.h" -#include "mifaresim.h" -#include "crapto1/crapto1.h" #include "BigBuf.h" #include "string.h" #include "mifareutil.h" #include "fpgaloader.h" -#include "proxmark3.h" -#include "usb_cdc.h" +#include "proxmark3_arm.h" #include "cmd.h" #include "protocols.h" -#include "apps.h" +#include "appmain.h" +#include "util.h" +#include "commonutil.h" +#include "crc16.h" +#include "dbprint.h" +#include "ticks.h" static bool IsTrailerAccessAllowed(uint8_t blockNo, uint8_t keytype, uint8_t action) { uint8_t sector_trailer[16]; @@ -506,7 +511,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1 uint8_t rAUTH_NT_keystream[4]; uint32_t nonce = 0; - tUart *uart = GetUart(); + tUart14a *uart = GetUart14a(); // free eventually allocated BigBuf memory but keep Emulator Memory BigBuf_free_keep_EM(); diff --git a/armsrc/mifaresim.h b/armsrc/mifaresim.h index a161d2974e..d8c15aee2a 100644 --- a/armsrc/mifaresim.h +++ b/armsrc/mifaresim.h @@ -13,14 +13,12 @@ #ifndef __MIFARESIM_H #define __MIFARESIM_H -#include +#include "common.h" #ifndef CheckCrc14A # define CheckCrc14A(data, len) check_crc(CRC_14443_A, (data), (len)) #endif -void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint16_t atqa, uint8_t sak); - #define AC_DATA_READ 0 #define AC_DATA_WRITE 1 #define AC_DATA_INC 2 @@ -36,4 +34,6 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1 #define AUTHKEYB 1 #define AUTHKEYNONE 0xff +void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint16_t atqa, uint8_t sak); + #endif diff --git a/armsrc/mifaresniff.c b/armsrc/mifaresniff_disabled.c similarity index 96% rename from armsrc/mifaresniff.c rename to armsrc/mifaresniff_disabled.c index 4171ab5722..799fd62bed 100644 --- a/armsrc/mifaresniff.c +++ b/armsrc/mifaresniff_disabled.c @@ -68,10 +68,10 @@ void RAMFUNC SniffMifare(uint8_t param) { // Set up the demodulator for tag -> reader responses. - DemodInit(receivedResp, receivedRespPar); + Demod14aInit(receivedResp, receivedRespPar); // Set up the demodulator for the reader -> tag commands - UartInit(receivedCmd, receivedCmdPar); + Uart14aInit(receivedCmd, receivedCmdPar); // Setup and start DMA. // set transfer address and number of bytes. Start transfer. @@ -80,8 +80,8 @@ void RAMFUNC SniffMifare(uint8_t param) { return; } - tUart *uart = GetUart(); - tDemod *demod = GetDemod(); + tUart14a *uart = GetUart14a(); + tDemod14a *demod = GetDemod14a(); MfSniffInit(); @@ -149,10 +149,10 @@ void RAMFUNC SniffMifare(uint8_t param) { uint8_t readerbyte = (previous_data & 0xF0) | (*data >> 4); if (MillerDecoding(readerbyte, (sniffCounter - 1) * 4)) { LogTrace(receivedCmd, uart->len, 0, 0, NULL, true); - DemodReset(); - UartReset(); + Demod14aReset(); + Uart14aReset(); } - ReaderIsActive = (uart->state != STATE_UNSYNCD); + ReaderIsActive = (uart->state != STATE_14A_UNSYNCD); } // no need to try decoding tag data if the reader is sending @@ -160,10 +160,10 @@ void RAMFUNC SniffMifare(uint8_t param) { uint8_t tagbyte = (previous_data << 4) | (*data & 0x0F); if (ManchesterDecoding(tagbyte, 0, (sniffCounter - 1) * 4)) { LogTrace(receivedResp, demod->len, 0, 0, NULL, false); - DemodReset(); - UartReset(); + Demod14aReset(); + Uart14aReset(); } - TagIsActive = (demod->state != DEMOD_UNSYNCD); + TagIsActive = (demod->state != DEMOD_14A_UNSYNCD); } } previous_data = *data; diff --git a/armsrc/mifaresniff.h b/armsrc/mifaresniff_disabled.h similarity index 87% rename from armsrc/mifaresniff.h rename to armsrc/mifaresniff_disabled.h index 198d14daf0..426e5ccfaf 100644 --- a/armsrc/mifaresniff.h +++ b/armsrc/mifaresniff_disabled.h @@ -11,13 +11,6 @@ #ifndef __MIFARESNIFF_H #define __MIFARESNIFF_H -#include "proxmark3.h" -#include "apps.h" -#include "util.h" -#include "string.h" -#include "iso14443a.h" -#include "crapto1/crapto1.h" -#include "mifareutil.h" #include "common.h" #define SNF_INIT 0 diff --git a/armsrc/mifareutil.c b/armsrc/mifareutil.c index b5f7567f9e..ca112f1f89 100644 --- a/armsrc/mifareutil.c +++ b/armsrc/mifareutil.c @@ -9,6 +9,17 @@ //----------------------------------------------------------------------------- #include "mifareutil.h" +#include "string.h" +#include "BigBuf.h" +#include "iso14443a.h" +#include "ticks.h" +#include "dbprint.h" +#include "parity.h" +#include "commonutil.h" +#include "crc16.h" +#include "protocols.h" +#include "des.h" + int DBGLEVEL = DBG_ERROR; // crypto1 helpers diff --git a/armsrc/mifareutil.h b/armsrc/mifareutil.h index a2086c5e7a..64eb04545b 100644 --- a/armsrc/mifareutil.h +++ b/armsrc/mifareutil.h @@ -12,14 +12,8 @@ #ifndef __MIFAREUTIL_H #define __MIFAREUTIL_H -#include "proxmark3.h" -#include "apps.h" -#include "parity.h" -#include "util.h" -#include "string.h" -#include "iso14443a.h" +#include "common.h" #include "crapto1/crapto1.h" -#include "des.h" // mifare authentication #define CRYPT_NONE 0 diff --git a/armsrc/nprintf.c b/armsrc/nprintf.c index 62e6ea8c0a..b61ad794d5 100644 --- a/armsrc/nprintf.c +++ b/armsrc/nprintf.c @@ -30,9 +30,6 @@ // /////////////////////////////////////////////////////////////////////////////// -#include -#include - #include "nprintf.h" diff --git a/armsrc/nprintf.h b/armsrc/nprintf.h index 3cfdb41341..5c83384b72 100644 --- a/armsrc/nprintf.h +++ b/armsrc/nprintf.h @@ -32,14 +32,10 @@ #ifndef _PRINTF_H_ #define _PRINTF_H_ -#include +#include +#include #include - - -#ifdef __cplusplus -extern "C" { -#endif - +#include /** * Output a character to a custom device like UART, used by the printf() function @@ -108,10 +104,4 @@ int vprintf_(const char *format, va_list va); */ int fctprintf(void (*out)(char character, void *arg), void *arg, const char *format, ...); - -#ifdef __cplusplus -} -#endif - - #endif // _PRINTF_H_ diff --git a/armsrc/optimized_cipher.h b/armsrc/optimized_cipher.h index 9bf0516def..893297ddd9 100644 --- a/armsrc/optimized_cipher.h +++ b/armsrc/optimized_cipher.h @@ -1,9 +1,7 @@ #ifndef OPTIMIZED_CIPHER_H #define OPTIMIZED_CIPHER_H -#include -#include -#include +#include "common.h" /** * Definition 1 (Cipher state). A cipher state of iClass s is an element of F 40/2 diff --git a/armsrc/pcf7931.c b/armsrc/pcf7931.c index a80e30927a..2c679b31f6 100644 --- a/armsrc/pcf7931.c +++ b/armsrc/pcf7931.c @@ -1,5 +1,15 @@ #include "pcf7931.h" +#include "proxmark3_arm.h" +#include "cmd.h" +#include "BigBuf.h" +#include "fpgaloader.h" +#include "ticks.h" +#include "dbprint.h" +#include "util.h" +#include "lfsampling.h" +#include "string.h" + #define T0_PCF 8 //period for the pcf7931 in us #define ALLOC 16 diff --git a/armsrc/pcf7931.h b/armsrc/pcf7931.h index 5e3c5a8e4a..67a11f5f8c 100644 --- a/armsrc/pcf7931.h +++ b/armsrc/pcf7931.h @@ -1,11 +1,7 @@ #ifndef __PCF7931_H #define __PCF7931_H -#include "proxmark3.h" -#include "apps.h" -#include "lfsampling.h" -#include "pcf7931.h" -#include "string.h" +#include "common.h" size_t DemodPCF7931(uint8_t **outBlocks); bool IsBlock0PCF7931(uint8_t *block); diff --git a/armsrc/printf.c b/armsrc/printf.c index d0d873e7dc..0dffbb037d 100644 --- a/armsrc/printf.c +++ b/armsrc/printf.c @@ -35,6 +35,8 @@ */ #include "printf.h" +#include "string.h" + typedef unsigned char u_char; typedef unsigned int u_int; typedef unsigned long long u_quad_t; diff --git a/armsrc/printf.h b/armsrc/printf.h index ff0143790e..bd0a6e2c96 100644 --- a/armsrc/printf.h +++ b/armsrc/printf.h @@ -11,9 +11,8 @@ #ifndef __PRINTF_H #define __PRINTF_H -#include -#include -#include "string.h" +#include "common.h" +#include // va_list int kvsprintf(const char *fmt, void *arg, int radix, va_list ap) __attribute__((format(printf, 1, 0))); int vsprintf(char *dest, const char *fmt, va_list ap) __attribute__((format(printf, 2, 0))); diff --git a/common/radixsort.c b/armsrc/radixsort.c similarity index 100% rename from common/radixsort.c rename to armsrc/radixsort.c diff --git a/common/radixsort.h b/armsrc/radixsort.h similarity index 87% rename from common/radixsort.h rename to armsrc/radixsort.h index 41a036461b..fb2bcc044f 100644 --- a/common/radixsort.h +++ b/armsrc/radixsort.h @@ -1,9 +1,7 @@ #ifndef RADIXSORT_H__ #define RADIXSORT_H__ -#include -#include -#include +#include "common.h" typedef union { struct { @@ -20,4 +18,5 @@ typedef union { } rscounts_t; uint64_t *radixSort(uint64_t *array, uint32_t size); + #endif // RADIXSORT_H__ diff --git a/armsrc/spiffs.c b/armsrc/spiffs.c index 7fd712e7f7..de6e9e2262 100644 --- a/armsrc/spiffs.c +++ b/armsrc/spiffs.c @@ -43,6 +43,12 @@ RDV40_SPIFFS_SAFE_FOOTER #include "spiffs.h" +#include "flashmem.h" +#include "dbprint.h" +#include "printf.h" +#include "common.h" +#include "string.h" +#include "BigBuf.h" ///// FLASH LEVEL R/W/E operations for feeding SPIFFS Driver///////////////// static s32_t rdv40_spiffs_llread(u32_t addr, u32_t size, u8_t *dst) { diff --git a/armsrc/spiffs.h b/armsrc/spiffs.h index f36bde4b03..29e8215b0e 100644 --- a/armsrc/spiffs.h +++ b/armsrc/spiffs.h @@ -7,9 +7,8 @@ #ifndef SPIFFS_H_ #define SPIFFS_H_ -#if defined(__cplusplus) -extern "C" { -#endif + +#include "common.h" #include "spiffs_config.h" @@ -854,8 +853,5 @@ u32_t SPIFFS_buffer_bytes_for_cache(spiffs *fs, u32_t num_pages); #if SPIFFS_CACHE #endif -#if defined(__cplusplus) -} -#endif #endif /* SPIFFS_H_ */ diff --git a/armsrc/spiffs_config.h b/armsrc/spiffs_config.h index 99557f41f4..6fe1f48c6d 100644 --- a/armsrc/spiffs_config.h +++ b/armsrc/spiffs_config.h @@ -8,22 +8,7 @@ #ifndef SPIFFS_CONFIG_H_ #define SPIFFS_CONFIG_H_ -// ----------- 8< ------------ -// Following includes are for the linux test build of spiffs -// These may/should/must be removed/altered/replaced in your target -//#include -//#include -// -#include "printf.h" -#include "string.h" -#include "flashmem.h" - -void Dbprintf(const char *fmt, ...); - -//#include -//#include -// ----------- >8 ------------ - +#include "common.h" typedef int s32_t; typedef uint32_t u32_t; diff --git a/armsrc/spiffs_nucleus.h b/armsrc/spiffs_nucleus.h index c4a3603845..c437faf30c 100644 --- a/armsrc/spiffs_nucleus.h +++ b/armsrc/spiffs_nucleus.h @@ -110,6 +110,11 @@ #ifndef SPIFFS_NUCLEUS_H_ #define SPIFFS_NUCLEUS_H_ +#include "common.h" + +#include "string.h" +#include "spiffs.h" + #define _SPIFFS_ERR_CHECK_FIRST (SPIFFS_ERR_INTERNAL - 1) #define SPIFFS_ERR_CHECK_OBJ_ID_MISM (SPIFFS_ERR_INTERNAL - 1) #define SPIFFS_ERR_CHECK_SPIX_MISM (SPIFFS_ERR_INTERNAL - 2) diff --git a/armsrc/start.c b/armsrc/start.c index 94eb429acf..3e6f347025 100644 --- a/armsrc/start.c +++ b/armsrc/start.c @@ -12,8 +12,8 @@ #ifndef __START_H #define __START_H -#include "proxmark3.h" -#include "apps.h" +#include "proxmark3_arm.h" +#include "appmain.h" #include "zlib.h" #include "BigBuf.h" diff --git a/armsrc/string.h b/armsrc/string.h index 5e3e311378..781641fb9d 100644 --- a/armsrc/string.h +++ b/armsrc/string.h @@ -12,7 +12,7 @@ #ifndef __STRING_H #define __STRING_H -#include +#include "common.h" int strlen(const char *str); void *memcpy(void *dest, const void *src, int len); @@ -36,7 +36,4 @@ int strncmp(const char *s1, const char *s2, size_t n); char c_tolower(int c); char c_isprint(unsigned char c); - - - #endif /* __STRING_H */ diff --git a/armsrc/thinfilm.c b/armsrc/thinfilm.c index 735fdb0413..bd8e696fb0 100644 --- a/armsrc/thinfilm.c +++ b/armsrc/thinfilm.c @@ -10,6 +10,16 @@ #include "thinfilm.h" +#include "proxmark3_arm.h" +#include "cmd.h" +#include "appmain.h" +#include "BigBuf.h" +#include "iso14443a.h" +#include "fpgaloader.h" +#include "ticks.h" +#include "dbprint.h" +#include "util.h" + /** * ref * https://www.thinfilmnfc.com/wp-content/uploads/2017/09/Thinfilm-Kovio-NFC-Barcode-Protocol-Tag-Functional-Specification-v3.4-2017-05-26.pdf diff --git a/armsrc/thinfilm.h b/armsrc/thinfilm.h index 15453e3c21..af15644826 100644 --- a/armsrc/thinfilm.h +++ b/armsrc/thinfilm.h @@ -11,20 +11,9 @@ #ifndef __THINFILM_H #define __THINFILM_H -#ifdef __cplusplus -extern "C" { -#endif - -#include "pm3_cmd.h" -#include "cmd.h" -#include "apps.h" -#include "iso14443a.h" +#include "common.h" void ReadThinFilm(void); void SimulateThinFilm(uint8_t *data, size_t len); -#ifdef __cplusplus -} -#endif - #endif /* __ISO14443A_H */ diff --git a/armsrc/ticks.c b/armsrc/ticks.c index 610afb5a23..43555b21b9 100644 --- a/armsrc/ticks.c +++ b/armsrc/ticks.c @@ -10,6 +10,9 @@ //----------------------------------------------------------------------------- #include "ticks.h" +#include "proxmark3_arm.h" +#include "dbprint.h" + // timer counts in 21.3us increments (1024/48MHz), rounding applies // WARNING: timer can't measure more than 1.39s (21.3us * 0xffff) void SpinDelayUs(int us) { diff --git a/armsrc/ticks.h b/armsrc/ticks.h index 9ff0d60000..089501c871 100644 --- a/armsrc/ticks.h +++ b/armsrc/ticks.h @@ -12,11 +12,7 @@ #ifndef __TICKS_H #define __TICKS_H -#include -#include #include "common.h" -#include "apps.h" -#include "proxmark3.h" #ifndef GET_TICKS #define GET_TICKS GetTicks() @@ -45,4 +41,5 @@ void WaitUS(uint16_t us); void WaitMS(uint16_t ms); void StopTicks(void); + #endif diff --git a/common/usart.c b/armsrc/usart.c similarity index 99% rename from common/usart.c rename to armsrc/usart.c index cb52d01168..f3abb40a1d 100644 --- a/common/usart.c +++ b/armsrc/usart.c @@ -8,10 +8,8 @@ //----------------------------------------------------------------------------- // The main USART code, for serial communications over FPC connector //----------------------------------------------------------------------------- -#include "cmd.h" #include "usart.h" -#include "string.h" -#include "../armsrc/ticks.h" // startcountus +#include "proxmark3_arm.h" volatile AT91PS_USART pUS1 = AT91C_BASE_US1; volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA; diff --git a/common/usart.h b/armsrc/usart.h similarity index 58% rename from common/usart.h rename to armsrc/usart.h index ef0691df58..01ca0d8091 100644 --- a/common/usart.h +++ b/armsrc/usart.h @@ -1,28 +1,20 @@ #ifndef __USART_H #define __USART_H -#include -#include "proxmark3.h" +#include "common.h" +#include "usart_defs.h" -//#define USART_BAUD_RATE 9600 -#define USART_BAUD_RATE 115200 - -// BT HC-06 physical layer runs at 128kbps -// so it's possible to gain a little bit by using 230400 -// with some risk to overflow its internal buffers: -//#define USART_BAUD_RATE 230400 +#define USART_BUFFLEN 512 +#define USART_FIFOLEN (2*USART_BUFFLEN) // Higher baudrates are pointless, only increasing overflow risk extern uint32_t usart_baudrate; -#define USART_PARITY 'N' extern uint8_t usart_parity; void usart_init(uint32_t baudrate, uint8_t parity); int usart_writebuffer_sync(uint8_t *data, size_t len); uint32_t usart_read_ng(uint8_t *data, size_t len); uint16_t usart_rxdata_available(void); -#define USART_BUFFLEN 512 -#define USART_FIFOLEN (2*USART_BUFFLEN) #endif diff --git a/armsrc/util.c b/armsrc/util.c index a691766d05..b855ab9491 100644 --- a/armsrc/util.c +++ b/armsrc/util.c @@ -9,6 +9,14 @@ //----------------------------------------------------------------------------- #include "util.h" +#include "proxmark3_arm.h" +#include "ticks.h" +#include "commonutil.h" +#include "dbprint.h" +#include "string.h" +#include "usb_cdc.h" +#include "usart.h" + size_t nbytes(size_t nbits) { return (nbits >> 3) + ((nbits % 8) > 0); } diff --git a/armsrc/util.h b/armsrc/util.h index 8649f04314..9748152efc 100644 --- a/armsrc/util.h +++ b/armsrc/util.h @@ -12,11 +12,6 @@ #define __UTIL_H #include "common.h" -#include "commonutil.h" -#include "proxmark3.h" -#include "string.h" -#include "BigBuf.h" -#include "ticks.h" // Basic macros diff --git a/armsrc/vtsend.c b/armsrc/vtsend.c index e851d43342..f07793cced 100644 --- a/armsrc/vtsend.c +++ b/armsrc/vtsend.c @@ -31,7 +31,8 @@ */ #include "vtsend.h" -#include "apps.h" +#include "pm3_cmd.h" +#include "dbprint.h" #define ESC (0x1B) //#define UART_WRITE(P, BUF, SIZ) (P)->uart_write(BUF, SIZ, (P)->extobj) diff --git a/armsrc/vtsend.h b/armsrc/vtsend.h index 4dcb0c62b7..63d3d24617 100644 --- a/armsrc/vtsend.h +++ b/armsrc/vtsend.h @@ -33,6 +33,8 @@ #ifndef VTSEND_H #define VTSEND_H +#include "common.h" + #define VTSEND_COLOR_BLACK (0) #define VTSEND_COLOR_RED (1) #define VTSEND_COLOR_GREEN (2) @@ -56,10 +58,6 @@ typedef struct { void *extobj; } vtsend_t; -#ifdef __cplusplus -extern "C" { -#endif - int vtsend_init(vtsend_t *p, VTSEND_SERIAL_WRITE uart_write, void *extobj); int vtsend_cursor_position(vtsend_t *p, const int column, const int line); int vtsend_cursor_up(vtsend_t *p, const int n); @@ -84,10 +82,4 @@ int vtsend_fill_box( vtsend_t *p, const int x1, const int y1, const int x2, const int y2); -#ifdef __cplusplus -} #endif - -#endif - - diff --git a/common/wiegand.c b/armsrc/wiegand.c similarity index 100% rename from common/wiegand.c rename to armsrc/wiegand.c diff --git a/common/wiegand.h b/armsrc/wiegand.h similarity index 100% rename from common/wiegand.h rename to armsrc/wiegand.h diff --git a/bootrom/Makefile b/bootrom/Makefile index afc4162a7b..c4103b5228 100644 --- a/bootrom/Makefile +++ b/bootrom/Makefile @@ -3,13 +3,13 @@ # at your option, any later version. See the LICENSE.txt file for the text of # the license. #----------------------------------------------------------------------------- -# Makefile for bootrom, see ../common/Makefile.common for common settings +# Makefile for bootrom, see ../common_arm/Makefile.common for common settings #----------------------------------------------------------------------------- # DO NOT use thumb mode in the phase 1 bootloader since that generates a section with glue code ARMSRC = THUMBSRC = usb_cdc.c \ - bootrom.c + bootrom.c ASMSRC = ram-reset.s flash-reset.s VERSIONSRC = version.c @@ -29,7 +29,7 @@ APP_CFLAGS += -fno-stack-protector -fno-pie # Do not move this inclusion before the definition of {THUMB,ASM,ARM}SRC -include ../common/Makefile.common +include ../common_arm/Makefile.common OBJS = $(OBJDIR)/bootrom.s19 diff --git a/bootrom/bootrom.c b/bootrom/bootrom.c index 31bb139eff..2c1a6f23ad 100644 --- a/bootrom/bootrom.c +++ b/bootrom/bootrom.c @@ -6,9 +6,10 @@ // Main code for the bootloader //----------------------------------------------------------------------------- -#include #include "usb_cdc.h" +#include "proxmark3_arm.h" + struct common_area common_area __attribute__((section(".commonarea"))); unsigned int start_addr, end_addr, bootrom_unlocked; extern char _bootrom_start, _bootrom_end, _flash_start, _flash_end; diff --git a/bootrom/ldscript-flash b/bootrom/ldscript-flash index 26acf8242d..c9174ffcd8 100644 --- a/bootrom/ldscript-flash +++ b/bootrom/ldscript-flash @@ -8,7 +8,7 @@ ----------------------------------------------------------------------------- */ -INCLUDE ../common/ldscript.common +INCLUDE ../common_arm/ldscript.common PHDRS { diff --git a/client/Makefile b/client/Makefile index 47a890d0a5..e1cb031027 100644 --- a/client/Makefile +++ b/client/Makefile @@ -28,7 +28,7 @@ ENV_CFLAGS := $(CFLAGS) platform = $(shell uname) -VPATH = ../common ../zlib ../uart +VPATH = ../common ../common/zlib uart OBJDIR = obj LDLIBS = @@ -44,18 +44,19 @@ ifneq ($(platform),Darwin) LDLIBS += -Wl,--as-needed -latomic -Wl,--no-as-needed endif -LUALIB = ../liblua/liblua.a +LUALIBPATH = ./liblua +LUALIB = $(LUALIBPATH)/liblua.a JANSSONLIBPATH = ./jansson JANSSONLIB = $(JANSSONLIBPATH)/libjansson.a MBEDTLSLIBPATH = ../common/mbedtls MBEDTLSLIB = $(MBEDTLSLIBPATH)/libmbedtls.a CBORLIBPATH = ./tinycbor CBORLIB = $(CBORLIBPATH)/tinycbor.a -LIBS = -I../zlib -I../uart -I../liblua -I$(MBEDTLSLIBPATH) -I$(JANSSONLIBPATH) -I$(CBORLIBPATH) +LIBS = -I../common/zlib -Iuart -I$(LUALIBPATH) -I$(MBEDTLSLIBPATH) -I$(JANSSONLIBPATH) -I$(CBORLIBPATH) INCLUDES_CLIENT = -I. -I../include -I../common -I/opt/local/include $(LIBS) LDFLAGS = $(ENV_LDFLAGS) -CFLAGS = $(ENV_CFLAGS) -std=c99 -D_ISOC99_SOURCE -DPRESETS $(INCLUDES_CLIENT) -Wall -g -O3 +CFLAGS = $(ENV_CFLAGS) -std=c99 -D_ISOC99_SOURCE -DPRESETS $(INCLUDES_CLIENT) -Wall -Werror -g -O3 ifneq (,$(findstring MINGW,$(platform))) CFLAGS += -mno-ms-bitfields endif @@ -117,7 +118,7 @@ endif # Flags to generate temporary dependency files DEPFLAGS = -MT $@ -MMD -MP -MF $(OBJDIR)/$*.Td -# make temporary to final dependeny files after successful compilation +# make temporary to final dependency files after successful compilation POSTCOMPILE = $(MV) -f $(OBJDIR)/$*.Td $(OBJDIR)/$*.d CORESRCS = uart_posix.c \ @@ -237,7 +238,6 @@ CMDSRCS = crapto1/crapto1.c \ scripting.c \ cmdscript.c \ pm3_bitlib.c \ - protocols.c \ cmdcrc.c \ reveng/preset.c \ reveng/reveng.c \ @@ -333,7 +333,7 @@ lualibs/mf_default_keys.lua : default_keys.dic clean: $(Q)$(RM) $(CLEAN) - $(Q)$(MAKE) --no-print-directory -C ../liblua clean + $(Q)$(MAKE) --no-print-directory -C $(LUALIBPATH) clean $(Q)$(MAKE) --no-print-directory -C $(JANSSONLIBPATH) clean $(Q)$(MAKE) --no-print-directory -C $(MBEDTLSLIBPATH) clean $(Q)$(MAKE) --no-print-directory -C $(CBORLIBPATH) clean @@ -344,7 +344,7 @@ tarbin: $(BINS) lua_build: $(info [*] MAKE liblua for $(LUAPLATFORM)) - $(Q)$(MAKE) --no-print-directory -C ../liblua $(LUAPLATFORM) + $(Q)$(MAKE) --no-print-directory -C $(LUALIBPATH) $(LUAPLATFORM) jansson_build: $(info [*] MAKE jansson) diff --git a/client/cliparser/cliparser.c b/client/cliparser/cliparser.c index ae2124085b..02746c0f46 100644 --- a/client/cliparser/cliparser.c +++ b/client/cliparser/cliparser.c @@ -9,7 +9,6 @@ //----------------------------------------------------------------------------- #include "cliparser.h" -#include #include void **argtable = NULL; diff --git a/client/cliparser/cliparser.h b/client/cliparser/cliparser.h index 7da5097570..c67488d59a 100644 --- a/client/cliparser/cliparser.h +++ b/client/cliparser/cliparser.h @@ -12,7 +12,6 @@ #define __CLIPARSER_H #include "argtable3.h" #include "util.h" -#include #define arg_param_begin arg_lit0("hH", "help", "print this help and exit") #define arg_param_end arg_end(20) diff --git a/client/cmdanalyse.c b/client/cmdanalyse.c index 0821cc4d11..2e88f6e5b2 100644 --- a/client/cmdanalyse.c +++ b/client/cmdanalyse.c @@ -9,6 +9,19 @@ //----------------------------------------------------------------------------- #include "cmdanalyse.h" +#include // size_t +#include +#include // tolower + +#include "commonutil.h" // reflect... +#include "comms.h" // clearCommandBuffer +#include "cmdparser.h" // command_t +#include "ui.h" // PrintAndLog +#include "crc.h" +#include "crc16.h" // crc16 ccitt +#include "tea.h" +#include "legic_prng.h" + static int CmdHelp(const char *Cmd); static int usage_analyse_lcr(void) { diff --git a/client/cmdanalyse.h b/client/cmdanalyse.h index 20dc58a7eb..4d223be1b2 100644 --- a/client/cmdanalyse.h +++ b/client/cmdanalyse.h @@ -11,20 +11,7 @@ #ifndef CMDANALYSE_H__ #define CMDANALYSE_H__ -#include // size_t -#include -#include -#include "cmdmain.h" -#include "proxmark3.h" -#include "ui.h" // PrintAndLog -#include "util.h" -#include "crc.h" -#include "crc16.h" // crc16 ccitt -#include "tea.h" -#include "legic_prng.h" -#include "loclass/elite_crack.h" -#include "mifare/mfkey.h" // nonce2key -#include "util_posix.h" // msclock +#include "common.h" int CmdAnalyse(const char *Cmd); #endif diff --git a/client/cmdcrc.c b/client/cmdcrc.c index af4baae450..7f41b90e37 100644 --- a/client/cmdcrc.c +++ b/client/cmdcrc.c @@ -9,6 +9,23 @@ //----------------------------------------------------------------------------- #include "cmdcrc.h" +#include +#include +#include +#include + +#ifdef _WIN32 +# include +# include +# ifndef STDIN_FILENO +# define STDIN_FILENO 0 +# endif /* STDIN_FILENO */ +#endif /* _WIN32 */ + +#include "reveng/reveng.h" +#include "ui.h" +#include "util.h" + #define MAX_ARGS 20 static int split(char *str, char *arr[MAX_ARGS]) { diff --git a/client/cmdcrc.h b/client/cmdcrc.h index e45c004f5e..957cd1eec5 100644 --- a/client/cmdcrc.h +++ b/client/cmdcrc.h @@ -11,22 +11,7 @@ #ifndef CMDCRC_H__ #define CMDCRC_H__ -#ifdef _WIN32 -# include -# include -# ifndef STDIN_FILENO -# define STDIN_FILENO 0 -# endif /* STDIN_FILENO */ -#endif /* _WIN32 */ - -#include -#include -#include -#include -#include "cmdmain.h" -#include "reveng/reveng.h" -#include "ui.h" -#include "util.h" +#include "common.h" int CmdCrc(const char *Cmd); diff --git a/client/cmddata.c b/client/cmddata.c index 3887c6cb8a..81060cd592 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -9,6 +9,21 @@ //----------------------------------------------------------------------------- #include "cmddata.h" +#include +#include +#include // for CmdNorm INT_MIN && INT_MAX +#include // pow +#include // tolower + +#include "commonutil.h" // ARRAYLEN +#include "cmdparser.h" // for command_t +#include "ui.h" // for show graph controls +#include "graph.h" // for graph data +#include "comms.h" +#include "lfdemod.h" // for demod code +#include "loclass/cipherutils.h" // for decimating samples in getsamples +#include "cmdlfem4x.h" // askem410xdecode + uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN]; size_t DemodBufferLen = 0; size_t g_DemodStartIdx = 0; diff --git a/client/cmddata.h b/client/cmddata.h index 583af4dd15..a453fafb1b 100644 --- a/client/cmddata.h +++ b/client/cmddata.h @@ -11,26 +11,9 @@ #ifndef CMDDATA_H__ #define CMDDATA_H__ -#include //size_t -#include //uint_32+ -#include //bool -#include "cmdparser.h" // for command_t +#include "common.h" -#include // also included in util.h -#include // also included in util.h -#include -#include // for CmdNorm INT_MIN && INT_MAX -#include "util.h" -#include "cmdmain.h" -#include "proxmark3.h"// sendcommand -#include "ui.h" // for show graph controls -#include "graph.h" // for graph data -#include "comms.h" -#include "lfdemod.h" // for demod code -#include "crc.h" // for pyramid checksum maxim -#include "crc16.h" // for FDXB demod checksum -#include "loclass/cipherutils.h" // for decimating samples in getsamples -#include "cmdlfem4x.h" // askem410xdecode +//#include //size_t int CmdData(const char *Cmd); diff --git a/client/cmdflashmem.c b/client/cmdflashmem.c index c639ab1070..6bb6fbc3c5 100644 --- a/client/cmdflashmem.c +++ b/client/cmdflashmem.c @@ -9,9 +9,17 @@ //----------------------------------------------------------------------------- #include "cmdflashmem.h" +#include + +#include "cmdparser.h" // command_t + +#include "pmflash.h" +#include "loclass/fileutils.h" //saveFile +#include "comms.h" //getfromdevice +#include "cmdflashmemspiffs.h" // spiffs commands + #include "mbedtls/rsa.h" #include "mbedtls/sha1.h" -#include "mbedtls/base64.h" #define MCK 48000000 #define FLASH_MINFAST 24000000 //33000000 @@ -209,7 +217,7 @@ static int CmdFlashMemLoad(const char *Cmd) { } if (datalen > FLASH_MEM_MAX_SIZE) { - PrintAndLogDevice(ERR, "error, filesize is larger than available memory"); + PrintAndLogEx(ERR, "error, filesize is larger than available memory"); free(data); return PM3_EOVFLOW; } @@ -310,7 +318,7 @@ static int CmdFlashMemDump(const char *Cmd) { uint8_t *dump = calloc(len, sizeof(uint8_t)); if (!dump) { - PrintAndLogDevice(ERR, "error, cannot allocate memory "); + PrintAndLogEx(ERR, "error, cannot allocate memory "); return PM3_EMALLOC; } diff --git a/client/cmdflashmem.h b/client/cmdflashmem.h index b08164837d..011b57a145 100644 --- a/client/cmdflashmem.h +++ b/client/cmdflashmem.h @@ -11,20 +11,7 @@ #ifndef CMDFLASHMEM_H__ #define CMDFLASHMEM_H__ -#include -#include -#include -#include -#include "pmflash.h" #include "common.h" -#include "proxmark3.h" -#include "ui.h" -#include "cmdparser.h" -#include "util.h" -#include "util_posix.h" // msclock -#include "loclass/fileutils.h" //saveFile -#include "comms.h" //getfromdevice -#include "cmdflashmemspiffs.h" // spiffs commands typedef enum { DICTIONARY_NONE = 0, diff --git a/client/cmdflashmemspiffs.c b/client/cmdflashmemspiffs.c index bc7a408bd6..a3f9b950ac 100644 --- a/client/cmdflashmemspiffs.c +++ b/client/cmdflashmemspiffs.c @@ -9,9 +9,12 @@ //----------------------------------------------------------------------------- #include "cmdflashmemspiffs.h" -#include "mbedtls/base64.h" -#include "mbedtls/rsa.h" -#include "mbedtls/sha1.h" +#include + +#include "cmdparser.h" // command_t +#include "pmflash.h" +#include "loclass/fileutils.h" //saveFile +#include "comms.h" //getfromdevice static int CmdHelp(const char *Cmd); @@ -278,7 +281,7 @@ static int CmdFlashMemSpiFFSDump(const char *Cmd) { uint8_t *dump = calloc(len, sizeof(uint8_t)); if (!dump) { - PrintAndLogDevice(ERR, "error, cannot allocate memory "); + PrintAndLogEx(ERR, "error, cannot allocate memory "); return PM3_EMALLOC; } @@ -358,7 +361,7 @@ static int CmdFlashMemSpiFFSLoad(const char *Cmd) { } if (datalen > FLASH_MEM_MAX_SIZE) { - PrintAndLogDevice(ERR, "error, filesize is larger than available memory"); + PrintAndLogEx(ERR, "error, filesize is larger than available memory"); free(data); return PM3_EOVFLOW; } diff --git a/client/cmdflashmemspiffs.h b/client/cmdflashmemspiffs.h index b3589ce860..d2dee17ab0 100644 --- a/client/cmdflashmemspiffs.h +++ b/client/cmdflashmemspiffs.h @@ -11,19 +11,7 @@ #ifndef CMDFLASHMEMSPIFFS_H__ #define CMDFLASHMEMSPIFFS_H__ -#include -#include -#include -#include -#include "pmflash.h" #include "common.h" -#include "proxmark3.h" -#include "ui.h" -#include "cmdparser.h" -#include "util.h" -#include "util_posix.h" // msclock -#include "loclass/fileutils.h" //saveFile -#include "comms.h" //getfromdevice int CmdFlashMemSpiFFS(const char *Cmd); diff --git a/client/cmdhf.c b/client/cmdhf.c index 931737f1c0..7af98e46f0 100644 --- a/client/cmdhf.c +++ b/client/cmdhf.c @@ -8,7 +8,29 @@ //----------------------------------------------------------------------------- // High frequency commands //----------------------------------------------------------------------------- -#include "cmdhf.h" +//#include "cmdhf.h" + +#include // tolower + +#include "cmdparser.h" // command_t +#include "comms.h" // clearCommandBuffer + +#include "cmdhf14a.h" // ISO14443-A +#include "cmdhf14b.h" // ISO14443-B +#include "cmdhf15.h" // ISO15693 +#include "cmdhfepa.h" +#include "cmdhflegic.h" // LEGIC +#include "cmdhficlass.h" // ICLASS +#include "cmdhfmf.h" // CLASSIC +#include "cmdhfmfu.h" // ULTRALIGHT/NTAG etc +#include "cmdhfmfp.h" // Mifare Plus +#include "cmdhfmfdes.h" // DESFIRE +#include "cmdhftopaz.h" // TOPAZ +#include "cmdhffelica.h" // ISO18092 / FeliCa +#include "cmdhffido.h" // FIDO authenticators +#include "cmdhfthinfilm.h" // Thinfilm +#include "cmdtrace.h" // trace list +#include "ui.h" static int CmdHelp(const char *Cmd); @@ -101,15 +123,15 @@ int CmdHFSearch(const char *Cmd) { } } - /* - if (IfPm3Felica()) { - ans = CmdHFFelicaReader("s"); - if (ans) { - PrintAndLogEx(NORMAL, "\nValid " _GREEN_("ISO18092 / FeliCa tag") " found\n"); - return ans; - } - } - */ + + //if (IfPm3Felica()) { + // ans = CmdHFFelicaReader("s"); + // if (ans) { + // PrintAndLogEx(NORMAL, "\nValid " _GREEN_("ISO18092 / FeliCa tag") " found\n"); + // return ans; + // } + //} + PrintAndLogEx(FAILED, "\nno known/supported 13.56 MHz tags found\n"); return PM3_ESOFT; diff --git a/client/cmdhf.h b/client/cmdhf.h index cd0ae5db54..14ded8e0ea 100644 --- a/client/cmdhf.h +++ b/client/cmdhf.h @@ -11,28 +11,7 @@ #ifndef CMDHF_H__ #define CMDHF_H__ -#include -#include -#include -#include "proxmark3.h" -#include "graph.h" -#include "ui.h" -#include "cmdparser.h" -#include "cmdhf14a.h" // ISO14443-A -#include "cmdhf14b.h" // ISO14443-B -#include "cmdhf15.h" // ISO15693 -#include "cmdhfepa.h" -#include "cmdhflegic.h" // LEGIC -#include "cmdhficlass.h" // ICLASS -#include "cmdhfmf.h" // CLASSIC -#include "cmdhfmfu.h" // ULTRALIGHT/NTAG etc -#include "cmdhfmfp.h" // Mifare Plus -#include "cmdhfmfdes.h" // DESFIRE -#include "cmdhftopaz.h" // TOPAZ -#include "cmdhffelica.h" // ISO18092 / FeliCa -#include "cmdhffido.h" // FIDO authenticators -#include "cmdhfthinfilm.h" // Thinfilm -#include "cmdtrace.h" // trace list +#include "common.h" int CmdHF(const char *Cmd); int CmdHFTune(const char *Cmd); diff --git a/client/cmdhf14a.c b/client/cmdhf14a.c index 3fbf022fd7..8aea8db6c3 100644 --- a/client/cmdhf14a.c +++ b/client/cmdhf14a.c @@ -12,6 +12,21 @@ //----------------------------------------------------------------------------- #include "cmdhf14a.h" +#include +#include + +#include "cmdparser.h" // command_t +#include "commonutil.h" // ARRAYLEN +#include "comms.h" // clearCommandBuffer +#include "cmdtrace.h" +#include "cliparser/cliparser.h" +#include "cmdhfmf.h" +#include "cmdhfmfu.h" +#include "emv/emvcore.h" +#include "ui.h" +#include "crc16.h" +#include "util_posix.h" // msclock + bool APDUInFramingEnable = true; static int CmdHelp(const char *Cmd); diff --git a/client/cmdhf14a.h b/client/cmdhf14a.h index d5626d9958..9c42b9afd0 100644 --- a/client/cmdhf14a.h +++ b/client/cmdhf14a.h @@ -12,25 +12,9 @@ #ifndef CMDHF14A_H__ #define CMDHF14A_H__ -#include -#include -#include -#include -#include -#include -#include "proxmark3.h" #include "common.h" -#include "ui.h" -#include "util.h" -#include "cmdparser.h" -#include "cmdmain.h" -#include "mifare.h" -#include "cmdhfmf.h" -#include "cmdhfmfu.h" -#include "cmdhf.h" // list cmd -#include "mifare/mifarehost.h" -#include "emv/apduinfo.h" -#include "emv/emvcore.h" + +#include "mifare.h" // structs // structure and database for uid -> tagtype lookups typedef struct { diff --git a/client/cmdhf14b.c b/client/cmdhf14b.c index b02fe4d2fb..c5a6288359 100644 --- a/client/cmdhf14b.c +++ b/client/cmdhf14b.c @@ -11,6 +11,17 @@ #include "cmdhf14b.h" +#include +#include "loclass/fileutils.h" + +#include "cmdparser.h" // command_t +#include "comms.h" // clearCommandBuffer +#include "cmdtrace.h" + +#include "crc16.h" +#include "cmdhf14a.h" +#include "protocols.h" // definitions of ISO14B protocol + #define TIMEOUT 2000 static int CmdHelp(const char *Cmd); diff --git a/client/cmdhf14b.h b/client/cmdhf14b.h index 2180e2088f..2058ea8ba2 100644 --- a/client/cmdhf14b.h +++ b/client/cmdhf14b.h @@ -11,23 +11,7 @@ #ifndef CMDHF14B_H__ #define CMDHF14B_H__ -#include -#include -#include -#include -#include "crc16.h" -#include "proxmark3.h" -#include "graph.h" -#include "util.h" -#include "ui.h" -#include "cmdparser.h" -#include "cmdmain.h" -#include "cmdhf14a.h" -#include "cmdhf.h" -#include "prng.h" -#include "mbedtls/sha1.h" -#include "mifare.h" // structs/enum for ISO14B -#include "protocols.h" // definitions of ISO14B protocol +#include "common.h" int CmdHF14B(const char *Cmd); diff --git a/client/cmdhf15.c b/client/cmdhf15.c index f43b6d85cb..2c788087e1 100644 --- a/client/cmdhf15.c +++ b/client/cmdhf15.c @@ -24,6 +24,19 @@ // variant, but offers the possibility to analyze the waveforms directly. #include "cmdhf15.h" +#include + +#include "cmdparser.h" // command_t +#include "commonutil.h" // ARRAYLEN +#include "comms.h" // clearCommandBuffer +#include "cmdtrace.h" +#include "iso15693tools.h" + +#include "graph.h" +#include "crc16.h" // iso15 crc +#include "cmddata.h" // getsamples +#include "loclass/fileutils.h" // savefileEML + #define FrameSOF Iso15693FrameSOF #define Logic0 Iso15693Logic0 #define Logic1 Iso15693Logic1 diff --git a/client/cmdhf15.h b/client/cmdhf15.h index 049e9f68f8..b3f64ac70e 100644 --- a/client/cmdhf15.h +++ b/client/cmdhf15.h @@ -11,20 +11,7 @@ #ifndef CMDHF15_H__ #define CMDHF15_H__ -#include -#include -#include -#include - -#include "proxmark3.h" -#include "graph.h" -#include "ui.h" -#include "util.h" -#include "cmdparser.h" -#include "crc16.h" // iso15 crc -#include "cmdmain.h" -#include "cmddata.h" // getsamples -#include "loclass/fileutils.h" // savefileEML +#include "common.h" int CmdHF15(const char *Cmd); diff --git a/client/cmdhfepa.c b/client/cmdhfepa.c index 3370c05c93..b6329bef96 100644 --- a/client/cmdhfepa.c +++ b/client/cmdhfepa.c @@ -9,6 +9,18 @@ //----------------------------------------------------------------------------- #include "cmdhfepa.h" +#include +#include +#include +#include +#include + +#include "cmdparser.h" // command_t +#include "commonutil.h" // ARRAYLEN +#include "comms.h" // clearCommandBuffer +#include "ui.h" +#include "util_posix.h" + static int CmdHelp(const char *Cmd); // Perform (part of) the PACE protocol diff --git a/client/cmdhfepa.h b/client/cmdhfepa.h index c08fa8ea06..da21630cd5 100644 --- a/client/cmdhfepa.h +++ b/client/cmdhfepa.h @@ -11,19 +11,7 @@ #ifndef CMDHFEPA_H__ #define CMDHFEPA_H__ -#include -#include -#include -#include -#include -#include "util.h" -#include "proxmark3.h" #include "common.h" -#include "ui.h" -#include "cmdparser.h" -#include "cmdmain.h" -#include "util_posix.h" - int CmdHFEPA(const char *Cmd); diff --git a/client/cmdhffelica.c b/client/cmdhffelica.c index e873daaaf0..c3681bf604 100644 --- a/client/cmdhffelica.c +++ b/client/cmdhffelica.c @@ -9,6 +9,19 @@ //----------------------------------------------------------------------------- #include "cmdhffelica.h" +#include +#include +#include +#include + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "cmdtrace.h" +#include "crc16.h" + +#include "ui.h" +#include "mifare.h" // felica_card_select_t struct + static int CmdHelp(const char *Cmd); /* diff --git a/client/cmdhffelica.h b/client/cmdhffelica.h index b495b80ec9..4193235f50 100644 --- a/client/cmdhffelica.h +++ b/client/cmdhffelica.h @@ -11,19 +11,7 @@ #ifndef CMDHFFELICA_H__ #define CMDHFFELICA_H__ -#include -#include -#include -#include -#include -#include "proxmark3.h" #include "common.h" -#include "ui.h" -#include "util.h" -#include "cmdparser.h" -#include "comms.h" // getfromdevice -#include "cmdhf.h" // list cmd -#include "mifare.h" // felica_card_select_t struct int CmdHFFelica(const char *Cmd); diff --git a/client/cmdhffido.c b/client/cmdhffido.c index 37f80d8e5d..e9b3376a9e 100644 --- a/client/cmdhffido.c +++ b/client/cmdhffido.c @@ -21,31 +21,23 @@ #include "cmdhffido.h" -#include -#include -#include -#include -#include #include -#include -#include -#include -#include + +#include "cmdparser.h" // command_t +#include "commonutil.h" + #include "comms.h" -#include "cmdmain.h" -#include "util.h" -#include "ui.h" #include "proxmark3.h" -#include "mifare.h" #include "emv/emvcore.h" #include "emv/emvjson.h" -#include "emv/dump.h" #include "cliparser/cliparser.h" #include "crypto/asn1utils.h" #include "crypto/libpcrypto.h" #include "fido/cbortools.h" #include "fido/fidocore.h" -#include "fido/cose.h" +#include "emv/dump.h" +#include "ui.h" +#include "cmdhf14a.h" static int CmdHelp(const char *Cmd); diff --git a/client/cmdhffido.h b/client/cmdhffido.h index b54f53118b..9aca8ecc84 100644 --- a/client/cmdhffido.h +++ b/client/cmdhffido.h @@ -21,7 +21,8 @@ #ifndef CMDHFFIDO_H__ #define CMDHFFIDO_H__ -int CmdHFFido(const char *Cmd); +#include "common.h" +int CmdHFFido(const char *Cmd); #endif diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 1f8aef9a58..f58d5377c9 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -13,6 +13,23 @@ #include "cmdhficlass.h" +#include + +#include "cmdparser.h" // command_t +#include "commonutil.h" // ARRAYLEN +#include "cmdtrace.h" +#include "util_posix.h" + +#include "comms.h" +#include "mbedtls/des.h" +#include "loclass/cipherutils.h" +#include "loclass/cipher.h" +#include "loclass/ikeys.h" +#include "loclass/elite_crack.h" +#include "loclass/fileutils.h" +#include "protocols.h" + + #define NUM_CSNS 9 #define ICLASS_KEYS_MAX 8 @@ -271,6 +288,145 @@ static int xorbits_8(uint8_t val) { return res & 1; } */ + +// iclass / picopass chip config structures and shared routines +typedef struct { + uint8_t app_limit; //[8] + uint8_t otp[2]; //[9-10] + uint8_t block_writelock;//[11] + uint8_t chip_config; //[12] + uint8_t mem_config; //[13] + uint8_t eas; //[14] + uint8_t fuses; //[15] +} picopass_conf_block; + + +typedef struct { + uint8_t csn[8]; + picopass_conf_block conf; + uint8_t epurse[8]; + uint8_t key_d[8]; + uint8_t key_c[8]; + uint8_t app_issuer_area[8]; +} picopass_hdr; + +static uint8_t isset(uint8_t val, uint8_t mask) { + return (val & mask); +} + +static uint8_t notset(uint8_t val, uint8_t mask) { + return !(val & mask); +} + +static void fuse_config(const picopass_hdr *hdr) { + uint8_t fuses = hdr->conf.fuses; + + if (isset(fuses, FUSE_FPERS)) + PrintAndLogEx(SUCCESS, "\tMode: Personalization [Programmable]"); + else + PrintAndLogEx(NORMAL, "\tMode: Application [Locked]"); + + if (isset(fuses, FUSE_CODING1)) { + PrintAndLogEx(NORMAL, "\tCoding: RFU"); + } else { + if (isset(fuses, FUSE_CODING0)) + PrintAndLogEx(NORMAL, "\tCoding: ISO 14443-2 B/ISO 15693"); + else + PrintAndLogEx(NORMAL, "\tCoding: ISO 14443B only"); + } + // 1 1 + if (isset(fuses, FUSE_CRYPT1) && isset(fuses, FUSE_CRYPT0)) PrintAndLogEx(SUCCESS, "\tCrypt: Secured page, keys not locked"); + // 1 0 + if (isset(fuses, FUSE_CRYPT1) && notset(fuses, FUSE_CRYPT0)) PrintAndLogEx(NORMAL, "\tCrypt: Secured page, keys locked"); + // 0 1 + if (notset(fuses, FUSE_CRYPT1) && isset(fuses, FUSE_CRYPT0)) PrintAndLogEx(SUCCESS, "\tCrypt: Non secured page"); + // 0 0 + if (notset(fuses, FUSE_CRYPT1) && notset(fuses, FUSE_CRYPT0)) PrintAndLogEx(NORMAL, "\tCrypt: No auth possible. Read only if RA is enabled"); + + if (isset(fuses, FUSE_RA)) + PrintAndLogEx(NORMAL, "\tRA: Read access enabled"); + else + PrintAndLogEx(WARNING, "\tRA: Read access not enabled"); +} + +static void getMemConfig(uint8_t mem_cfg, uint8_t chip_cfg, uint8_t *max_blk, uint8_t *app_areas, uint8_t *kb) { + // mem-bit 5, mem-bit 7, chip-bit 4: defines chip type + uint8_t k16 = isset(mem_cfg, 0x80); + //uint8_t k2 = isset(mem_cfg, 0x08); + uint8_t book = isset(mem_cfg, 0x20); + + if (isset(chip_cfg, 0x10) && !k16 && !book) { + *kb = 2; + *app_areas = 2; + *max_blk = 31; + } else if (isset(chip_cfg, 0x10) && k16 && !book) { + *kb = 16; + *app_areas = 2; + *max_blk = 255; //16kb + } else if (notset(chip_cfg, 0x10) && !k16 && !book) { + *kb = 16; + *app_areas = 16; + *max_blk = 255; //16kb + } else if (isset(chip_cfg, 0x10) && k16 && book) { + *kb = 32; + *app_areas = 3; + *max_blk = 255; //16kb + } else if (notset(chip_cfg, 0x10) && !k16 && book) { + *kb = 32; + *app_areas = 17; + *max_blk = 255; //16kb + } else { + *kb = 32; + *app_areas = 2; + *max_blk = 255; + } +} + +static void mem_app_config(const picopass_hdr *hdr) { + uint8_t mem = hdr->conf.mem_config; + uint8_t chip = hdr->conf.chip_config; + uint8_t applimit = hdr->conf.app_limit; + uint8_t kb = 2; + uint8_t app_areas = 2; + uint8_t max_blk = 31; + + getMemConfig(mem, chip, &max_blk, &app_areas, &kb); + + if (applimit < 6) applimit = 26; + if (kb == 2 && (applimit > 0x1f)) applimit = 26; + + PrintAndLogEx(NORMAL, " Mem: %u KBits/%u App Areas (%u * 8 bytes) [%02X]", kb, app_areas, max_blk, mem); + PrintAndLogEx(NORMAL, "\tAA1: blocks 06-%02X", applimit); + PrintAndLogEx(NORMAL, "\tAA2: blocks %02X-%02X", applimit + 1, max_blk); + PrintAndLogEx(NORMAL, "\tOTP: 0x%02X%02X", hdr->conf.otp[1], hdr->conf.otp[0]); + PrintAndLogEx(NORMAL, "\nKeyAccess:"); + + uint8_t book = isset(mem, 0x20); + if (book) { + PrintAndLogEx(NORMAL, "\tRead A - Kd"); + PrintAndLogEx(NORMAL, "\tRead B - Kc"); + PrintAndLogEx(NORMAL, "\tWrite A - Kd"); + PrintAndLogEx(NORMAL, "\tWrite B - Kc"); + PrintAndLogEx(NORMAL, "\tDebit - Kd or Kc"); + PrintAndLogEx(NORMAL, "\tCredit - Kc"); + } else { + PrintAndLogEx(NORMAL, "\tRead A - Kd or Kc"); + PrintAndLogEx(NORMAL, "\tRead B - Kd or Kc"); + PrintAndLogEx(NORMAL, "\tWrite A - Kc"); + PrintAndLogEx(NORMAL, "\tWrite B - Kc"); + PrintAndLogEx(NORMAL, "\tDebit - Kd or Kc"); + PrintAndLogEx(NORMAL, "\tCredit - Kc"); + } +} +static void print_picopass_info(const picopass_hdr *hdr) { + fuse_config(hdr); + mem_app_config(hdr); +} +static void printIclassDumpInfo(uint8_t *iclass_dump) { + print_picopass_info((picopass_hdr *) iclass_dump); +} + + static int CmdHFiClassList(const char *Cmd) { (void)Cmd; // Cmd is not used so far //PrintAndLogEx(NORMAL, "Deprecated command, use 'hf list iclass' instead"); @@ -550,14 +706,14 @@ static int CmdHFiClassELoad(const char *Cmd) { fseek(f, 0, SEEK_SET); if (fsize <= 0) { - PrintAndLogDevice(ERR, "error, when getting filesize"); + PrintAndLogEx(ERR, "error, when getting filesize"); fclose(f); return 1; } uint8_t *dump = calloc(fsize, sizeof(uint8_t)); if (!dump) { - PrintAndLogDevice(ERR, "error, cannot allocate memory "); + PrintAndLogEx(ERR, "error, cannot allocate memory "); fclose(f); return 1; } @@ -569,7 +725,7 @@ static int CmdHFiClassELoad(const char *Cmd) { //Validate if (bytes_read < fsize) { - PrintAndLogDevice(ERR, "error, could only read %d bytes (should be %d)", bytes_read, fsize); + PrintAndLogEx(ERR, "error, could only read %d bytes (should be %d)", bytes_read, fsize); free(dump); return 1; } @@ -1449,7 +1605,7 @@ static int CmdHFiClass_loclass(const char *Cmd) { errors += testMAC(); errors += doKeyTests(0); errors += testElite(); - if (errors) PrintAndLogDevice(ERR, "There were errors!!!"); + if (errors) PrintAndLogEx(ERR, "There were errors!!!"); return errors; } return PM3_SUCCESS; diff --git a/client/cmdhficlass.h b/client/cmdhficlass.h index aa29fae1e8..9f2b5caacb 100644 --- a/client/cmdhficlass.h +++ b/client/cmdhficlass.h @@ -11,31 +11,7 @@ #ifndef CMDHFICLASS_H__ #define CMDHFICLASS_H__ -#include -#include -#include -#include -//#include "iso14443crc.h" // Can also be used for iClass, using 0xE012 as CRC-type -#include "proxmark3.h" -#include "ui.h" -#include "cmdparser.h" #include "common.h" -#include "util.h" -#include "comms.h" -#include "mbedtls/des.h" -#include "loclass/cipherutils.h" -#include "loclass/cipher.h" -#include "loclass/ikeys.h" -#include "loclass/elite_crack.h" -#include "loclass/fileutils.h" -#include "protocols.h" -#include "pm3_cmd.h" -#include "cmdhfmfu.h" -#include "cmdhf.h" -#include "protocols.h" // picopass structs, -#include "usb_cdc.h" // for usb_poll_validate_length - - typedef struct iclass_block { uint8_t d[8]; diff --git a/client/cmdhflegic.c b/client/cmdhflegic.c index 20fba3781a..af56807b16 100644 --- a/client/cmdhflegic.c +++ b/client/cmdhflegic.c @@ -9,6 +9,16 @@ //----------------------------------------------------------------------------- #include "cmdhflegic.h" +#include // for Mingw readline +#include + +#include "cmdparser.h" // command_t +#include "comms.h" // clearCommandBuffer +#include "cmdtrace.h" +#include "crc.h" +#include "crc16.h" +#include "loclass/fileutils.h" //saveFile + static int CmdHelp(const char *Cmd); #define MAX_LENGTH 1024 diff --git a/client/cmdhflegic.h b/client/cmdhflegic.h index b922420eca..9e9411a333 100644 --- a/client/cmdhflegic.h +++ b/client/cmdhflegic.h @@ -11,18 +11,9 @@ #ifndef CMDHFLEGIC_H__ #define CMDHFLEGIC_H__ -#include -#include -#include "proxmark3.h" -#include "ui.h" -#include "cmdparser.h" -#include "comms.h" -#include "util.h" -#include "crc.h" -#include "legic_prng.h" -#include "legic.h" // legic_card_select_t struct -#include "cmdhf.h" // "hf list" -#include "loclass/fileutils.h" //saveFile +#include "common.h" + +#include "legic.h" // struct int CmdHFLegic(const char *Cmd); diff --git a/client/cmdhflist.c b/client/cmdhflist.c index d583dedbb5..5a2ff5248f 100644 --- a/client/cmdhflist.c +++ b/client/cmdhflist.c @@ -11,6 +11,19 @@ #include "cmdhflist.h" +#include +#include +#include + +#include "commonutil.h" // ARRAYLEN +#include "mifare/mifarehost.h" +#include "mifare/mifaredefault.h" +#include "parity.h" // oddparity +#include "ui.h" +#include "crc16.h" +#include "crapto1/crapto1.h" +#include "protocols.h" + enum MifareAuthSeq { masNone, masNt, diff --git a/client/cmdhflist.h b/client/cmdhflist.h index ddc0ab00cc..0dda4ea17d 100644 --- a/client/cmdhflist.h +++ b/client/cmdhflist.h @@ -10,32 +10,7 @@ #ifndef CMDHFLIST_H #define CMDHFLIST_H -#include -#include -#include -#include -#include -#include "util.h" -#include "ui.h" -#include "cmdhf14a.h" // ISO14443-A -#include "cmdhf14b.h" // ISO14443-B -#include "cmdhf15.h" // ISO15693 -#include "cmdhfepa.h" -#include "cmdhflegic.h" // LEGIC -#include "cmdhficlass.h" // ICLASS -#include "cmdhfmf.h" // CLASSIC -#include "cmdhfmfu.h" // ULTRALIGHT/NTAG etc -#include "cmdhfmfdes.h" // DESFIRE -#include "cmdhftopaz.h" // TOPAZ -#include "cmdhffelica.h" // ISO18092 / FeliCa -#include "emv/cmdemv.h" // EMV -#include "protocols.h" -#include "crapto1/crapto1.h" -#include "mifare/mifarehost.h" -#include "mifare/mifaredefault.h" -#include "parity.h" // oddparity -#include "iso15693tools.h" // ISO15693 crc - +#include "common.h" typedef struct { uint32_t uid; // UID diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 16b6b9d491..affc536038 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -9,10 +9,22 @@ //----------------------------------------------------------------------------- #include "cmdhfmf.h" -#include "mifare/mifare4.h" + +#include + +#include "cmdparser.h" // command_t +#include "commonutil.h" // ARRAYLEN +#include "comms.h" // clearCommandBuffer +#include "loclass/fileutils.h" +#include "cmdtrace.h" +#include "emv/dump.h" +#include "mifare/mifaredefault.h" // mifare default key array +#include "cliparser/cliparser.h" // argtable +#include "hardnested/hardnested_bf_core.h" // SetSIMDInstr #include "mifare/mad.h" #include "mifare/ndef.h" - +#include "protocols.h" +#include "util_posix.h" // msclock #define MFBLOCK_SIZE 16 diff --git a/client/cmdhfmf.h b/client/cmdhfmf.h index 8b7e68a40b..55997bd875 100644 --- a/client/cmdhfmf.h +++ b/client/cmdhfmf.h @@ -11,26 +11,9 @@ #ifndef CMDHFMF_H__ #define CMDHFMF_H__ -#include -#include -#include -#include -#include -#include -#include "proxmark3.h" -#include "ui.h" -#include "cmdparser.h" #include "common.h" -#include "util.h" -#include "mifare.h" // nonces_t struct -#include "mifare/mfkey.h" // mfkey32_moebious -#include "cmdhfmfhard.h" -#include "mifare/mifarehost.h" // icesector_t, sector_t -#include "util_posix.h" // msclock -#include "mifare/mifaredefault.h" // mifare default key array -#include "cmdhf14a.h" // dropfield -#include "cliparser/cliparser.h" // argtable -#include "hardnested/hardnested_bf_core.h" // SetSIMDInstr +#include "mifare/mfkey.h" +#include "mifare/mifarehost.h" // struct int CmdHFMF(const char *Cmd); int CmdHF14AMfELoad(const char *Cmd); // used by cmd hf mfu eload diff --git a/client/cmdhfmfdes.c b/client/cmdhfmfdes.c index c5a54735ad..f46384d120 100644 --- a/client/cmdhfmfdes.c +++ b/client/cmdhfmfdes.c @@ -9,6 +9,15 @@ //----------------------------------------------------------------------------- #include "cmdhfmfdes.h" +#include +#include + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "ui.h" +#include "cmdhf14a.h" +#include "mbedtls/des.h" + uint8_t key_zero_data[16] = { 0x00 }; uint8_t key_ones_data[16] = { 0x01 }; uint8_t key_defa_data[16] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; diff --git a/client/cmdhfmfdes.h b/client/cmdhfmfdes.h index 70e61e7572..3a19f6d830 100644 --- a/client/cmdhfmfdes.h +++ b/client/cmdhfmfdes.h @@ -10,19 +10,7 @@ #ifndef __MFDESFIRE_H #define __MFDESFIRE_H -#include -#include -#include -#include -#include "cmdmain.h" -#include "proxmark3.h" -#include "../include/common.h" -#include "../include/mifare.h" -#include "ui.h" -#include "cmdparser.h" -#include "util.h" -#include "cmdhf14a.h" -#include "mbedtls/des.h" +#include "common.h" int CmdHFMFDes(const char *Cmd); diff --git a/client/cmdhfmfdesfire.c b/client/cmdhfmfdesfire_disabled.c similarity index 98% rename from client/cmdhfmfdesfire.c rename to client/cmdhfmfdesfire_disabled.c index d09a56eeac..fc123667b0 100644 --- a/client/cmdhfmfdesfire.c +++ b/client/cmdhfmfdesfire_disabled.c @@ -10,6 +10,13 @@ #include "cmdhfmfdesfire.h" +#include "cmdparser.h" // command_t + +#include "cmdhfmf.h" +#include "util.h" +#include "mbedtls/des.h" +#include "mbedtls/aes.h" + static int CmdHelp(const char *Cmd); //DESFIRE diff --git a/client/cmdhfmfdesfire.h b/client/cmdhfmfdesfire_disabled.h similarity index 52% rename from client/cmdhfmfdesfire.h rename to client/cmdhfmfdesfire_disabled.h index bfa653dc3d..1583bc395c 100644 --- a/client/cmdhfmfdesfire.h +++ b/client/cmdhfmfdesfire_disabled.h @@ -1,10 +1,7 @@ #ifndef __MFDESFIRE_AD_H #define __MFDESFIRE_AD_H -#include "cmdhfmf.h" -#include "util.h" -#include "mbedtls/des.h" -#include "mbedtls/aes.h" +#include "common.h" int CmdHFMFDesfire(const char *Cmd); diff --git a/client/cmdhfmfhard.c b/client/cmdhfmfhard.c index a944f11abd..d66df7eae1 100644 --- a/client/cmdhfmfhard.c +++ b/client/cmdhfmfhard.c @@ -21,18 +21,18 @@ #include #include #include -#include -#include #include #include +#include // MingW + +#include "commonutil.h" // ARRAYLEN +#include "comms.h" + #include "proxmark3.h" -#include "cmdmain.h" #include "ui.h" -#include "util.h" #include "util_posix.h" #include "crapto1/crapto1.h" #include "parity.h" -#include "hardnested/hardnested_bruteforce.h" #include "hardnested/hardnested_bf_core.h" #include "hardnested/hardnested_bitarray_core.h" #include "zlib.h" diff --git a/client/cmdhfmfhard.h b/client/cmdhfmfhard.h index 2f20986e2c..d86a2005ae 100644 --- a/client/cmdhfmfhard.h +++ b/client/cmdhfmfhard.h @@ -11,8 +11,7 @@ #ifndef CMDHFMFHARD_H__ #define CMDHFMFHARD_H__ -#include -#include +#include "common.h" #define NUM_SUMS 19 // number of possible sum property values diff --git a/client/cmdhfmfp.c b/client/cmdhfmfp.c index e9dd245b67..8c7cfcc5c6 100644 --- a/client/cmdhfmfp.c +++ b/client/cmdhfmfp.c @@ -11,23 +11,20 @@ #include "cmdhfmfp.h" -#include #include -#include -#include -#include + +#include "cmdparser.h" // command_t +#include "commonutil.h" // ARRAYLEN + #include "comms.h" -#include "cmdmain.h" -#include "util.h" #include "ui.h" #include "cmdhf14a.h" -#include "mifare.h" #include "mifare/mifare4.h" #include "mifare/mad.h" #include "mifare/ndef.h" #include "cliparser/cliparser.h" -#include "crypto/libpcrypto.h" #include "emv/dump.h" +#include "mifare/mifaredefault.h" static const uint8_t DefaultKey[16] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; diff --git a/client/cmdhfmfp.h b/client/cmdhfmfp.h index 76917315b5..6ba2af5044 100644 --- a/client/cmdhfmfp.h +++ b/client/cmdhfmfp.h @@ -10,7 +10,7 @@ #ifndef CMDHFMFP_H__ #define CMDHFMFP_H__ -#include "mifare/mifaredefault.h" +#include "common.h" int CmdHFMFP(const char *Cmd); diff --git a/client/cmdhfmfu.c b/client/cmdhfmfu.c index 7367dfd668..e2c64a004d 100644 --- a/client/cmdhfmfu.c +++ b/client/cmdhfmfu.c @@ -9,6 +9,18 @@ //----------------------------------------------------------------------------- #include "cmdhfmfu.h" +#include + +#include "cmdparser.h" +#include "commonutil.h" +#include "crypto/libpcrypto.h" +#include "mbedtls/des.h" +#include "cmdhfmf.h" +#include "cmdhf14a.h" +#include "comms.h" +#include "loclass/fileutils.h" +#include "protocols.h" + #define MAX_UL_BLOCKS 0x0F #define MAX_ULC_BLOCKS 0x2B #define MAX_ULEV1a_BLOCKS 0x13 diff --git a/client/cmdhfmfu.h b/client/cmdhfmfu.h index 6587cd5380..85f6a8475b 100644 --- a/client/cmdhfmfu.h +++ b/client/cmdhfmfu.h @@ -1,17 +1,9 @@ #ifndef CMDHFMFU_H__ #define CMDHFMFU_H__ -#include -#include -#include "mbedtls/des.h" -#include "cmdhfmf.h" -#include "cmdhf14a.h" -#include "mifare.h" -#include "util.h" -#include "protocols.h" -#include "comms.h" -#include "loclass/fileutils.h" +#include "common.h" +#include "mifare.h" // structs // Old Ultralight/NTAG dump file format // It is used only for converting diff --git a/client/cmdhfthinfilm.c b/client/cmdhfthinfilm.c index 454641bd8a..2e9ab7a85d 100644 --- a/client/cmdhfthinfilm.c +++ b/client/cmdhfthinfilm.c @@ -9,6 +9,17 @@ //----------------------------------------------------------------------------- #include "cmdhfthinfilm.h" +#include +#include +#include + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "cmdtrace.h" +#include "crc16.h" +#include "ui.h" +#include "cmdhf14a.h" // manufacture + static int CmdHelp(const char *Cmd); static int usage_thinfilm_info(void) { diff --git a/client/cmdhfthinfilm.h b/client/cmdhfthinfilm.h index ed2b0dd891..ce7534759b 100644 --- a/client/cmdhfthinfilm.h +++ b/client/cmdhfthinfilm.h @@ -11,16 +11,7 @@ #ifndef CMDHFTHINFILM_H__ #define CMDHFTHINFILM_H__ -#include -#include -#include #include "common.h" -#include "proxmark3.h" -#include "ui.h" -#include "cmdparser.h" -#include "util.h" -#include "cmdhf.h" // list cmd -#include "cmdhf14a.h" // manufacture int infoThinFilm(bool verbose); diff --git a/client/cmdhftopaz.c b/client/cmdhftopaz.c index b7be9a7870..35b31d8cea 100644 --- a/client/cmdhftopaz.c +++ b/client/cmdhftopaz.c @@ -9,6 +9,20 @@ //----------------------------------------------------------------------------- #include "cmdhftopaz.h" +#include +#include +#include +#include + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "cmdtrace.h" + +#include "cmdhf14a.h" +#include "ui.h" +#include "crc16.h" +#include "protocols.h" + #define TOPAZ_STATIC_MEMORY (0x0f * 8) // 15 blocks with 8 Bytes each // a struct to describe a memory area which contains lock bits and the corresponding lockable memory area diff --git a/client/cmdhftopaz.h b/client/cmdhftopaz.h index ed0b37a08b..2cd2379b07 100644 --- a/client/cmdhftopaz.h +++ b/client/cmdhftopaz.h @@ -11,19 +11,7 @@ #ifndef CMDHFTOPAZ_H__ #define CMDHFTOPAZ_H__ -#include -#include -#include -#include -#include "cmdmain.h" -#include "cmdparser.h" -#include "cmdhf14a.h" -#include "ui.h" -#include "mifare.h" -#include "proxmark3.h" -#include "crc16.h" -#include "protocols.h" -#include "cmdhf.h" +#include "common.h" int CmdHFTopaz(const char *Cmd); diff --git a/client/cmdhw.c b/client/cmdhw.c index 0bfa583dc6..7fec7a40c8 100644 --- a/client/cmdhw.c +++ b/client/cmdhw.c @@ -12,12 +12,13 @@ #include #include #include -#include +#include + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "usart_defs.h" #include "ui.h" -#include "proxmark3.h" -#include "cmdparser.h" #include "cmdhw.h" -#include "cmdmain.h" #include "cmddata.h" static int CmdHelp(const char *Cmd); diff --git a/client/cmdhw.h b/client/cmdhw.h index a1a3a4b8fa..1a378e70ff 100644 --- a/client/cmdhw.h +++ b/client/cmdhw.h @@ -11,6 +11,8 @@ #ifndef CMDHW_H__ #define CMDHW_H__ +#include "common.h" + int CmdHW(const char *Cmd); void pm3_version(bool verbose); diff --git a/client/cmdlf.c b/client/cmdlf.c index 4831ede0f8..cf8e60f82d 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -9,6 +9,45 @@ //----------------------------------------------------------------------------- #include "cmdlf.h" +#include +#include +#include +#include +#include + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "commonutil.h" // ARRAYLEN + +#include "lfdemod.h" // device/client demods of LF signals +#include "ui.h" // for show graph controls +#include "graph.h" // for graph data +#include "cmddata.h" // for `lf search` +#include "cmdlfawid.h" // for awid menu +#include "cmdlfem4x.h" // for em4x menu +#include "cmdlfhid.h" // for hid menu +#include "cmdlfhitag.h" // for hitag menu +#include "cmdlfio.h" // for ioprox menu +#include "cmdlft55xx.h" // for t55xx menu +#include "cmdlfti.h" // for ti menu +#include "cmdlfpresco.h" // for presco menu +#include "cmdlfpcf7931.h" // for pcf7931 menu +#include "cmdlfpyramid.h" // for pyramid menu +#include "cmdlfviking.h" // for viking menu +#include "cmdlfnedap.h" // for NEDAP menu +#include "cmdlfjablotron.h" // for JABLOTRON menu +#include "cmdlfvisa2000.h" // for VISA2000 menu +#include "cmdlfnoralsy.h" // for NORALSY meny +#include "cmdlfcotag.h" // for COTAG meny +#include "cmdlfindala.h" // for indala menu +#include "cmdlfguard.h" // for gproxii menu +#include "cmdlffdx.h" // for fdx-b menu +#include "cmdlfparadox.h" // for paradox menu +#include "cmdlfnexwatch.h" // for nexwatch menu +#include "cmdlfsecurakey.h" // for securakey menu +#include "cmdlfpac.h" // for pac menu +#include "cmdlfkeri.h" // for keri menu + bool g_lf_threshold_set = false; static int CmdHelp(const char *Cmd); diff --git a/client/cmdlf.h b/client/cmdlf.h index 89299beaf2..8c90d2d423 100644 --- a/client/cmdlf.h +++ b/client/cmdlf.h @@ -10,46 +10,8 @@ #ifndef CMDLF_H__ #define CMDLF_H__ -#include -#include -#include -#include -#include -#include -#include "proxmark3.h" -#include "lfdemod.h" // device/client demods of LF signals -#include "util.h" // for parsing cli command utils -#include "ui.h" // for show graph controls -#include "graph.h" // for graph data -#include "cmdparser.h" // for getting cli commands included in cmdmain.h -#include "cmdmain.h" // for sending cmds to device. GetFromBigBuf -#include "cmddata.h" // for `lf search` -#include "cmdlfawid.h" // for awid menu -#include "cmdlfem4x.h" // for em4x menu -#include "cmdlfhid.h" // for hid menu -#include "cmdlfhitag.h" // for hitag menu -#include "cmdlfio.h" // for ioprox menu -#include "cmdlft55xx.h" // for t55xx menu -#include "cmdlfti.h" // for ti menu -#include "cmdlfpresco.h" // for presco menu -#include "cmdlfpcf7931.h" // for pcf7931 menu -#include "cmdlfpyramid.h" // for pyramid menu -#include "cmdlfviking.h" // for viking menu -#include "cmdlfguard.h" // for GuardAll menu -#include "cmdlfnedap.h" // for NEDAP menu -#include "cmdlfjablotron.h" // for JABLOTRON menu -#include "cmdlfvisa2000.h" // for VISA2000 menu -#include "cmdlfnoralsy.h" // for NORALSY meny -#include "cmdlffdx.h" // for FDX-B meny -#include "cmdlfcotag.h" // for COTAG meny -#include "cmdlfindala.h" // for indala menu -#include "cmdlfguard.h" // for gproxii menu -#include "cmdlffdx.h" // for fdx-b menu -#include "cmdlfparadox.h" // for paradox menu -#include "cmdlfnexwatch.h" // for nexwatch menu -#include "cmdlfsecurakey.h" // for securakey menu -#include "cmdlfpac.h" // for pac menu -#include "cmdlfkeri.h" // for keri menu + +#include "common.h" #define T55XX_WRITE_TIMEOUT 1500 diff --git a/client/cmdlfawid.c b/client/cmdlfawid.c index 09a73aca58..b574af7727 100644 --- a/client/cmdlfawid.c +++ b/client/cmdlfawid.c @@ -12,6 +12,21 @@ //----------------------------------------------------------------------------- #include "cmdlfawid.h" // AWID function declarations +#include +#include +#include + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "graph.h" +#include "cmddata.h" + +#include "ui.h" // PrintAndLog +#include "lfdemod.h" // parityTest +#include "cmdlf.h" // lf read +#include "protocols.h" // for T55xx config register definitions +#include "util_posix.h" + static int CmdHelp(const char *Cmd); /* static int usage_lf_awid_read(void) { diff --git a/client/cmdlfawid.h b/client/cmdlfawid.h index e51e986a62..80645e9b9a 100644 --- a/client/cmdlfawid.h +++ b/client/cmdlfawid.h @@ -11,18 +11,7 @@ #ifndef CMDLFAWID_H__ #define CMDLFAWID_H__ -#include // sscanf -#include // bool -#include "proxmark3.h" // Definitions, USB controls, etc -#include "ui.h" // PrintAndLog -#include "cmdparser.h" // CmdsParse, CmdsHelp -#include "lfdemod.h" // parityTest -#include "util.h" // weigandparity -#include "cmdlf.h" // lf read -#include "protocols.h" // for T55xx config register definitions -#include "cmdmain.h" -#include "util_posix.h" - +#include "common.h" int CmdLFAWID(const char *Cmd); diff --git a/client/cmdlfcotag.c b/client/cmdlfcotag.c index 338c0a6d68..96548fca95 100644 --- a/client/cmdlfcotag.c +++ b/client/cmdlfcotag.c @@ -9,6 +9,15 @@ //----------------------------------------------------------------------------- #include "cmdlfcotag.h" // COTAG function declarations +#include +#include + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "lfdemod.h" +#include "cmddata.h" // getSamples +#include "ui.h" // PrintAndLog + static int CmdHelp(const char *Cmd); static int usage_lf_cotag_read(void) { diff --git a/client/cmdlfcotag.h b/client/cmdlfcotag.h index e4b12235da..01c4daa034 100644 --- a/client/cmdlfcotag.h +++ b/client/cmdlfcotag.h @@ -11,13 +11,7 @@ #ifndef CMDLFCOTAG_H__ #define CMDLFCOTAG_H__ -#include "proxmark3.h" // Definitions, USB controls, COTAG_BITS -#include "util.h" // FALSE / TRUE -#include "cmddata.h" // getSamples -#include "cmdparser.h" // CmdsParse, CmdsHelp -#include "comms.h" -#include "ui.h" // PrintAndLog -#include "cmdlf.h" // Setconfig +#include "common.h" #ifndef COTAG_BITS #define COTAG_BITS 264 diff --git a/client/cmdlfem4x.c b/client/cmdlfem4x.c index 77c6531605..a87fd46ebc 100644 --- a/client/cmdlfem4x.c +++ b/client/cmdlfem4x.c @@ -10,6 +10,23 @@ #include "cmdlfem4x.h" +#include +#include +#include +#include +#include + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "commonutil.h" +#include "util_posix.h" +#include "protocols.h" +#include "ui.h" +#include "graph.h" +#include "cmddata.h" +#include "cmdlf.h" +#include "lfdemod.h" + uint64_t g_em410xid = 0; static int CmdHelp(const char *Cmd); diff --git a/client/cmdlfem4x.h b/client/cmdlfem4x.h index 12f27c2c7a..d727cb5511 100644 --- a/client/cmdlfem4x.h +++ b/client/cmdlfem4x.h @@ -11,19 +11,7 @@ #ifndef CMDLFEM4X_H__ #define CMDLFEM4X_H__ -#include -#include // for bool -#include -#include -#include "proxmark3.h" -#include "ui.h" -#include "util.h" -#include "graph.h" -#include "cmdparser.h" -#include "cmddata.h" -#include "comms.h" -#include "cmdlf.h" -#include "lfdemod.h" +#include "common.h" int CmdLFEM4X(const char *Cmd); diff --git a/client/cmdlffdx.c b/client/cmdlffdx.c index a13c1e947d..2e48918fbb 100644 --- a/client/cmdlffdx.c +++ b/client/cmdlffdx.c @@ -10,6 +10,21 @@ #include "cmdlffdx.h" +#include +#include +#include + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "commonutil.h" + +#include "ui.h" // PrintAndLog +#include "cmddata.h" +#include "cmdlf.h" // lf read +#include "crc16.h" // for checksum crc-16_ccitt +#include "protocols.h" // for T55xx config register definitions +#include "lfdemod.h" // parityTest + /* FDX-B ISO11784/85 demod (aka animal tag) BIPHASE, inverted, rf/32, with preamble of 00000000001 (128bits) 8 databits + 1 parity (1) diff --git a/client/cmdlffdx.h b/client/cmdlffdx.h index 5e6c5ab483..d8b666ccb7 100644 --- a/client/cmdlffdx.h +++ b/client/cmdlffdx.h @@ -8,16 +8,8 @@ //----------------------------------------------------------------------------- #ifndef CMDLFFDX_H__ #define CMDLFFDX_H__ -#include "proxmark3.h" // Definitions, USB controls, etc -#include "ui.h" // PrintAndLog -#include "util.h" // weigandparity -#include "cmdparser.h" -#include "cmddata.h" -#include "cmdmain.h" -#include "cmdlf.h" // lf read -#include "crc16.h" // for checksum crc-16_ccitt -#include "protocols.h" // for T55xx config register definitions -#include "lfdemod.h" // parityTest + +#include "common.h" int CmdLFFdx(const char *Cmd); int detectFDXB(uint8_t *dest, size_t *size); diff --git a/client/cmdlfguard.c b/client/cmdlfguard.c index 19f23088ef..22f7141fcd 100644 --- a/client/cmdlfguard.c +++ b/client/cmdlfguard.c @@ -9,6 +9,19 @@ //----------------------------------------------------------------------------- #include "cmdlfguard.h" +#include +#include +#include +#include + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "ui.h" +#include "cmddata.h" +#include "cmdlf.h" +#include "protocols.h" // for T55xx config register definitions +#include "lfdemod.h" // parityTest + static int CmdHelp(const char *Cmd); static int usage_lf_guard_clone(void) { diff --git a/client/cmdlfguard.h b/client/cmdlfguard.h index c6725ed076..3d923a7fed 100644 --- a/client/cmdlfguard.h +++ b/client/cmdlfguard.h @@ -8,19 +8,8 @@ //----------------------------------------------------------------------------- #ifndef CMDLFGUARD_H__ #define CMDLFGUARD_H__ -#include -#include -#include "proxmark3.h" -#include "ui.h" -#include "util.h" -#include "graph.h" -#include "cmdparser.h" -#include "cmddata.h" -#include "cmdmain.h" -#include "cmdlf.h" -#include "protocols.h" // for T55xx config register definitions -#include "lfdemod.h" // parityTest -#include "crc.h" + +#include "common.h" int CmdLFGuard(const char *Cmd); int detectGProxII(uint8_t *bits, size_t *size); diff --git a/client/cmdlfhid.c b/client/cmdlfhid.c index 57df08d5dc..8e22654f4a 100644 --- a/client/cmdlfhid.c +++ b/client/cmdlfhid.c @@ -10,6 +10,22 @@ #include "cmdlfhid.h" +#include +#include + +#include +#include + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "commonutil.h" // ARRAYLEN +#include "ui.h" +#include "graph.h" +#include "cmddata.h" //for g_debugMode, demodbuff cmds +#include "cmdlf.h" // lf_read +#include "util_posix.h" +#include "lfdemod.h" + #ifndef BITS # define BITS 96 #endif diff --git a/client/cmdlfhid.h b/client/cmdlfhid.h index 8270b64695..2b61861ffe 100644 --- a/client/cmdlfhid.h +++ b/client/cmdlfhid.h @@ -11,18 +11,7 @@ #ifndef CMDLFHID_H__ #define CMDLFHID_H__ -#include -#include -#include "proxmark3.h" -#include "ui.h" -#include "graph.h" -#include "cmdparser.h" -#include "util.h" // wiegand_add_parity etc -#include "cmddata.h" //for g_debugMode, demodbuff cmds -#include "cmdlf.h" // lf_read -#include "cmdmain.h" -#include "util_posix.h" -#include "lfdemod.h" +#include "common.h" int CmdLFHID(const char *Cmd); diff --git a/client/cmdlfhitag.c b/client/cmdlfhitag.c index a1fb3415b5..190b842837 100644 --- a/client/cmdlfhitag.c +++ b/client/cmdlfhitag.c @@ -8,19 +8,13 @@ // Low frequency Hitag support //----------------------------------------------------------------------------- -#include -#include -#include -#include "proxmark3.h" -#include "ui.h" -#include "cmdparser.h" -#include "common.h" -#include "util.h" -#include "parity.h" -#include "hitag.h" -#include "util_posix.h" +#include + +#include "cmdparser.h" // command_t #include "comms.h" -#include "cmddata.h" +#include "cmdtrace.h" +#include "commonutil.h" +#include "hitag.h" #include "loclass/fileutils.h" // savefile static int CmdHelp(const char *Cmd); @@ -299,7 +293,7 @@ static int CmdLFHitagSim(const char *Cmd) { param_getstr(Cmd, cmdp + 1, filename, sizeof(filename)); res = loadFileEML(filename, data, &datalen); if (res > 0 || datalen != maxdatalen) { - PrintAndLogDevice(FAILED, "error, bytes read mismatch file size"); + PrintAndLogEx(FAILED, "error, bytes read mismatch file size"); errors = true; break; } diff --git a/client/cmdlfhitag.h b/client/cmdlfhitag.h index 264a245a18..c95c0e3348 100644 --- a/client/cmdlfhitag.h +++ b/client/cmdlfhitag.h @@ -11,6 +11,8 @@ #ifndef CMDLFHITAG_H__ #define CMDLFHITAG_H__ +#include "common.h" + int CmdLFHitag(const char *Cmd); int readHitagUid(void); diff --git a/client/cmdlfindala.c b/client/cmdlfindala.c index f7dc652710..3fd3be59e3 100644 --- a/client/cmdlfindala.c +++ b/client/cmdlfindala.c @@ -10,6 +10,22 @@ #include "cmdlfindala.h" +#include +#include + +#include +#include + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "graph.h" +#include "cliparser/cliparser.h" +#include "commonutil.h" +#include "ui.h" // PrintAndLog +#include "lfdemod.h" // parityTest, bitbytes_to_byte +#include "cmddata.h" +#include "cmdlf.h" // lf_read + static int CmdHelp(const char *Cmd); //large 224 bit indala formats (different preamble too...) diff --git a/client/cmdlfindala.h b/client/cmdlfindala.h index 1de894bf7c..8300171178 100644 --- a/client/cmdlfindala.h +++ b/client/cmdlfindala.h @@ -10,18 +10,7 @@ #ifndef CMDLFINDALA_H__ #define CMDLFINDALA_H__ -#include // sscanf -#include -#include -#include "proxmark3.h" // Definitions, USB controls, etc -#include "ui.h" // PrintAndLog -#include "cmdparser.h" // CmdsParse, CmdsHelp -#include "lfdemod.h" // parityTest, bitbytes_to_byte -#include "util.h" // weigandparity -#include "protocols.h" // for T55xx config register definitions -#include "cmdmain.h" -#include "cmddata.h" -#include "cmdlf.h" // lf_read +#include "common.h" int CmdLFINDALA(const char *Cmd); diff --git a/client/cmdlfio.c b/client/cmdlfio.c index b1605ecfa9..87fa17b02b 100644 --- a/client/cmdlfio.c +++ b/client/cmdlfio.c @@ -10,6 +10,21 @@ #include "cmdlfio.h" +#include // sscanf +#include +#include + +#include + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "graph.h" +#include "cmdlf.h" +#include "ui.h" // PrintAndLog +#include "lfdemod.h" // parityTest, bitbytes_to_byte +#include "protocols.h" // for T55xx config register definitions +#include "cmddata.h" + static int CmdHelp(const char *Cmd); /* static int usage_lf_io_read(void) { diff --git a/client/cmdlfio.h b/client/cmdlfio.h index 39abbc767b..cb3a514be0 100644 --- a/client/cmdlfio.h +++ b/client/cmdlfio.h @@ -4,17 +4,7 @@ #ifndef CMDLFIO_H__ #define CMDLFIO_H__ -#include // sscanf -#include -#include -#include "proxmark3.h" // Definitions, USB controls, etc -#include "ui.h" // PrintAndLog -#include "cmdparser.h" // CmdsParse, CmdsHelp -#include "lfdemod.h" // parityTest, bitbytes_to_byte -#include "util.h" // weigandparity -#include "protocols.h" // for T55xx config register definitions -#include "cmdmain.h" -#include "cmddata.h" +#include "common.h" int CmdLFIO(const char *Cmd); diff --git a/client/cmdlfjablotron.c b/client/cmdlfjablotron.c index 11370e2861..9cc6638950 100644 --- a/client/cmdlfjablotron.c +++ b/client/cmdlfjablotron.c @@ -10,6 +10,21 @@ #include "cmdlfjablotron.h" +#include +#include +#include +#include +#include + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "commonutil.h" +#include "ui.h" +#include "cmddata.h" +#include "cmdlf.h" +#include "protocols.h" // for T55xx config register definitions +#include "lfdemod.h" // parityTest + static int CmdHelp(const char *Cmd); static int usage_lf_jablotron_clone(void) { diff --git a/client/cmdlfjablotron.h b/client/cmdlfjablotron.h index ae61864963..da4de291f7 100644 --- a/client/cmdlfjablotron.h +++ b/client/cmdlfjablotron.h @@ -8,19 +8,8 @@ //----------------------------------------------------------------------------- #ifndef CMDLFJABLOTRON_H__ #define CMDLFJABLOTRON_H__ -#include -#include -#include -#include "proxmark3.h" -#include "ui.h" -#include "util.h" -#include "graph.h" -#include "cmdparser.h" -#include "cmddata.h" -#include "cmdmain.h" -#include "cmdlf.h" -#include "protocols.h" // for T55xx config register definitions -#include "lfdemod.h" // parityTest + +#include "common.h" int CmdLFJablotron(const char *Cmd); diff --git a/client/cmdlfkeri.c b/client/cmdlfkeri.c index a71687a62d..384aad0b62 100644 --- a/client/cmdlfkeri.c +++ b/client/cmdlfkeri.c @@ -9,6 +9,20 @@ //----------------------------------------------------------------------------- #include "cmdlfkeri.h" +#include +#include + +#include +#include + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "ui.h" +#include "cmddata.h" +#include "cmdlf.h" +#include "protocols.h" // for T55xx config register definitions +#include "lfdemod.h" // preamble test + static int CmdHelp(const char *Cmd); static int usage_lf_keri_clone(void) { diff --git a/client/cmdlfkeri.h b/client/cmdlfkeri.h index 78b0878347..2e1ada11f6 100644 --- a/client/cmdlfkeri.h +++ b/client/cmdlfkeri.h @@ -9,18 +9,7 @@ #ifndef CMDLFKERI_H__ #define CMDLFKERI_H__ -#include -#include -#include "proxmark3.h" -#include "ui.h" -#include "util.h" -#include "graph.h" -#include "cmdparser.h" -#include "cmddata.h" -#include "cmdmain.h" -#include "cmdlf.h" -#include "protocols.h" // for T55xx config register definitions -#include "lfdemod.h" // preamble test +#include "common.h" int CmdLFKeri(const char *Cmd); diff --git a/client/cmdlfnedap.c b/client/cmdlfnedap.c index dc88949710..b7f9891a56 100644 --- a/client/cmdlfnedap.c +++ b/client/cmdlfnedap.c @@ -9,6 +9,20 @@ #include "cmdlfnedap.h" +#include + +#include +#include + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "crc16.h" +#include "cmdlft55xx.h" +#include "ui.h" +#include "cmddata.h" +#include "cmdlf.h" +#include "lfdemod.h" + #define FIXED_71 0x71 #define FIXED_40 0x40 #define UNKNOWN_A 0x00 diff --git a/client/cmdlfnedap.h b/client/cmdlfnedap.h index 8ba7c9908e..fda0e130ea 100644 --- a/client/cmdlfnedap.h +++ b/client/cmdlfnedap.h @@ -8,19 +8,8 @@ //----------------------------------------------------------------------------- #ifndef CMDLFNEDAP_H__ #define CMDLFNEDAP_H__ -#include -#include -#include "proxmark3.h" -#include "ui.h" -#include "util.h" -#include "graph.h" -#include "cmdparser.h" -#include "cmddata.h" -#include "cmdmain.h" -#include "cmdlf.h" -#include "protocols.h" // for T55xx config register definitions -#include "lfdemod.h" // parityTest -#include "crc.h" + +#include "common.h" int CmdLFNedap(const char *Cmd); diff --git a/client/cmdlfnexwatch.c b/client/cmdlfnexwatch.c index e543dd635a..bad9dea4fd 100644 --- a/client/cmdlfnexwatch.c +++ b/client/cmdlfnexwatch.c @@ -10,6 +10,13 @@ #include "cmdlfnexwatch.h" +#include "cmdparser.h" // command_t +#include "comms.h" +#include "ui.h" +#include "cmddata.h" // preamblesearch +#include "cmdlf.h" +#include "lfdemod.h" + static int CmdHelp(const char *Cmd); static int CmdNexWatchDemod(const char *Cmd) { diff --git a/client/cmdlfnexwatch.h b/client/cmdlfnexwatch.h index 4a70761a4a..a282a320ee 100644 --- a/client/cmdlfnexwatch.h +++ b/client/cmdlfnexwatch.h @@ -9,18 +9,7 @@ #ifndef CMDLFNEXWATCH_H__ #define CMDLFNEXWATCH_H__ -#include -#include -#include -#include -#include "proxmark3.h" -#include "ui.h" -#include "util.h" -#include "graph.h" -#include "cmdparser.h" -#include "cmddata.h" // preamblesearch -#include "cmdlf.h" -#include "lfdemod.h" +#include "common.h" int CmdLFNEXWATCH(const char *Cmd); diff --git a/client/cmdlfnoralsy.c b/client/cmdlfnoralsy.c index ec8da0bf96..cc1db82caf 100644 --- a/client/cmdlfnoralsy.c +++ b/client/cmdlfnoralsy.c @@ -9,6 +9,18 @@ //----------------------------------------------------------------------------- #include "cmdlfnoralsy.h" +#include +#include +#include + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "ui.h" +#include "cmddata.h" +#include "cmdlf.h" +#include "protocols.h" // for T55xx config register definitions +#include "lfdemod.h" // parityTest + static int CmdHelp(const char *Cmd); static int usage_lf_noralsy_clone(void) { diff --git a/client/cmdlfnoralsy.h b/client/cmdlfnoralsy.h index b5a5cd9145..f76accab7f 100644 --- a/client/cmdlfnoralsy.h +++ b/client/cmdlfnoralsy.h @@ -8,19 +8,8 @@ //----------------------------------------------------------------------------- #ifndef CMDLFNORALSY_H__ #define CMDLFNORALSY_H__ -#include -#include -#include -#include "proxmark3.h" -#include "ui.h" -#include "util.h" -#include "graph.h" -#include "cmdparser.h" -#include "cmddata.h" -#include "cmdmain.h" -#include "cmdlf.h" -#include "protocols.h" // for T55xx config register definitions -#include "lfdemod.h" // parityTest + +#include "common.h" int CmdLFNoralsy(const char *Cmd); diff --git a/client/cmdlfpac.c b/client/cmdlfpac.c index b9d6f1449c..8645060895 100644 --- a/client/cmdlfpac.c +++ b/client/cmdlfpac.c @@ -9,6 +9,13 @@ //----------------------------------------------------------------------------- #include "cmdlfpac.h" +#include "cmdparser.h" // command_t +#include "comms.h" +#include "ui.h" +#include "cmddata.h" +#include "cmdlf.h" +#include "lfdemod.h" // preamble test + static int CmdHelp(const char *Cmd); //see NRZDemod for what args are accepted diff --git a/client/cmdlfpac.h b/client/cmdlfpac.h index f076121cd9..3c9c4fbda4 100644 --- a/client/cmdlfpac.h +++ b/client/cmdlfpac.h @@ -9,17 +9,7 @@ #ifndef CMDLFPAC_H__ #define CMDLFPAC_H__ -#include -#include -#include "proxmark3.h" -#include "ui.h" -#include "util.h" -#include "graph.h" -#include "cmdparser.h" -#include "cmddata.h" -#include "cmdmain.h" -#include "cmdlf.h" -#include "lfdemod.h" // preamble test +#include "common.h" int CmdLFPac(const char *Cmd); diff --git a/client/cmdlfparadox.c b/client/cmdlfparadox.c index d18c501ca5..8a1a940c53 100644 --- a/client/cmdlfparadox.c +++ b/client/cmdlfparadox.c @@ -7,15 +7,17 @@ // Low frequency Paradox tag commands // FSK2a, rf/50, 96 bits (completely known) //----------------------------------------------------------------------------- +#include "cmdlfparadox.h" + #include #include -#include -#include "cmdlfparadox.h" -#include "proxmark3.h" +#include +#include + +#include "cmdparser.h" // command_t +#include "comms.h" #include "ui.h" -#include "util.h" #include "graph.h" -#include "cmdparser.h" #include "cmddata.h" #include "cmdlf.h" #include "lfdemod.h" diff --git a/client/cmdlfparadox.h b/client/cmdlfparadox.h index f7f4a4ffe9..34c3cb6cdd 100644 --- a/client/cmdlfparadox.h +++ b/client/cmdlfparadox.h @@ -8,6 +8,9 @@ //----------------------------------------------------------------------------- #ifndef CMDLFPARADOX_H__ #define CMDLFPARADOX_H__ + +#include "common.h" + int CmdLFParadox(const char *Cmd); int demodParadox(void); diff --git a/client/cmdlfpcf7931.c b/client/cmdlfpcf7931.c index a9ab9cf3eb..e4a14a47ef 100644 --- a/client/cmdlfpcf7931.c +++ b/client/cmdlfpcf7931.c @@ -8,17 +8,13 @@ //----------------------------------------------------------------------------- // Low frequency PCF7931 commands //----------------------------------------------------------------------------- -#include +#include "cmdlfpcf7931.h" + #include -#include "proxmark3.h" + +#include "cmdparser.h" // command_t +#include "comms.h" #include "ui.h" -#include "util.h" -#include "graph.h" -#include "cmdparser.h" -#include "cmddata.h" -#include "cmdmain.h" -#include "cmdlf.h" -#include "cmdlfpcf7931.h" static int CmdHelp(const char *Cmd); diff --git a/client/cmdlfpcf7931.h b/client/cmdlfpcf7931.h index 4193869565..4f84085b28 100644 --- a/client/cmdlfpcf7931.h +++ b/client/cmdlfpcf7931.h @@ -12,6 +12,8 @@ #ifndef CMDLFPCF7931_H__ #define CMDLFPCF7931_H__ +#include "common.h" + struct pcf7931_config { uint8_t Pwd[7]; uint16_t InitDelay; diff --git a/client/cmdlfpresco.c b/client/cmdlfpresco.c index cbf919aefa..14d87648e6 100644 --- a/client/cmdlfpresco.c +++ b/client/cmdlfpresco.c @@ -8,6 +8,20 @@ //----------------------------------------------------------------------------- #include "cmdlfpresco.h" + +#include +#include +#include +#include + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "ui.h" +#include "cmddata.h" +#include "cmdlf.h" +#include "protocols.h" // for T55xx config register definitions +#include "lfdemod.h" // parityTest + static int CmdHelp(const char *Cmd); static int usage_lf_presco_clone(void) { diff --git a/client/cmdlfpresco.h b/client/cmdlfpresco.h index 1f101a13c5..098a983420 100644 --- a/client/cmdlfpresco.h +++ b/client/cmdlfpresco.h @@ -8,18 +8,8 @@ //----------------------------------------------------------------------------- #ifndef CMDLFPRESCO_H__ #define CMDLFPRESCO_H__ -#include -#include -#include "proxmark3.h" -#include "ui.h" -#include "util.h" -#include "graph.h" -#include "cmdparser.h" -#include "cmddata.h" -#include "cmdmain.h" -#include "cmdlf.h" -#include "protocols.h" // for T55xx config register definitions -#include "lfdemod.h" // parityTest + +#include "common.h" int CmdLFPresco(const char *Cmd); diff --git a/client/cmdlfpyramid.c b/client/cmdlfpyramid.c index b36d386c9f..d5c3076a98 100644 --- a/client/cmdlfpyramid.c +++ b/client/cmdlfpyramid.c @@ -9,6 +9,21 @@ //----------------------------------------------------------------------------- #include "cmdlfpyramid.h" +#include +#include +#include +#include + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "ui.h" +#include "graph.h" +#include "cmddata.h" +#include "cmdlf.h" +#include "protocols.h" // for T55xx config register definitions +#include "lfdemod.h" // parityTest +#include "crc.h" + static int CmdHelp(const char *Cmd); static int usage_lf_pyramid_clone(void) { diff --git a/client/cmdlfpyramid.h b/client/cmdlfpyramid.h index 009bec3ce0..2d717fbb37 100644 --- a/client/cmdlfpyramid.h +++ b/client/cmdlfpyramid.h @@ -8,19 +8,8 @@ //----------------------------------------------------------------------------- #ifndef CMDLFPYRAMID_H__ #define CMDLFPYRAMID_H__ -#include -#include -#include "proxmark3.h" -#include "ui.h" -#include "util.h" -#include "graph.h" -#include "cmdparser.h" -#include "cmddata.h" -#include "cmdmain.h" -#include "cmdlf.h" -#include "protocols.h" // for T55xx config register definitions -#include "lfdemod.h" // parityTest -#include "crc.h" + +#include "common.h" int CmdLFPyramid(const char *Cmd); diff --git a/client/cmdlfsecurakey.c b/client/cmdlfsecurakey.c index 82df3b659c..0ee22524f9 100644 --- a/client/cmdlfsecurakey.c +++ b/client/cmdlfsecurakey.c @@ -9,6 +9,16 @@ //----------------------------------------------------------------------------- #include "cmdlfsecurakey.h" +#include + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "ui.h" +#include "cmddata.h" +#include "cmdlf.h" +#include "lfdemod.h" // preamble test +#include "parity.h" // for wiegand parity test + static int CmdHelp(const char *Cmd); //see ASKDemod for what args are accepted diff --git a/client/cmdlfsecurakey.h b/client/cmdlfsecurakey.h index 6a84d2046b..229fd0047b 100644 --- a/client/cmdlfsecurakey.h +++ b/client/cmdlfsecurakey.h @@ -9,20 +9,7 @@ #ifndef CMDLFSECURAKEY_H__ #define CMDLFSECURAKEY_H__ -#include -#include -#include -#include "proxmark3.h" -#include "ui.h" -#include "util.h" -#include "graph.h" -#include "cmdparser.h" -#include "cmddata.h" -#include "cmdmain.h" -#include "cmdlf.h" -#include "protocols.h" // for T55xx config register definitions -#include "lfdemod.h" // preamble test -#include "parity.h" // for wiegand parity test +#include "common.h" int CmdLFSecurakey(const char *Cmd); diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index be24be9765..72838e73b5 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -14,6 +14,21 @@ #include "cmdlft55xx.h" +#include +#include // MingW + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "commonutil.h" +#include "protocols.h" +#include "graph.h" +#include "cmddata.h" +#include "lfdemod.h" +#include "cmdhf14a.h" // for getTagInfo +#include "loclass/fileutils.h" // loadDictionary +#include "util_posix.h" + + // Some defines for readability #define T55XX_DLMODE_FIXED 0 // Default Mode #define T55XX_DLMODE_LLR 1 // Long Leading Reference @@ -2117,7 +2132,7 @@ static int CmdT55xxChkPwds(const char *Cmd) { // TODO, a way of reallocating memory if file was larger keyBlock = calloc(4 * 200, sizeof(uint8_t)); if (keyBlock == NULL) { - PrintAndLogDevice(ERR, "error, cannot allocate memory "); + PrintAndLogEx(ERR, "error, cannot allocate memory "); return PM3_ESOFT; } diff --git a/client/cmdlft55xx.h b/client/cmdlft55xx.h index c61ef137d5..668b23be31 100644 --- a/client/cmdlft55xx.h +++ b/client/cmdlft55xx.h @@ -10,23 +10,7 @@ #ifndef CMDLFT55XX_H__ #define CMDLFT55XX_H__ -#include -#include -#include -#include -#include -#include "proxmark3.h" -#include "ui.h" -#include "graph.h" -#include "comms.h" -#include "cmdparser.h" -#include "cmddata.h" -#include "cmdlf.h" -#include "util.h" -#include "lfdemod.h" -#include "cmdhf14a.h" // for getTagInfo -#include "loclass/fileutils.h" // loadDictionary - +#include "common.h" #define T55x7_CONFIGURATION_BLOCK 0x00 #define T55x7_TRACE_BLOCK1 0x01 diff --git a/client/cmdlfti.c b/client/cmdlfti.c index 9e07926f4a..cf01abb737 100644 --- a/client/cmdlfti.c +++ b/client/cmdlfti.c @@ -11,13 +11,14 @@ #include #include #include + +#include "cmdparser.h" // command_t +#include "commonutil.h" +#include "comms.h" #include "crc16.h" -#include "proxmark3.h" #include "ui.h" #include "graph.h" -#include "cmdparser.h" #include "cmdlfti.h" -#include "cmdmain.h" static int CmdHelp(const char *Cmd); diff --git a/client/cmdlfti.h b/client/cmdlfti.h index bb4922f783..e185a14030 100644 --- a/client/cmdlfti.h +++ b/client/cmdlfti.h @@ -11,6 +11,8 @@ #ifndef CMDLFTI_H__ #define CMDLFTI_H__ +#include "common.h" + int CmdLFTI(const char *Cmd); int demodTI(void); diff --git a/client/cmdlfviking.c b/client/cmdlfviking.c index 1d2114e95d..ef88cc1698 100644 --- a/client/cmdlfviking.c +++ b/client/cmdlfviking.c @@ -9,6 +9,17 @@ //----------------------------------------------------------------------------- #include "cmdlfviking.h" +#include +#include +#include + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "ui.h" +#include "cmddata.h" +#include "cmdlf.h" +#include "lfdemod.h" + static int CmdHelp(const char *Cmd); static int usage_lf_viking_clone(void) { diff --git a/client/cmdlfviking.h b/client/cmdlfviking.h index 8789515d65..156d57c7da 100644 --- a/client/cmdlfviking.h +++ b/client/cmdlfviking.h @@ -8,18 +8,8 @@ //----------------------------------------------------------------------------- #ifndef CMDLFVIKING_H__ #define CMDLFVIKING_H__ -#include -#include -#include -#include "proxmark3.h" -#include "ui.h" -#include "util.h" -#include "graph.h" -#include "cmdparser.h" -#include "cmddata.h" -#include "cmdmain.h" -#include "cmdlf.h" -#include "lfdemod.h" + +#include "common.h" int CmdLFViking(const char *Cmd); diff --git a/client/cmdlfvisa2000.c b/client/cmdlfvisa2000.c index d698535bfa..ed181d9910 100644 --- a/client/cmdlfvisa2000.c +++ b/client/cmdlfvisa2000.c @@ -11,6 +11,19 @@ #include "cmdlfvisa2000.h" +#include +#include +#include + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "ui.h" +#include "graph.h" +#include "cmddata.h" +#include "cmdlf.h" +#include "protocols.h" // for T55xx config register definitions +#include "lfdemod.h" // parityTest + #define BL0CK1 0x56495332 static int CmdHelp(const char *Cmd); diff --git a/client/cmdlfvisa2000.h b/client/cmdlfvisa2000.h index 15d626f6c2..63e7fdc677 100644 --- a/client/cmdlfvisa2000.h +++ b/client/cmdlfvisa2000.h @@ -8,19 +8,9 @@ //----------------------------------------------------------------------------- #ifndef CMDLFVISA2000_H__ #define CMDLFVISA2000_H__ -#include -#include -#include -#include "proxmark3.h" -#include "ui.h" -#include "util.h" -#include "graph.h" -#include "cmdparser.h" -#include "cmddata.h" -#include "cmdmain.h" -#include "cmdlf.h" -#include "protocols.h" // for T55xx config register definitions -#include "lfdemod.h" // parityTest + +#include "common.h" + int CmdLFVisa2k(const char *Cmd); int getvisa2kBits(uint64_t fullcode, uint8_t *bits); diff --git a/client/cmdmain.c b/client/cmdmain.c index 6748f81f09..618f04c73e 100644 --- a/client/cmdmain.c +++ b/client/cmdmain.c @@ -15,6 +15,26 @@ #endif #include "cmdmain.h" +#include +#include +#include // MingW + +#include "comms.h" +#include "cmdhf.h" +#include "cmddata.h" +#include "cmdhw.h" +#include "cmdlf.h" +#include "cmdtrace.h" +#include "cmdscript.h" +#include "cmdcrc.h" +#include "cmdanalyse.h" +#include "emv/cmdemv.h" // EMV +#include "cmdflashmem.h" // rdv40 flashmem commands +#include "cmdsmartcard.h" // rdv40 smart card ISO7816 commands +#include "cmdusart.h" // rdv40 FPC USART commands +#include "ui.h" +#include "util_posix.h" + static int CmdHelp(const char *Cmd); static int CmdRem(const char *Cmd) { diff --git a/client/cmdmain.h b/client/cmdmain.h index e3c5135500..8b440143ed 100644 --- a/client/cmdmain.h +++ b/client/cmdmain.h @@ -11,30 +11,8 @@ #ifndef CMDMAIN_H__ #define CMDMAIN_H__ -#include -#include -#include -#include -#include -#include -#include "util_posix.h" -#include "proxmark3.h" -#include "pm3_cmd.h" -#include "util.h" -#include "ui.h" -#include "cmdparser.h" -#include "cmdhf.h" -#include "cmddata.h" -#include "cmdhw.h" -#include "cmdlf.h" -#include "cmdtrace.h" -#include "cmdscript.h" -#include "cmdcrc.h" -#include "cmdanalyse.h" -#include "emv/cmdemv.h" // EMV -#include "cmdflashmem.h" // rdv40 flashmem commands -#include "cmdsmartcard.h" // rdv40 smart card ISO7816 commands -#include "cmdusart.h" // rdv40 FPC USART commands +#include "common.h" +#include "cmdparser.h" // command_t int CommandReceived(char *Cmd); command_t *getTopLevelCommandTable(void); diff --git a/client/cmdparser.c b/client/cmdparser.c index fff0fabecc..d9ece2310e 100644 --- a/client/cmdparser.c +++ b/client/cmdparser.c @@ -8,13 +8,12 @@ // Command parser //----------------------------------------------------------------------------- +#include "cmdparser.h" + #include -#include #include -#include "util.h" + #include "ui.h" -#include "cmdparser.h" -#include "proxmark3.h" #include "comms.h" bool AlwaysAvailable(void) { diff --git a/client/cmdparser.h b/client/cmdparser.h index 06eb02848e..284142780c 100644 --- a/client/cmdparser.h +++ b/client/cmdparser.h @@ -11,6 +11,8 @@ #ifndef CMDPARSER_H__ #define CMDPARSER_H__ +#include "common.h" + typedef struct command_s { const char *Name; int (*Parse)(const char *Cmd); diff --git a/client/cmdscript.c b/client/cmdscript.c index 8880e18fd6..28dd8608f5 100644 --- a/client/cmdscript.c +++ b/client/cmdscript.c @@ -11,27 +11,21 @@ // this define is needed for scandir/alphasort to work #define _GNU_SOURCE -#include +#include #include #include -#include -#include -#include -#include "proxmark3.h" +#include "cmdparser.h" // command_t #include "scripting.h" -#include "ui.h" -#include "graph.h" -#include "cmdparser.h" -#include "cmdmain.h" #include "comms.h" #include "cmdscript.h" #include "cmdhfmf.h" #include "pm3_binlib.h" #include "pm3_bitlib.h" -#include -#include -#include +#include "lualib.h" +#include "lauxlib.h" +#include "proxmark3.h" +#include "ui.h" #ifdef _WIN32 #include "scandir.h" diff --git a/client/cmdscript.h b/client/cmdscript.h index 866b09e99f..37384db206 100644 --- a/client/cmdscript.h +++ b/client/cmdscript.h @@ -11,6 +11,8 @@ #ifndef CMDSCRIPT_H__ #define CMDSCRIPT_H__ +#include "common.h" + int CmdScript(const char *Cmd); #endif diff --git a/client/cmdsmartcard.c b/client/cmdsmartcard.c index 5147dbd7ed..f1fd2b9176 100644 --- a/client/cmdsmartcard.c +++ b/client/cmdsmartcard.c @@ -8,7 +8,20 @@ // Proxmark3 RDV40 Smartcard module commands //----------------------------------------------------------------------------- #include "cmdsmartcard.h" -#include "../emv/emvjson.h" + +#include +#include + +#include "cmdparser.h" // command_t +#include "commonutil.h" // ARRAYLEN +#include "protocols.h" +#include "cmdtrace.h" +#include "proxmark3.h" +#include "comms.h" // getfromdevice +#include "emv/emvcore.h" // decodeTVL +#include "crypto/libpcrypto.h" // sha512hash +#include "emv/dump.h" +#include "ui.h" static int CmdHelp(const char *Cmd); diff --git a/client/cmdsmartcard.h b/client/cmdsmartcard.h index 6b960f3111..74c305a0d9 100644 --- a/client/cmdsmartcard.h +++ b/client/cmdsmartcard.h @@ -11,21 +11,8 @@ #ifndef CMDSMARTCARD_H__ #define CMDSMARTCARD_H__ -#include -#include -#include -#include -#include "proxmark3.h" -#include "ui.h" -#include "cmdparser.h" #include "common.h" -#include "util.h" -#include "loclass/fileutils.h" // saveFile -#include "comms.h" // getfromdevice -#include "emv/emvcore.h" // decodeTVL -#include "emv/apduinfo.h" // APDUcode description -#include "emv/dump.h" // dump_buffer -#include "crypto/libpcrypto.h" // sha512hash +#include "mifare.h" // structs int CmdSmartcard(const char *Cmd); diff --git a/client/cmdtrace.c b/client/cmdtrace.c index 4f961b69e6..15416a8a6a 100644 --- a/client/cmdtrace.c +++ b/client/cmdtrace.c @@ -9,6 +9,15 @@ //----------------------------------------------------------------------------- #include "cmdtrace.h" +#include + +#include "cmdparser.h" // command_t +#include "protocols.h" +#include "parity.h" // oddparity +#include "cmdhflist.h" // annotations +#include "comms.h" // for sending cmds to device. GetFromBigBuf +#include "loclass/fileutils.h" // for saveFile + static int CmdHelp(const char *Cmd); // trace pointer diff --git a/client/cmdtrace.h b/client/cmdtrace.h index 2f0125664c..acef66884d 100644 --- a/client/cmdtrace.h +++ b/client/cmdtrace.h @@ -10,22 +10,8 @@ #ifndef CMDTRACE_H__ #define CMDTRACE_H__ -#include -#include -#include -#include -#include -#include -#include "proxmark3.h" -#include "protocols.h" -#include "parity.h" // oddparity -#include "cmdhflist.h" // annotations -#include "iso15693tools.h" // ISO15693 crc -#include "util.h" // for parsing cli command utils -#include "ui.h" // for show graph controls -#include "cmdparser.h" // for getting cli commands included in cmdmain.h -#include "comms.h" // for sending cmds to device. GetFromBigBuf -#include "loclass/fileutils.h" // for saveFile + +#include "common.h" int CmdTrace(const char *Cmd); int CmdTraceList(const char *Cmd); diff --git a/client/cmdusart.c b/client/cmdusart.c index 5cb1a7b0cb..0b668bbe75 100644 --- a/client/cmdusart.c +++ b/client/cmdusart.c @@ -9,6 +9,18 @@ //----------------------------------------------------------------------------- #include "cmdusart.h" +#include // size_t +#include +#include +#include + +#include "cmdparser.h" // command_t +#include "commonutil.h" // ARRAYLEN +#include "comms.h" +#include "util_posix.h" +#include "usart_defs.h" +#include "ui.h" // PrintAndLog + static int CmdHelp(const char *Cmd); static int usage_usart_bt_pin(void) { diff --git a/client/cmdusart.h b/client/cmdusart.h index f2e4d02dd9..1ee21e0604 100644 --- a/client/cmdusart.h +++ b/client/cmdusart.h @@ -11,14 +11,7 @@ #ifndef CMDUSART_H__ #define CMDUSART_H__ -#include // size_t -#include -#include -#include "cmdmain.h" -#include "proxmark3.h" -#include "ui.h" // PrintAndLog -#include "util.h" -//#include "util_posix.h" // msclock +#include "common.h" int CmdUsart(const char *Cmd); #endif diff --git a/client/comms.c b/client/comms.c index 22e5c7fa15..d42bd09fbf 100644 --- a/client/comms.c +++ b/client/comms.c @@ -10,11 +10,15 @@ //----------------------------------------------------------------------------- #include "comms.h" + +#include +#include +#include + +#include "uart.h" +#include "ui.h" #include "crc16.h" -#if defined(__linux__) || (__APPLE__) -#include -#include -#endif +#include "util_posix.h" // msclock //#define COMMS_DEBUG //#define COMMS_DEBUG_RAW diff --git a/client/comms.h b/client/comms.h index bc036f008e..b49ff6d112 100644 --- a/client/comms.h +++ b/client/comms.h @@ -12,19 +12,22 @@ #ifndef COMMS_H_ #define COMMS_H_ -#include -#include - -#include "pm3_cmd.h" -#include "uart.h" -#include "ui.h" #include "common.h" -#include "util_posix.h" -#include "util.h" -#include "util_darwin.h" +#include "pm3_cmd.h" // Packet structs +#include "util.h" // FILE_PATH_SIZE + +#ifndef DropField +#define DropField() { \ + clearCommandBuffer(); SendCommandNG(CMD_HF_DROPFIELD, NULL, 0); \ + } +#endif -#if defined(__linux__) && !defined(NO_UNLINK) -#include // for unlink() +#ifndef DropFieldEx +#define DropFieldEx(x) { \ + if ( (x) == ECC_CONTACTLESS) { \ + DropField(); \ + } \ + } #endif //For storing command that are received from the device diff --git a/client/crypto/asn1dump.c b/client/crypto/asn1dump.c index 2c720ad04e..356dd3591e 100644 --- a/client/crypto/asn1dump.c +++ b/client/crypto/asn1dump.c @@ -8,8 +8,10 @@ // asn.1 dumping //----------------------------------------------------------------------------- #define _POSIX_C_SOURCE 200809L // need for strnlen() - #include "asn1dump.h" + +#include "commonutil.h" // ARRAYLEN + #include #include #include diff --git a/client/crypto/asn1utils.c b/client/crypto/asn1utils.c index c82f4aac88..1b2c782129 100644 --- a/client/crypto/asn1utils.c +++ b/client/crypto/asn1utils.c @@ -12,6 +12,9 @@ #include #include #include + +#include "ui.h" // Print... + #include "emv/tlv.h" #include "emv/dump.h" #include "asn1dump.h" diff --git a/client/emv/apduinfo.c b/client/emv/apduinfo.c index fd49eede89..cf43615cb0 100644 --- a/client/emv/apduinfo.c +++ b/client/emv/apduinfo.c @@ -10,6 +10,13 @@ #include "apduinfo.h" +#include // memmove +#include + +#include "ui.h" // Print... +#include "util.h" +#include "commonutil.h" // ARRAYLEN + const APDUCode APDUCodeTable[] = { // ID Type Description {"XXXX", APDUCODE_TYPE_NONE, ""}, // blank string diff --git a/client/emv/apduinfo.h b/client/emv/apduinfo.h index 25d062dcf1..590c728851 100644 --- a/client/emv/apduinfo.h +++ b/client/emv/apduinfo.h @@ -11,13 +11,7 @@ #ifndef APDUINFO_H__ #define APDUINFO_H__ -#include -#include -#include -#include -#include - -#include "util.h" +#include "common.h" #define APDUCODE_TYPE_NONE 0 #define APDUCODE_TYPE_INFO 1 diff --git a/client/emv/cmdemv.c b/client/emv/cmdemv.c index 0cf1776206..3891bdb481 100644 --- a/client/emv/cmdemv.c +++ b/client/emv/cmdemv.c @@ -8,14 +8,24 @@ // EMV commands //----------------------------------------------------------------------------- -#include -#include "mifare.h" #include "cmdemv.h" + +#include + +#include "comms.h" // DropField +#include "cmdsmartcard.h" // smart_select +#include "cmdtrace.h" #include "emvjson.h" -#include "emv_pki.h" #include "test/cryptotest.h" #include "cliparser/cliparser.h" -#include +#include "cmdparser.h" +#include "proxmark3.h" +#include "emv_roca.h" +#include "emvcore.h" +#include "cmdhf14a.h" +#include "dol.h" +#include "ui.h" +#include "emv_tags.h" static int CmdHelp(const char *Cmd); diff --git a/client/emv/cmdemv.h b/client/emv/cmdemv.h index 8cdcdf9908..ca1f9fc5a4 100644 --- a/client/emv/cmdemv.h +++ b/client/emv/cmdemv.h @@ -11,21 +11,7 @@ #ifndef CMDEMV_H__ #define CMDEMV_H__ -#include -#include -#include -#include -#include -#include "proxmark3.h" -#include "ui.h" -#include "cmdparser.h" #include "common.h" -#include "util.h" -#include "util_posix.h" -#include "cmdmain.h" -#include "emvcore.h" -#include "apduinfo.h" -#include "emv_roca.h" int CmdEMV(const char *Cmd); diff --git a/client/emv/crypto.c b/client/emv/crypto.c index ccf6684772..f7fc60c808 100644 --- a/client/emv/crypto.c +++ b/client/emv/crypto.c @@ -20,8 +20,6 @@ #include "crypto.h" #include "crypto_backend.h" -#include - static struct crypto_backend *crypto_backend; static bool crypto_init(void) { diff --git a/client/emv/crypto.h b/client/emv/crypto.h index 4eacca0b84..32252b4ccf 100644 --- a/client/emv/crypto.h +++ b/client/emv/crypto.h @@ -16,8 +16,7 @@ #ifndef CRYPTO_H #define CRYPTO_H -#include -#include +#include "common.h" enum crypto_algo_hash { HASH_INVALID, diff --git a/client/emv/crypto_backend.h b/client/emv/crypto_backend.h index 1113cf3410..3a38cc772a 100644 --- a/client/emv/crypto_backend.h +++ b/client/emv/crypto_backend.h @@ -18,8 +18,7 @@ #include "crypto.h" -#include -#include +#include // va_list struct crypto_hash { enum crypto_algo_hash algo; diff --git a/client/emv/crypto_polarssl.c b/client/emv/crypto_polarssl.c index 13f093aa45..b87dd9ee0d 100644 --- a/client/emv/crypto_polarssl.c +++ b/client/emv/crypto_polarssl.c @@ -18,11 +18,8 @@ #include #endif -#include "crypto.h" #include "crypto_backend.h" -#include -#include #include #include diff --git a/client/emv/dol.h b/client/emv/dol.h index 496ae66f50..8e65f679d4 100644 --- a/client/emv/dol.h +++ b/client/emv/dol.h @@ -17,7 +17,6 @@ #define DOL_H #include "emv/tlv.h" -#include struct tlv *dol_process(const struct tlv *tlv, const struct tlvdb *tlvdb, tlv_tag_t tag); struct tlvdb *dol_parse(const struct tlv *tlv, const unsigned char *data, size_t data_len); diff --git a/client/emv/dump.h b/client/emv/dump.h index fd6e160184..5a71b9519a 100644 --- a/client/emv/dump.h +++ b/client/emv/dump.h @@ -16,9 +16,9 @@ #ifndef DUMP_H #define DUMP_H -#include -#include -#include +#include "common.h" + +#include // FILE void dump_buffer_simple(const unsigned char *ptr, size_t len, FILE *f); void dump_buffer(const unsigned char *ptr, size_t len, FILE *f, int level); diff --git a/client/emv/emv_pk.c b/client/emv/emv_pk.c index b03567440f..e273480c8e 100644 --- a/client/emv/emv_pk.c +++ b/client/emv/emv_pk.c @@ -19,16 +19,16 @@ /* For asprintf */ #define _GNU_SOURCE -#include #include "emv_pk.h" -#include "crypto.h" -#include "proxmark3.h" -#include "util.h" -#include + +#include #include #include -#include + +#include "ui.h" +#include "crypto.h" +#include "proxmark3.h" #define BCD(c) (((c) >= '0' && (c) <= '9') ? ((c) - '0') : \ -1) diff --git a/client/emv/emv_pk.h b/client/emv/emv_pk.h index ed8000dc0a..dfc2497100 100644 --- a/client/emv/emv_pk.h +++ b/client/emv/emv_pk.h @@ -16,8 +16,7 @@ #ifndef EMV_PK_H #define EMV_PK_H -#include -#include +#include "common.h" struct emv_pk { unsigned char rid[5]; diff --git a/client/emv/emv_pki.c b/client/emv/emv_pki.c index cb2486bb44..bbdb321b30 100644 --- a/client/emv/emv_pki.c +++ b/client/emv/emv_pki.c @@ -18,15 +18,15 @@ #endif #include "emv_pki.h" -#include "crypto.h" -#include "dump.h" -#include "util.h" -#include #include #include #include +#include "crypto.h" +#include "dump.h" +#include "util.h" + static bool strictExecution = true; void PKISetStrictExecution(bool se) { strictExecution = se; diff --git a/client/emv/emv_pki.h b/client/emv/emv_pki.h index 91ff601668..05506f02c9 100644 --- a/client/emv/emv_pki.h +++ b/client/emv/emv_pki.h @@ -19,8 +19,6 @@ #include "emv_pk.h" #include "tlv.h" -#include - void PKISetStrictExecution(bool se); unsigned char *emv_pki_sdatl_fill(const struct tlvdb *db, size_t *sdatl_len); diff --git a/client/emv/emv_pki_priv.c b/client/emv/emv_pki_priv.c index 5256b4e378..f10c5352b7 100644 --- a/client/emv/emv_pki_priv.c +++ b/client/emv/emv_pki_priv.c @@ -18,7 +18,6 @@ #endif #include "emv_pki_priv.h" -#include "crypto.h" #include #include diff --git a/client/emv/emv_pki_priv.h b/client/emv/emv_pki_priv.h index 8c8d1a813c..b85b1176b3 100644 --- a/client/emv/emv_pki_priv.h +++ b/client/emv/emv_pki_priv.h @@ -16,12 +16,12 @@ #ifndef EMV_PKI_PRIV_H #define EMV_PKI_PRIV_H +#include "common.h" + #include "crypto.h" #include "emv_pk.h" #include "tlv.h" -#include - struct emv_pk *emv_pki_make_ca(const struct crypto_pk *cp, const unsigned char *rid, unsigned char index, unsigned int expire, enum crypto_algo_hash hash_algo); diff --git a/client/emv/emv_roca.c b/client/emv/emv_roca.c index a3a8cb7fe5..521120b05b 100644 --- a/client/emv/emv_roca.c +++ b/client/emv/emv_roca.c @@ -23,6 +23,9 @@ #include "emv_roca.h" +#include "ui.h" // Print... +#include "mbedtls/bignum.h" + static uint8_t g_primes[ROCA_PRINTS_LENGTH] = { 11, 13, 17, 19, 37, 53, 61, 71, 73, 79, 97, 103, 107, 109, 127, 151, 157 }; diff --git a/client/emv/emv_roca.h b/client/emv/emv_roca.h index 6663ce710e..8c8ea86e4b 100644 --- a/client/emv/emv_roca.h +++ b/client/emv/emv_roca.h @@ -24,10 +24,7 @@ #ifndef EMV_ROCA_H__ #define EMV_ROCA_H__ -#include -#include -#include "mbedtls/bignum.h" -#include "util.h" +#include "common.h" #define ROCA_PRINTS_LENGTH 17 diff --git a/client/emv/emv_tags.c b/client/emv/emv_tags.c index 45202f9e64..72c1fe78e3 100644 --- a/client/emv/emv_tags.c +++ b/client/emv/emv_tags.c @@ -17,13 +17,13 @@ #include #endif -#include "commonutil.h" -#include "tlv.h" #include "emv_tags.h" #include #include +#include "commonutil.h" + #ifndef PRINT_INDENT # define PRINT_INDENT(level) {for (int myi = 0; myi < (level); myi++) fprintf(f, " ");} #endif diff --git a/client/emv/emv_tags.h b/client/emv/emv_tags.h index 51905e75ed..235048b20f 100644 --- a/client/emv/emv_tags.h +++ b/client/emv/emv_tags.h @@ -17,7 +17,7 @@ #define TAGS_H #include "tlv.h" -#include +#include // FILE // AC # define EMVAC_AC_MASK 0xC0 diff --git a/client/emv/emvcore.c b/client/emv/emvcore.c index e44492078f..09dc7883e7 100644 --- a/client/emv/emvcore.c +++ b/client/emv/emvcore.c @@ -9,6 +9,18 @@ //----------------------------------------------------------------------------- #include "emvcore.h" + +#include + +#include "commonutil.h" // ARRAYLEN +#include "comms.h" // DropField +#include "cmdparser.h" +#include "cmdsmartcard.h" // ExchangeAPDUSC +#include "ui.h" +#include "cmdhf14a.h" +#include "dol.h" +#include "dump.h" +#include "emv_tags.h" #include "emvjson.h" #include "util_posix.h" diff --git a/client/emv/emvcore.h b/client/emv/emvcore.h index 3faae283d2..a520a2d5f2 100644 --- a/client/emv/emvcore.h +++ b/client/emv/emvcore.h @@ -11,22 +11,12 @@ #ifndef EMVCORE_H__ #define EMVCORE_H__ -#include -#include -#include +#include "common.h" + #include -#include #include -#include "util.h" -#include "common.h" -#include "ui.h" -#include "cmdhf14a.h" + #include "apduinfo.h" -#include "tlv.h" -#include "dol.h" -#include "dump.h" -#include "emv_tags.h" -#include "emv_pk.h" #include "emv_pki.h" #define APDU_RES_LEN 260 diff --git a/client/emv/emvjson.c b/client/emv/emvjson.c index 67de327011..88d886c6eb 100644 --- a/client/emv/emvjson.c +++ b/client/emv/emvjson.c @@ -9,12 +9,12 @@ //----------------------------------------------------------------------------- #include "emvjson.h" -#include -#include -#include -#include + #include + +#include "commonutil.h" // ARRAYLEN #include "ui.h" +#include "util.h" #include "proxmark3.h" #include "emv_tags.h" diff --git a/client/emv/emvjson.h b/client/emv/emvjson.h index 6bcf8243d3..54d97ada80 100644 --- a/client/emv/emvjson.h +++ b/client/emv/emvjson.h @@ -10,6 +10,8 @@ #ifndef EMVJSON_H__ #define EMVJSON_H__ +#include "common.h" + #include #include "tlv.h" diff --git a/client/emv/test/crypto_test.c b/client/emv/test/crypto_test.c index dcac3f8456..cdf22a9953 100644 --- a/client/emv/test/crypto_test.c +++ b/client/emv/test/crypto_test.c @@ -17,10 +17,11 @@ #include #endif +#include "commonutil.h" // ARRAYLEN + #include "../crypto.h" #include "../dump.h" #include "util_posix.h" -#include "commonutil.h" #include #include diff --git a/client/emv/tlv.c b/client/emv/tlv.c index f3961c7a6c..6e840f9286 100644 --- a/client/emv/tlv.c +++ b/client/emv/tlv.c @@ -22,8 +22,6 @@ #include "tlv.h" #include -#include -#include #include #define TLV_TAG_CLASS_MASK 0xc0 diff --git a/client/emv/tlv.h b/client/emv/tlv.h index 053b313626..06a836876d 100644 --- a/client/emv/tlv.h +++ b/client/emv/tlv.h @@ -18,9 +18,7 @@ #ifndef TLV_H #define TLV_H -#include -#include -#include +#include "common.h" typedef uint32_t tlv_tag_t; diff --git a/client/fido/additional_ca.c b/client/fido/additional_ca.c index 550847e100..21d9d80f68 100644 --- a/client/fido/additional_ca.c +++ b/client/fido/additional_ca.c @@ -10,7 +10,6 @@ // #include "additional_ca.h" -#include "mbedtls/certs.h" #define GLOBALSIGN_CA \ "-----BEGIN CERTIFICATE-----\r\n" \ diff --git a/client/fido/additional_ca.h b/client/fido/additional_ca.h index d0f642e467..689e5f059b 100644 --- a/client/fido/additional_ca.h +++ b/client/fido/additional_ca.h @@ -12,7 +12,7 @@ #ifndef __ADDITIONAL_CA_H__ #define __ADDITIONAL_CA_H__ -#include +#include "common.h" // Concatenation of all CA certificates in PEM format if available extern const char additional_ca_pem[]; diff --git a/client/fido/cbortools.c b/client/fido/cbortools.c index 7cb7fc4568..72cccf429b 100644 --- a/client/fido/cbortools.c +++ b/client/fido/cbortools.c @@ -11,7 +11,9 @@ // #include "cbortools.h" -#include + +#include + #include "emv/emvjson.h" #include "util.h" #include "fidocore.h" diff --git a/client/fido/cbortools.h b/client/fido/cbortools.h index 99b3536c17..96c39ca3bc 100644 --- a/client/fido/cbortools.h +++ b/client/fido/cbortools.h @@ -13,8 +13,7 @@ #ifndef __CBORTOOLS_H__ #define __CBORTOOLS_H__ -#include -#include +#include "common.h" #include #include diff --git a/client/fido/cose.c b/client/fido/cose.c index c62d6cfb3c..f6f20852bb 100644 --- a/client/fido/cose.c +++ b/client/fido/cose.c @@ -11,8 +11,11 @@ // #include "cose.h" -#include + #include "cbortools.h" +#include "commonutil.h" // ARRAYLEN +#include "ui.h" // Print... +#include "util.h" static const char COSEEmptyStr[] = ""; diff --git a/client/fido/cose.h b/client/fido/cose.h index e62054646f..b78f27421e 100644 --- a/client/fido/cose.h +++ b/client/fido/cose.h @@ -13,10 +13,7 @@ #ifndef __COSE_H__ #define __COSE_H__ -#include -#include -#include -#include "util.h" +#include "common.h" const char *GetCOSEAlgName(int id); const char *GetCOSEAlgDescription(int id); diff --git a/client/fido/fidocore.c b/client/fido/fidocore.c index 1611748d8e..8093f45c86 100644 --- a/client/fido/fidocore.c +++ b/client/fido/fidocore.c @@ -11,17 +11,20 @@ // #include "fidocore.h" + +#include "commonutil.h" // ARRAYLEN + #include "emv/emvcore.h" #include "emv/emvjson.h" -#include #include "cbortools.h" -#include -#include -#include +#include "mbedtls/x509_crt.h" #include "crypto/asn1utils.h" #include "crypto/libpcrypto.h" -#include "fido/additional_ca.h" -#include "fido/cose.h" +#include "additional_ca.h" +#include "cose.h" +#include "emv/dump.h" +#include "ui.h" +#include "util.h" typedef struct { uint8_t ErrorCode; diff --git a/client/fido/fidocore.h b/client/fido/fidocore.h index d54dc5b881..56c5631206 100644 --- a/client/fido/fidocore.h +++ b/client/fido/fidocore.h @@ -12,10 +12,10 @@ #ifndef __FIDOCORE_H__ #define __FIDOCORE_H__ -#include -#include +#include "common.h" + #include -#include "cmdhf14a.h" +#include "emv/apduinfo.h" // sAPDU typedef enum { fido2CmdMakeCredential = 0x01, diff --git a/client/flash.c b/client/flash.c index 732d0ef020..ca2f012bb2 100644 --- a/client/flash.c +++ b/client/flash.c @@ -10,6 +10,17 @@ #include "flash.h" +#include +#include +#include + +#include "ui.h" +#include "elf.h" +#include "proxendian.h" +#include "at91sam7s512.h" +#include "util_posix.h" +#include "comms.h" + #define FLASH_START 0x100000 #define BOOTLOADER_SIZE 0x2000 diff --git a/client/flash.h b/client/flash.h index 4f05029dc9..eca4d9ccc1 100644 --- a/client/flash.h +++ b/client/flash.h @@ -9,20 +9,7 @@ #ifndef __FLASH_H__ #define __FLASH_H__ -#include -#include -#include -#include -#include - -#include "proxmark3.h" -#include "elf.h" -#include "proxendian.h" -#include "pm3_cmd.h" -#include "at91sam7s512.h" -#include "util_posix.h" -#include "util.h" -#include "comms.h" +#include "common.h" typedef struct { void *data; diff --git a/client/flasher.c b/client/flasher.c index 97e3d7a1cb..931976997f 100644 --- a/client/flasher.c +++ b/client/flasher.c @@ -6,18 +6,11 @@ // Flasher frontend tool //----------------------------------------------------------------------------- -#include -#include #include -#include -#include #include -#include "util_posix.h" -#include "proxmark3.h" -#include "util.h" +#include "usart_defs.h" #include "flash.h" #include "comms.h" -#include "pm3_cmd.h" #include "ui.h" #define MAX_FILES 4 diff --git a/client/fpga_compress.c b/client/fpga_compress.c index a030afe81a..dfe62d0c87 100644 --- a/client/fpga_compress.c +++ b/client/fpga_compress.c @@ -15,14 +15,10 @@ #include #include #include -#include -#include #include #include "fpga.h" #include "zlib.h" -#define MAX(a,b) ((a)>(b)?(a):(b)) - // zlib configuration #define COMPRESS_LEVEL 9 // use best possible compression #define COMPRESS_WINDOW_BITS 15 // default = max = 15 for a window of 2^15 = 32KBytes diff --git a/client/graph.c b/client/graph.c index 4af3261d27..fc0ceab2d1 100644 --- a/client/graph.c +++ b/client/graph.c @@ -9,6 +9,12 @@ //----------------------------------------------------------------------------- #include "graph.h" +#include +#include "ui.h" +#include "util.h" //param_get32ex +#include "lfdemod.h" +#include "cmddata.h" //for g_debugmode + int GraphBuffer[MAX_GRAPH_TRACE_LEN]; size_t GraphTraceLen; int s_Buff[MAX_GRAPH_TRACE_LEN]; diff --git a/client/graph.h b/client/graph.h index fca93a8896..01b20c7e2a 100644 --- a/client/graph.h +++ b/client/graph.h @@ -10,13 +10,8 @@ #ifndef GRAPH_H__ #define GRAPH_H__ -#include -#include -#include -#include -#include "ui.h" -#include "lfdemod.h" -#include "cmddata.h" //for g_debugmode + +#include "common.h" void AppendGraph(bool redraw, uint16_t clock, int bit); size_t ClearGraph(bool redraw); diff --git a/client/hardnested/hardnested_bf_core.c b/client/hardnested/hardnested_bf_core.c index da9e19db48..adc203f61e 100644 --- a/client/hardnested/hardnested_bf_core.c +++ b/client/hardnested/hardnested_bf_core.c @@ -60,6 +60,7 @@ THE SOFTWARE. #include "crapto1/crapto1.h" #include "parity.h" #include "util.h" +#include "common.h" // bitslice type // while AVX supports 256 bit vector floating point operations, we need integer operations for boolean logic diff --git a/client/hardnested/hardnested_bruteforce.c b/client/hardnested/hardnested_bruteforce.c index 9ecec900ac..5f93d4811b 100644 --- a/client/hardnested/hardnested_bruteforce.c +++ b/client/hardnested/hardnested_bruteforce.c @@ -55,6 +55,8 @@ THE SOFTWARE. #include #include #include + +#include "common.h" #include "proxmark3.h" #include "cmdhfmfhard.h" #include "hardnested_bf_core.h" diff --git a/liblua/Makefile b/client/liblua/Makefile similarity index 100% rename from liblua/Makefile rename to client/liblua/Makefile diff --git a/liblua/lapi.c b/client/liblua/lapi.c similarity index 100% rename from liblua/lapi.c rename to client/liblua/lapi.c diff --git a/liblua/lapi.h b/client/liblua/lapi.h similarity index 100% rename from liblua/lapi.h rename to client/liblua/lapi.h diff --git a/liblua/lauxlib.c b/client/liblua/lauxlib.c similarity index 100% rename from liblua/lauxlib.c rename to client/liblua/lauxlib.c diff --git a/liblua/lauxlib.h b/client/liblua/lauxlib.h similarity index 100% rename from liblua/lauxlib.h rename to client/liblua/lauxlib.h diff --git a/liblua/lbaselib.c b/client/liblua/lbaselib.c similarity index 100% rename from liblua/lbaselib.c rename to client/liblua/lbaselib.c diff --git a/liblua/lbitlib.c b/client/liblua/lbitlib.c similarity index 100% rename from liblua/lbitlib.c rename to client/liblua/lbitlib.c diff --git a/liblua/lcode.c b/client/liblua/lcode.c similarity index 100% rename from liblua/lcode.c rename to client/liblua/lcode.c diff --git a/liblua/lcode.h b/client/liblua/lcode.h similarity index 100% rename from liblua/lcode.h rename to client/liblua/lcode.h diff --git a/liblua/lcorolib.c b/client/liblua/lcorolib.c similarity index 100% rename from liblua/lcorolib.c rename to client/liblua/lcorolib.c diff --git a/liblua/lctype.c b/client/liblua/lctype.c similarity index 100% rename from liblua/lctype.c rename to client/liblua/lctype.c diff --git a/liblua/lctype.h b/client/liblua/lctype.h similarity index 100% rename from liblua/lctype.h rename to client/liblua/lctype.h diff --git a/liblua/ldblib.c b/client/liblua/ldblib.c similarity index 100% rename from liblua/ldblib.c rename to client/liblua/ldblib.c diff --git a/liblua/ldebug.c b/client/liblua/ldebug.c similarity index 100% rename from liblua/ldebug.c rename to client/liblua/ldebug.c diff --git a/liblua/ldebug.h b/client/liblua/ldebug.h similarity index 100% rename from liblua/ldebug.h rename to client/liblua/ldebug.h diff --git a/liblua/ldo.c b/client/liblua/ldo.c similarity index 100% rename from liblua/ldo.c rename to client/liblua/ldo.c diff --git a/liblua/ldo.h b/client/liblua/ldo.h similarity index 100% rename from liblua/ldo.h rename to client/liblua/ldo.h diff --git a/liblua/ldump.c b/client/liblua/ldump.c similarity index 100% rename from liblua/ldump.c rename to client/liblua/ldump.c diff --git a/liblua/lfunc.c b/client/liblua/lfunc.c similarity index 100% rename from liblua/lfunc.c rename to client/liblua/lfunc.c diff --git a/liblua/lfunc.h b/client/liblua/lfunc.h similarity index 100% rename from liblua/lfunc.h rename to client/liblua/lfunc.h diff --git a/liblua/lgc.c b/client/liblua/lgc.c similarity index 100% rename from liblua/lgc.c rename to client/liblua/lgc.c diff --git a/liblua/lgc.h b/client/liblua/lgc.h similarity index 100% rename from liblua/lgc.h rename to client/liblua/lgc.h diff --git a/liblua/linit.c b/client/liblua/linit.c similarity index 100% rename from liblua/linit.c rename to client/liblua/linit.c diff --git a/liblua/liolib.c b/client/liblua/liolib.c similarity index 100% rename from liblua/liolib.c rename to client/liblua/liolib.c diff --git a/liblua/llex.c b/client/liblua/llex.c similarity index 100% rename from liblua/llex.c rename to client/liblua/llex.c diff --git a/liblua/llex.h b/client/liblua/llex.h similarity index 100% rename from liblua/llex.h rename to client/liblua/llex.h diff --git a/liblua/llimits.h b/client/liblua/llimits.h similarity index 100% rename from liblua/llimits.h rename to client/liblua/llimits.h diff --git a/liblua/lmathlib.c b/client/liblua/lmathlib.c similarity index 100% rename from liblua/lmathlib.c rename to client/liblua/lmathlib.c diff --git a/liblua/lmem.c b/client/liblua/lmem.c similarity index 100% rename from liblua/lmem.c rename to client/liblua/lmem.c diff --git a/liblua/lmem.h b/client/liblua/lmem.h similarity index 100% rename from liblua/lmem.h rename to client/liblua/lmem.h diff --git a/liblua/loadlib.c b/client/liblua/loadlib.c similarity index 100% rename from liblua/loadlib.c rename to client/liblua/loadlib.c diff --git a/liblua/lobject.c b/client/liblua/lobject.c similarity index 100% rename from liblua/lobject.c rename to client/liblua/lobject.c diff --git a/liblua/lobject.h b/client/liblua/lobject.h similarity index 100% rename from liblua/lobject.h rename to client/liblua/lobject.h diff --git a/liblua/lopcodes.c b/client/liblua/lopcodes.c similarity index 100% rename from liblua/lopcodes.c rename to client/liblua/lopcodes.c diff --git a/liblua/lopcodes.h b/client/liblua/lopcodes.h similarity index 100% rename from liblua/lopcodes.h rename to client/liblua/lopcodes.h diff --git a/liblua/loslib.c b/client/liblua/loslib.c similarity index 100% rename from liblua/loslib.c rename to client/liblua/loslib.c diff --git a/liblua/lparser.c b/client/liblua/lparser.c similarity index 100% rename from liblua/lparser.c rename to client/liblua/lparser.c diff --git a/liblua/lparser.h b/client/liblua/lparser.h similarity index 100% rename from liblua/lparser.h rename to client/liblua/lparser.h diff --git a/liblua/lstate.c b/client/liblua/lstate.c similarity index 100% rename from liblua/lstate.c rename to client/liblua/lstate.c diff --git a/liblua/lstate.h b/client/liblua/lstate.h similarity index 100% rename from liblua/lstate.h rename to client/liblua/lstate.h diff --git a/liblua/lstring.c b/client/liblua/lstring.c similarity index 100% rename from liblua/lstring.c rename to client/liblua/lstring.c diff --git a/liblua/lstring.h b/client/liblua/lstring.h similarity index 100% rename from liblua/lstring.h rename to client/liblua/lstring.h diff --git a/liblua/lstrlib.c b/client/liblua/lstrlib.c similarity index 100% rename from liblua/lstrlib.c rename to client/liblua/lstrlib.c diff --git a/liblua/ltable.c b/client/liblua/ltable.c similarity index 100% rename from liblua/ltable.c rename to client/liblua/ltable.c diff --git a/liblua/ltable.h b/client/liblua/ltable.h similarity index 100% rename from liblua/ltable.h rename to client/liblua/ltable.h diff --git a/liblua/ltablib.c b/client/liblua/ltablib.c similarity index 100% rename from liblua/ltablib.c rename to client/liblua/ltablib.c diff --git a/liblua/ltm.c b/client/liblua/ltm.c similarity index 100% rename from liblua/ltm.c rename to client/liblua/ltm.c diff --git a/liblua/ltm.h b/client/liblua/ltm.h similarity index 100% rename from liblua/ltm.h rename to client/liblua/ltm.h diff --git a/liblua/lua.c b/client/liblua/lua.c similarity index 100% rename from liblua/lua.c rename to client/liblua/lua.c diff --git a/liblua/lua.h b/client/liblua/lua.h similarity index 100% rename from liblua/lua.h rename to client/liblua/lua.h diff --git a/liblua/lua.hpp b/client/liblua/lua.hpp similarity index 100% rename from liblua/lua.hpp rename to client/liblua/lua.hpp diff --git a/liblua/luac.c b/client/liblua/luac.c similarity index 100% rename from liblua/luac.c rename to client/liblua/luac.c diff --git a/liblua/luaconf.h b/client/liblua/luaconf.h similarity index 100% rename from liblua/luaconf.h rename to client/liblua/luaconf.h diff --git a/liblua/lualib.h b/client/liblua/lualib.h similarity index 100% rename from liblua/lualib.h rename to client/liblua/lualib.h diff --git a/liblua/lundump.c b/client/liblua/lundump.c similarity index 100% rename from liblua/lundump.c rename to client/liblua/lundump.c diff --git a/liblua/lundump.h b/client/liblua/lundump.h similarity index 100% rename from liblua/lundump.h rename to client/liblua/lundump.h diff --git a/liblua/lvm.c b/client/liblua/lvm.c similarity index 100% rename from liblua/lvm.c rename to client/liblua/lvm.c diff --git a/liblua/lvm.h b/client/liblua/lvm.h similarity index 100% rename from liblua/lvm.h rename to client/liblua/lvm.h diff --git a/liblua/lzio.c b/client/liblua/lzio.c similarity index 100% rename from liblua/lzio.c rename to client/liblua/lzio.c diff --git a/liblua/lzio.h b/client/liblua/lzio.h similarity index 100% rename from liblua/lzio.h rename to client/liblua/lzio.h diff --git a/client/loclass/cipher.c b/client/loclass/cipher.c index fe676e83d3..931f0c8450 100644 --- a/client/loclass/cipher.c +++ b/client/loclass/cipher.c @@ -250,7 +250,7 @@ void doMAC_N(uint8_t *address_data_p, uint8_t address_data_size, uint8_t *div_ke #ifndef ON_DEVICE int testMAC() { - PrintAndLogDevice(SUCCESS, "Testing MAC calculation..."); + PrintAndLogEx(SUCCESS, "Testing MAC calculation..."); //From the "dismantling.IClass" paper: uint8_t cc_nr[] = {0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0, 0, 0, 0}; @@ -262,9 +262,9 @@ int testMAC() { doMAC(cc_nr, div_key, calculated_mac); if (memcmp(calculated_mac, correct_MAC, 4) == 0) { - PrintAndLogDevice(SUCCESS, "MAC calculation OK!"); + PrintAndLogEx(SUCCESS, "MAC calculation OK!"); } else { - PrintAndLogDevice(FAILED, "FAILED: MAC calculation failed:"); + PrintAndLogEx(FAILED, "FAILED: MAC calculation failed:"); printarr(" Calculated_MAC", calculated_mac, 4); printarr(" Correct_MAC ", correct_MAC, 4); return 1; diff --git a/client/loclass/cipherutils.c b/client/loclass/cipherutils.c index b6bea61869..b11f6883a2 100644 --- a/client/loclass/cipherutils.c +++ b/client/loclass/cipherutils.c @@ -34,12 +34,15 @@ * * ****************************************************************************/ +#include "cipherutils.h" #include #include #include + +#include "commonutil.h" // ARRAYLEN + #include "fileutils.h" -#include "cipherutils.h" /** * * @brief Return and remove the first bit (x0) in the stream : @@ -152,7 +155,7 @@ void printarr(const char *name, uint8_t *arr, int len) { cx += snprintf(output + cx, outsize - cx, "0x%02x,", *(arr + i)); //5 bytes per byte } snprintf(output + cx, outsize - cx, "};"); - PrintAndLogDevice(NORMAL, output); + PrintAndLogEx(NORMAL, output); free(output); } @@ -165,7 +168,7 @@ void printvar(const char *name, uint8_t *arr, int len) { cx += snprintf(output + cx, outsize - cx, "%02x", *(arr + i)); //2 bytes per byte } - PrintAndLogDevice(NORMAL, output); + PrintAndLogEx(NORMAL, output); free(output); } @@ -179,7 +182,7 @@ void printarr_human_readable(const char *title, uint8_t *arr, int len) { cx += snprintf(output + cx, outsize - cx, "\n%02x| ", i); cx += snprintf(output + cx, outsize - cx, "%02x ", *(arr + i)); } - PrintAndLogDevice(NORMAL, output); + PrintAndLogEx(NORMAL, output); free(output); } @@ -201,12 +204,12 @@ static int testBitStream() { } if (memcmp(input, output, sizeof(input)) == 0) { - PrintAndLogDevice(SUCCESS, " Bitstream test 1 ok"); + PrintAndLogEx(SUCCESS, " Bitstream test 1 ok"); } else { - PrintAndLogDevice(FAILED, " Bitstream test 1 failed"); + PrintAndLogEx(FAILED, " Bitstream test 1 failed"); uint8_t i; for (i = 0 ; i < ARRAYLEN(input) ; i++) { - PrintAndLogDevice(NORMAL, " IN %02x, OUT %02x", input[i], output[i]); + PrintAndLogEx(NORMAL, " IN %02x, OUT %02x", input[i], output[i]); } return 1; } @@ -231,12 +234,12 @@ static int testReversedBitstream() { } if (memcmp(input, output, sizeof(input)) == 0) { - PrintAndLogDevice(SUCCESS, " Bitstream test 2 ok"); + PrintAndLogEx(SUCCESS, " Bitstream test 2 ok"); } else { - PrintAndLogDevice(FAILED, " Bitstream test 2 failed"); + PrintAndLogEx(FAILED, " Bitstream test 2 failed"); uint8_t i; for (i = 0 ; i < ARRAYLEN(input) ; i++) { - PrintAndLogDevice(NORMAL, " IN %02x, MIDDLE: %02x, OUT %02x", input[i], reverse[i], output[i]); + PrintAndLogEx(NORMAL, " IN %02x, MIDDLE: %02x, OUT %02x", input[i], reverse[i], output[i]); } return 1; } @@ -245,7 +248,7 @@ static int testReversedBitstream() { int testCipherUtils(void) { - PrintAndLogDevice(INFO, "Testing some internals..."); + PrintAndLogEx(INFO, "Testing some internals..."); int retval = 0; retval |= testBitStream(); retval |= testReversedBitstream(); diff --git a/client/loclass/elite_crack.c b/client/loclass/elite_crack.c index 5b019d8e00..a4296f4764 100644 --- a/client/loclass/elite_crack.c +++ b/client/loclass/elite_crack.c @@ -221,7 +221,7 @@ void hash2(uint8_t *key64, uint8_t *outp_keytable) { // Once again, key is on iclass-format desencrypt_iclass(key64, key64_negated, z[0]); -// PrintAndLogDevice(NORMAL, "\n"); PrintAndLogDevice(NORMAL, "High security custom key (Kcus):"); +// PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(NORMAL, "High security custom key (Kcus):"); // printvar("z0 ", z[0],8); uint8_t y[8][8] = {{0}, {0}}; @@ -325,10 +325,10 @@ int bruteforceItem(dumpdata item, uint16_t keytable[]) { keytable[key_index[i]] |= BEING_CRACKED; if (numbytes_to_recover > 3) { - PrintAndLogDevice(FAILED, "The CSN requires > 3 byte bruteforce, not supported"); + PrintAndLogEx(FAILED, "The CSN requires > 3 byte bruteforce, not supported"); printvar("[-] CSN", item.csn, 8); printvar("[-] HASH1", key_index, 8); - PrintAndLogDevice(NORMAL, ""); + PrintAndLogEx(NORMAL, ""); //Before we exit, reset the 'BEING_CRACKED' to zero keytable[bytes_to_recover[0]] &= ~BEING_CRACKED; keytable[bytes_to_recover[1]] &= ~BEING_CRACKED; @@ -351,9 +351,9 @@ int bruteforceItem(dumpdata item, uint16_t keytable[]) { */ uint32_t endmask = 1 << 8 * numbytes_to_recover; - PrintAndLogDevice(NORMAL, "----------------------------"); + PrintAndLogEx(NORMAL, "----------------------------"); for (i = 0 ; i < numbytes_to_recover && numbytes_to_recover > 1; i++) - PrintAndLogDevice(INFO, "Bruteforcing byte %d", bytes_to_recover[i]); + PrintAndLogEx(INFO, "Bruteforcing byte %d", bytes_to_recover[i]); while (!found && !(brute & endmask)) { @@ -384,7 +384,7 @@ int bruteforceItem(dumpdata item, uint16_t keytable[]) { if (memcmp(calculated_MAC, item.mac, 4) == 0) { printf("\r\n"); for (i = 0 ; i < numbytes_to_recover; i++) { - PrintAndLogDevice(INFO, "%d: 0x%02x", bytes_to_recover[i], 0xFF & keytable[bytes_to_recover[i]]); + PrintAndLogEx(INFO, "%d: 0x%02x", bytes_to_recover[i], 0xFF & keytable[bytes_to_recover[i]]); } found = true; break; @@ -400,8 +400,8 @@ int bruteforceItem(dumpdata item, uint16_t keytable[]) { } if (!found) { - PrintAndLogDevice(NORMAL, "\n"); - PrintAndLogDevice(WARNING, "Failed to recover %d bytes using the following CSN", numbytes_to_recover); + PrintAndLogEx(NORMAL, "\n"); + PrintAndLogEx(WARNING, "Failed to recover %d bytes using the following CSN", numbytes_to_recover); printvar("[!] CSN", item.csn, 8); errors++; @@ -411,7 +411,7 @@ int bruteforceItem(dumpdata item, uint16_t keytable[]) { keytable[bytes_to_recover[i]] |= CRACK_FAILED; } } else { - //PrintAndLogDevice(SUCCESS, "DES calcs: %u", brute); + //PrintAndLogEx(SUCCESS, "DES calcs: %u", brute); for (i = 0; i < numbytes_to_recover; i++) { keytable[bytes_to_recover[i]] &= 0xFF; keytable[bytes_to_recover[i]] |= CRACKED; @@ -466,8 +466,8 @@ int calculateMasterKey(uint8_t first16bytes[], uint64_t master_key[]) { mbedtls_des_setkey_enc(&ctx_e, key64_stdformat); mbedtls_des_crypt_ecb(&ctx_e, key64_negated, result); - PrintAndLogDevice(NORMAL, "\n"); - PrintAndLogDevice(SUCCESS, "-- High security custom key (Kcus) --"); + PrintAndLogEx(NORMAL, "\n"); + PrintAndLogEx(SUCCESS, "-- High security custom key (Kcus) --"); printvar("[+] Standard format ", key64_stdformat, 8); printvar("[+] iClass format ", key64, 8); @@ -475,11 +475,11 @@ int calculateMasterKey(uint8_t first16bytes[], uint64_t master_key[]) { memcpy(master_key, key64, 8); if (memcmp(z_0, result, 4) != 0) { - PrintAndLogDevice(WARNING, "Failed to verify calculated master key (k_cus)! Something is wrong."); + PrintAndLogEx(WARNING, "Failed to verify calculated master key (k_cus)! Something is wrong."); return 1; } else { - PrintAndLogDevice(NORMAL, "\n"); - PrintAndLogDevice(SUCCESS, "Key verified ok!\n"); + PrintAndLogEx(NORMAL, "\n"); + PrintAndLogEx(SUCCESS, "Key verified ok!\n"); } return 0; } @@ -505,7 +505,7 @@ int bruteforceDump(uint8_t dump[], size_t dumpsize, uint16_t keytable[]) { } free(attack); t1 = msclock() - t1; - PrintAndLogDevice(SUCCESS, "time: %" PRIu64 " seconds", t1 / 1000); + PrintAndLogEx(SUCCESS, "time: %" PRIu64 " seconds", t1 / 1000); // Pick out the first 16 bytes of the keytable. // The keytable is now in 16-bit ints, where the upper 8 bits @@ -517,7 +517,7 @@ int bruteforceDump(uint8_t dump[], size_t dumpsize, uint16_t keytable[]) { first16bytes[i] = keytable[i] & 0xFF; if (!(keytable[i] & CRACKED)) - PrintAndLogDevice(WARNING, "Warning: we are missing byte %d, custom key calculation will fail...", i); + PrintAndLogEx(WARNING, "Warning: we are missing byte %d, custom key calculation will fail...", i); } errors += calculateMasterKey(first16bytes, NULL); return errors; @@ -532,7 +532,7 @@ int bruteforceDump(uint8_t dump[], size_t dumpsize, uint16_t keytable[]) { int bruteforceFile(const char *filename, uint16_t keytable[]) { FILE *f = fopen(filename, "rb"); if (!f) { - PrintAndLogDevice(WARNING, "Failed to read from file '%s'", filename); + PrintAndLogEx(WARNING, "Failed to read from file '%s'", filename); return 1; } @@ -541,14 +541,14 @@ int bruteforceFile(const char *filename, uint16_t keytable[]) { fseek(f, 0, SEEK_SET); if (fsize <= 0) { - PrintAndLogDevice(ERR, "Error, when getting filesize"); + PrintAndLogEx(ERR, "Error, when getting filesize"); fclose(f); return 1; } uint8_t *dump = calloc(fsize, sizeof(uint8_t)); if (!dump) { - PrintAndLogDevice(WARNING, "Failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); fclose(f); return 2; } @@ -557,7 +557,7 @@ int bruteforceFile(const char *filename, uint16_t keytable[]) { fclose(f); if (bytes_read < fsize) { - PrintAndLogDevice(WARNING, "Warning: could only read %d bytes (should be %d)", bytes_read, fsize); + PrintAndLogEx(WARNING, "Warning: could only read %d bytes (should be %d)", bytes_read, fsize); } uint8_t res = bruteforceDump(dump, fsize, keytable); @@ -585,7 +585,7 @@ static int _testBruteforce() { int errors = 0; if (true) { // First test - PrintAndLogDevice(INFO, "Testing crack from dumpfile..."); + PrintAndLogEx(INFO, "Testing crack from dumpfile..."); /** Expected values for the dumpfile: @@ -612,7 +612,7 @@ static int _testBruteforce() { } else if (fileExists("client/loclass/iclass_dump.bin")) { errors |= bruteforceFile("client/loclass/iclass_dump.bin", keytable); } else { - PrintAndLogDevice(ERR, "Error: The file iclass_dump.bin was not found!"); + PrintAndLogEx(ERR, "Error: The file iclass_dump.bin was not found!"); } } return errors; @@ -627,20 +627,20 @@ static int _test_iclass_key_permutation() { permutekey_rev(testcase_output, testcase_output_rev); if (memcmp(testcase_output, testcase_output_correct, 8) != 0) { - PrintAndLogDevice(ERR, "Error with iclass key permute!"); + PrintAndLogEx(ERR, "Error with iclass key permute!"); printarr("testcase_output", testcase_output, 8); printarr("testcase_output_correct", testcase_output_correct, 8); return 1; } if (memcmp(testcase, testcase_output_rev, 8) != 0) { - PrintAndLogDevice(ERR, "Error with reverse iclass key permute"); + PrintAndLogEx(ERR, "Error with reverse iclass key permute"); printarr("testcase", testcase, 8); printarr("testcase_output_rev", testcase_output_rev, 8); return 1; } - PrintAndLogDevice(SUCCESS, "Iclass key permutation OK!"); + PrintAndLogEx(SUCCESS, "Iclass key permutation OK!"); return 0; } @@ -651,7 +651,7 @@ static int _testHash1() { hash1(csn, k); if (memcmp(k, expected, 8) != 0) { - PrintAndLogDevice(ERR, "Error with hash1!"); + PrintAndLogEx(ERR, "Error with hash1!"); printarr("calculated", k, 8); printarr("expected", expected, 8); return 1; @@ -660,8 +660,8 @@ static int _testHash1() { } int testElite() { - PrintAndLogDevice(INFO, "Testing iClass Elite functinality..."); - PrintAndLogDevice(INFO, "Testing hash2"); + PrintAndLogEx(INFO, "Testing iClass Elite functinality..."); + PrintAndLogEx(INFO, "Testing hash2"); uint8_t k_cus[8] = {0x5B, 0x7C, 0x62, 0xC4, 0x91, 0xC1, 0x1B, 0x39}; /** @@ -683,13 +683,13 @@ int testElite() { hash2(k_cus, keytable); printarr_human_readable("Hash2", keytable, 128); if (keytable[3] == 0xA1 && keytable[0x30] == 0xA3 && keytable[0x6F] == 0x95) { - PrintAndLogDevice(SUCCESS, "Hash2 looks fine..."); + PrintAndLogEx(SUCCESS, "Hash2 looks fine..."); } int errors = 0 ; - PrintAndLogDevice(INFO, "Testing hash1..."); + PrintAndLogEx(INFO, "Testing hash1..."); errors += _testHash1(); - PrintAndLogDevice(INFO, "Testing key diversification ..."); + PrintAndLogEx(INFO, "Testing key diversification ..."); errors += _test_iclass_key_permutation(); errors += _testBruteforce(); return errors; diff --git a/client/loclass/fileutils.c b/client/loclass/fileutils.c index cb16a7fa31..b899253347 100644 --- a/client/loclass/fileutils.c +++ b/client/loclass/fileutils.c @@ -36,6 +36,13 @@ ****************************************************************************/ #include "fileutils.h" +#include + +#include "pm3_cmd.h" +#include "commonutil.h" +#include "util.h" + + #ifndef ON_DEVICE #define PATH_MAX_LENGTH 100 @@ -100,14 +107,14 @@ int saveFile(const char *preferredName, const char *suffix, const void *data, si /*Opening file for writing in binary mode*/ FILE *f = fopen(fileName, "wb"); if (!f) { - PrintAndLogDevice(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", fileName); + PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", fileName); free(fileName); return PM3_EFILE; } fwrite(data, 1, datalen, f); fflush(f); fclose(f); - PrintAndLogDevice(SUCCESS, "saved %u bytes to binary file " _YELLOW_("%s"), datalen, fileName); + PrintAndLogEx(SUCCESS, "saved %u bytes to binary file " _YELLOW_("%s"), datalen, fileName); free(fileName); return PM3_SUCCESS; } @@ -127,7 +134,7 @@ int saveFileEML(const char *preferredName, uint8_t *data, size_t datalen, size_t /*Opening file for writing in text mode*/ FILE *f = fopen(fileName, "w+"); if (!f) { - PrintAndLogDevice(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", fileName); + PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", fileName); retval = PM3_EFILE; goto out; } @@ -150,7 +157,7 @@ int saveFileEML(const char *preferredName, uint8_t *data, size_t datalen, size_t } fflush(f); fclose(f); - PrintAndLogDevice(SUCCESS, "saved %d blocks to text file " _YELLOW_("%s"), blocks, fileName); + PrintAndLogEx(SUCCESS, "saved %d blocks to text file " _YELLOW_("%s"), blocks, fileName); out: free(fileName); @@ -273,12 +280,12 @@ int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, s int res = json_dump_file(root, fileName, JSON_INDENT(2)); if (res) { - PrintAndLogDevice(FAILED, "error: can't save the file: " _YELLOW_("%s"), fileName); + PrintAndLogEx(FAILED, "error: can't save the file: " _YELLOW_("%s"), fileName); json_decref(root); retval = 200; goto out; } - PrintAndLogDevice(SUCCESS, "saved to json file " _YELLOW_("%s"), fileName); + PrintAndLogEx(SUCCESS, "saved to json file " _YELLOW_("%s"), fileName); json_decref(root); out: @@ -296,7 +303,7 @@ int loadFile(const char *preferredName, const char *suffix, void *data, size_t m FILE *f = fopen(fileName, "rb"); if (!f) { - PrintAndLogDevice(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", fileName); + PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", fileName); free(fileName); return PM3_EFILE; } @@ -307,14 +314,14 @@ int loadFile(const char *preferredName, const char *suffix, void *data, size_t m fseek(f, 0, SEEK_SET); if (fsize <= 0) { - PrintAndLogDevice(FAILED, "error, when getting filesize"); + PrintAndLogEx(FAILED, "error, when getting filesize"); retval = 1; goto out; } uint8_t *dump = calloc(fsize, sizeof(uint8_t)); if (!dump) { - PrintAndLogDevice(FAILED, "error, cannot allocate memory"); + PrintAndLogEx(FAILED, "error, cannot allocate memory"); retval = 2; goto out; } @@ -322,21 +329,21 @@ int loadFile(const char *preferredName, const char *suffix, void *data, size_t m size_t bytes_read = fread(dump, 1, fsize, f); if (bytes_read != fsize) { - PrintAndLogDevice(FAILED, "error, bytes read mismatch file size"); + PrintAndLogEx(FAILED, "error, bytes read mismatch file size"); free(dump); retval = 3; goto out; } if (bytes_read > maxdatalen) { - PrintAndLogDevice(WARNING, "Warning, bytes read exceed calling array limit. Max bytes is %d bytes", maxdatalen); + PrintAndLogEx(WARNING, "Warning, bytes read exceed calling array limit. Max bytes is %d bytes", maxdatalen); bytes_read = maxdatalen; } memcpy((data), dump, bytes_read); free(dump); - PrintAndLogDevice(SUCCESS, "loaded %d bytes from binary file " _YELLOW_("%s"), bytes_read, fileName); + PrintAndLogEx(SUCCESS, "loaded %d bytes from binary file " _YELLOW_("%s"), bytes_read, fileName); *datalen = bytes_read; @@ -358,7 +365,7 @@ int loadFileEML(const char *preferredName, void *data, size_t *datalen) { FILE *f = fopen(fileName, "r"); if (!f) { - PrintAndLogDevice(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", fileName); + PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", fileName); retval = PM3_EFILE; goto out; } @@ -391,7 +398,7 @@ int loadFileEML(const char *preferredName, void *data, size_t *datalen) { } } fclose(f); - PrintAndLogDevice(SUCCESS, "loaded %d bytes from text file " _YELLOW_("%s"), counter, fileName); + PrintAndLogEx(SUCCESS, "loaded %d bytes from text file " _YELLOW_("%s"), counter, fileName); if (datalen) *datalen = counter; @@ -532,7 +539,7 @@ int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, u FILE *f = fopen(fileName, "r"); if (!f) { - PrintAndLogDevice(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", fileName); + PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", fileName); retval = PM3_EFILE; goto out; } @@ -564,7 +571,7 @@ int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, u counter += (keylen >> 1); } fclose(f); - PrintAndLogDevice(SUCCESS, "loaded " _GREEN_("%2d") "keys from dictionary file " _YELLOW_("%s"), *keycnt, fileName); + PrintAndLogEx(SUCCESS, "loaded " _GREEN_("%2d") "keys from dictionary file " _YELLOW_("%s"), *keycnt, fileName); if (datalen) *datalen = counter; @@ -601,7 +608,7 @@ int convertOldMfuDump(uint8_t **dump, size_t *dumplen) { *dumplen = new_dump_len; free(*dump); *dump = (uint8_t *) mfu_dump; - PrintAndLogDevice(SUCCESS, "old mfu dump format, was converted on load to " _GREEN_("%d") " pages", mfu_dump->pages + 1); + PrintAndLogEx(SUCCESS, "old mfu dump format, was converted on load to " _GREEN_("%d") " pages", mfu_dump->pages + 1); return PM3_SUCCESS; } diff --git a/client/loclass/fileutils.h b/client/loclass/fileutils.h index dae23a1b1b..74d54000ba 100644 --- a/client/loclass/fileutils.h +++ b/client/loclass/fileutils.h @@ -162,7 +162,7 @@ int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, u */ int convertOldMfuDump(uint8_t **dump, size_t *dumplen); -#define PrintAndLogDevice(level, format, args...) PrintAndLogEx(level, format , ## args) +#define PrintAndLogEx(level, format, args...) PrintAndLogEx(level, format , ## args) #else /** @@ -172,7 +172,7 @@ int convertOldMfuDump(uint8_t **dump, size_t *dumplen); * write also to a logfile. When doing so, just point this function to use PrintAndLog * @param fmt */ -#define PrintAndLogDevice(level, format, args...) { } +#define PrintAndLogEx(level, format, args...) { } diff --git a/client/loclass/ikeys.c b/client/loclass/ikeys.c index 67278e3b52..53f7848def 100644 --- a/client/loclass/ikeys.c +++ b/client/loclass/ikeys.c @@ -63,6 +63,9 @@ From "Dismantling iclass": #include #include #include + +#include "commonutil.h" // ARRAYLEN + #include "fileutils.h" #include "cipherutils.h" #include "mbedtls/des.h" @@ -218,7 +221,7 @@ static void printbegin() { if (debug_print < 2) return; - PrintAndLogDevice(NORMAL, " | x| y|z0|z1|z2|z3|z4|z5|z6|z7|"); + PrintAndLogEx(NORMAL, " | x| y|z0|z1|z2|z3|z4|z5|z6|z7|"); } static void printState(const char *desc, uint64_t c) { @@ -281,7 +284,7 @@ void hash0(uint64_t c, uint8_t k[8]) { if (x & 1) //Check if x7 is 1 p = ~p; - if (debug_print >= 2) PrintAndLogDevice(DEBUG, "p:%02x", p); + if (debug_print >= 2) PrintAndLogEx(DEBUG, "p:%02x", p); BitstreamIn p_in = { &p, 8, 0 }; uint8_t outbuffer[] = {0, 0, 0, 0, 0, 0, 0, 0}; @@ -426,7 +429,7 @@ static int testDES(Testcase testcase, mbedtls_des_context ctx_enc, mbedtls_des_c if (memcmp(testcase.uid, decrypted, 8) != 0) { //Decryption fail - PrintAndLogDevice(FAILED, "Encryption <-> Decryption FAIL"); + PrintAndLogEx(FAILED, "Encryption <-> Decryption FAIL"); printarr("Input", testcase.uid, 8); printarr("Decrypted", decrypted, 8); retval = 1; @@ -434,7 +437,7 @@ static int testDES(Testcase testcase, mbedtls_des_context ctx_enc, mbedtls_des_c if (memcmp(des_encrypted_csn, testcase.t_key, 8) != 0) { //Encryption fail - PrintAndLogDevice(FAILED, "Encryption != Expected result"); + PrintAndLogEx(FAILED, "Encryption != Expected result"); printarr("Output", des_encrypted_csn, 8); printarr("Expected", testcase.t_key, 8); retval = 1; @@ -444,7 +447,7 @@ static int testDES(Testcase testcase, mbedtls_des_context ctx_enc, mbedtls_des_c if (memcmp(div_key, testcase.div_key, 8) != 0) { //Key diversification fail - PrintAndLogDevice(FAILED, "Div key != expected result"); + PrintAndLogEx(FAILED, "Div key != expected result"); printarr(" csn ", testcase.uid, 8); printarr("{csn} ", des_encrypted_csn, 8); printarr("hash0 ", div_key, 8); @@ -469,13 +472,13 @@ static void des_checkParity(uint8_t *key) { bool parity = des_getParityBitFromKey(key[i]); if (parity != (key[i] & 0x1)) { fails++; - PrintAndLogDevice(FAILED, "parity1 fail, byte %d [%02x] was %d, should be %d", i, key[i], (key[i] & 0x1), parity); + PrintAndLogEx(FAILED, "parity1 fail, byte %d [%02x] was %d, should be %d", i, key[i], (key[i] & 0x1), parity); } } if (fails) { - PrintAndLogDevice(FAILED, "parity fails: %d", fails); + PrintAndLogEx(FAILED, "parity fails: %d", fails); } else { - PrintAndLogDevice(SUCCESS, "Key syntax is with parity bits inside each byte"); + PrintAndLogEx(SUCCESS, "Key syntax is with parity bits inside each byte"); } } @@ -554,15 +557,15 @@ static int testKeyDiversificationWithMasterkeyTestcases() { int i, error = 0; uint8_t empty[8] = {0}; - PrintAndLogDevice(INFO, "Testing encryption/decryption"); + PrintAndLogEx(INFO, "Testing encryption/decryption"); for (i = 0; memcmp(testcases + i, empty, 8); i++) error += testDES(testcases[i], ctx_enc, ctx_dec); if (error) - PrintAndLogDevice(FAILED, "%d errors occurred (%d testcases)", error, i); + PrintAndLogEx(FAILED, "%d errors occurred (%d testcases)", error, i); else - PrintAndLogDevice(SUCCESS, "Hashing seems to work (%d testcases)", i); + PrintAndLogEx(SUCCESS, "Hashing seems to work (%d testcases)", i); return error; } @@ -573,7 +576,7 @@ static void print64bits(const char *name, uint64_t val) { static uint64_t testCryptedCSN(uint64_t crypted_csn, uint64_t expected) { int retval = 0; uint8_t result[8] = {0}; - if (debug_print) PrintAndLogDevice(DEBUG, "debug_print %d", debug_print); + if (debug_print) PrintAndLogEx(DEBUG, "debug_print %d", debug_print); if (debug_print) print64bits(" {csn} ", crypted_csn); uint64_t crypted_csn_swapped = swapZvalues(crypted_csn); @@ -586,13 +589,13 @@ static uint64_t testCryptedCSN(uint64_t crypted_csn, uint64_t expected) { if (resultbyte != expected) { if (debug_print) { - PrintAndLogDevice(NORMAL, "\n"); - PrintAndLogDevice(FAILED, "FAIL!"); + PrintAndLogEx(NORMAL, "\n"); + PrintAndLogEx(FAILED, "FAIL!"); print64bits(" expected ", expected); } retval = 1; } else { - if (debug_print) PrintAndLogDevice(SUCCESS, "[OK]"); + if (debug_print) PrintAndLogEx(SUCCESS, "[OK]"); } return retval; } @@ -611,7 +614,7 @@ static int testDES2(uint64_t csn, uint64_t expected) { print64bits(" expected ", expected); if (expected == crypt_csn) { - PrintAndLogDevice(SUCCESS, "OK"); + PrintAndLogEx(SUCCESS, "OK"); return 0; } else { return 1; @@ -626,13 +629,13 @@ static int testDES2(uint64_t csn, uint64_t expected) { static int doTestsWithKnownInputs() { // KSel from http://www.proxmark.org/forum/viewtopic.php?pid=10977#p10977 int errors = 0; - PrintAndLogDevice(SUCCESS, "Testing DES encryption"); + PrintAndLogEx(SUCCESS, "Testing DES encryption"); uint8_t key[8] = {0x6c, 0x8d, 0x44, 0xf9, 0x2a, 0x2d, 0x01, 0xbf}; mbedtls_des_setkey_enc(&ctx_enc, key); testDES2(0xbbbbaaaabbbbeeee, 0xd6ad3ca619659e6b); - PrintAndLogDevice(SUCCESS, "Testing hashing algorithm"); + PrintAndLogEx(SUCCESS, "Testing hashing algorithm"); errors += testCryptedCSN(0x0102030405060708, 0x0bdd6512073c460a); errors += testCryptedCSN(0x1020304050607080, 0x0208211405f3381f); @@ -645,9 +648,9 @@ static int doTestsWithKnownInputs() { errors += testCryptedCSN(0x14e2adfc5bb7e134, 0x6ac90c6508bd9ea3); if (errors) - PrintAndLogDevice(FAILED, "%d errors occurred (9 testcases)", errors); + PrintAndLogEx(FAILED, "%d errors occurred (9 testcases)", errors); else - PrintAndLogDevice(SUCCESS, "Hashing seems to work (9 testcases)"); + PrintAndLogEx(SUCCESS, "Hashing seems to work (9 testcases)"); return errors; } @@ -683,10 +686,10 @@ static bool readKeyFile(uint8_t key[8]) { int doKeyTests(uint8_t debuglevel) { debug_print = debuglevel; - PrintAndLogDevice(INFO, "Checking if the master key is present (iclass_key.bin)..."); + PrintAndLogEx(INFO, "Checking if the master key is present (iclass_key.bin)..."); uint8_t key[8] = {0}; if (!readKeyFile(key)) { - PrintAndLogDevice(FAILED, "Master key not present, will not be able to do all testcases"); + PrintAndLogEx(FAILED, "Master key not present, will not be able to do all testcases"); } else { //Test if it's the right key... @@ -696,19 +699,19 @@ int doKeyTests(uint8_t debuglevel) { j += key[i]; if (j != 185) { - PrintAndLogDevice(INFO, "A key was loaded, but it does not seem to be the correct one. Aborting these tests"); + PrintAndLogEx(INFO, "A key was loaded, but it does not seem to be the correct one. Aborting these tests"); } else { - PrintAndLogDevice(SUCCESS, "Key present"); - PrintAndLogDevice(SUCCESS, "Checking key parity..."); + PrintAndLogEx(SUCCESS, "Key present"); + PrintAndLogEx(SUCCESS, "Checking key parity..."); des_checkParity(key); mbedtls_des_setkey_enc(&ctx_enc, key); mbedtls_des_setkey_dec(&ctx_dec, key); // Test hashing functions - PrintAndLogDevice(SUCCESS, "The following tests require the correct 8-byte master key"); + PrintAndLogEx(SUCCESS, "The following tests require the correct 8-byte master key"); testKeyDiversificationWithMasterkeyTestcases(); } } - PrintAndLogDevice(SUCCESS, "Testing key diversification with non-sensitive keys..."); + PrintAndLogEx(SUCCESS, "Testing key diversification with non-sensitive keys..."); doTestsWithKnownInputs(); return 0; } diff --git a/client/mifare/mad.c b/client/mifare/mad.c index 47b7cb70a1..5cf3e18528 100644 --- a/client/mifare/mad.c +++ b/client/mifare/mad.c @@ -10,6 +10,8 @@ #include "mad.h" #include "ui.h" +#include "commonutil.h" // ARRAYLEN + #include "crc.h" #include "util.h" diff --git a/client/mifare/mad.h b/client/mifare/mad.h index d1028e06ac..ce5ed4131f 100644 --- a/client/mifare/mad.h +++ b/client/mifare/mad.h @@ -11,9 +11,7 @@ #ifndef _MAD_H_ #define _MAD_H_ -#include -#include -#include +#include "common.h" typedef struct { uint16_t AID; diff --git a/client/mifare/mfkey.c b/client/mifare/mfkey.c index 178da7fe4f..bdccd302ee 100644 --- a/client/mifare/mfkey.c +++ b/client/mifare/mfkey.c @@ -11,6 +11,8 @@ //----------------------------------------------------------------------------- #include "mfkey.h" +#include "crapto1/crapto1.h" + // MIFARE int compare_uint64(const void *a, const void *b) { if (*(uint64_t *)b == *(uint64_t *)a) return 0; diff --git a/client/mifare/mfkey.h b/client/mifare/mfkey.h index 4af5175a1c..36ca8ed11e 100644 --- a/client/mifare/mfkey.h +++ b/client/mifare/mfkey.h @@ -13,11 +13,8 @@ #ifndef MFKEY_H #define MFKEY_H -#include -#include -#include +#include "common.h" #include "mifare.h" -#include "crapto1/crapto1.h" uint32_t nonce2key(uint32_t uid, uint32_t nt, uint32_t nr, uint32_t ar, uint64_t par_info, uint64_t ks_info, uint64_t **keys); bool mfkey32(nonces_t data, uint64_t *outputkey); diff --git a/client/mifare/mifare4.c b/client/mifare/mifare4.c index 486dfd3715..5cdca2e143 100644 --- a/client/mifare/mifare4.c +++ b/client/mifare/mifare4.c @@ -10,10 +10,10 @@ //----------------------------------------------------------------------------- #include "mifare4.h" -#include #include +#include "commonutil.h" // ARRAYLEN +#include "comms.h" // DropField #include "cmdhf14a.h" -#include "util.h" #include "ui.h" #include "crypto/libpcrypto.h" diff --git a/client/mifare/mifare4.h b/client/mifare/mifare4.h index 330c6d9f9b..31eac1fdb7 100644 --- a/client/mifare/mifare4.h +++ b/client/mifare/mifare4.h @@ -12,9 +12,7 @@ #ifndef MIFARE4_H #define MIFARE4_H -#include -#include -#include +#include "common.h" typedef struct { bool Authenticated; diff --git a/client/mifare/mifaredefault.h b/client/mifare/mifaredefault.h index 4123fdf70b..7232510a02 100644 --- a/client/mifare/mifaredefault.h +++ b/client/mifare/mifaredefault.h @@ -11,7 +11,7 @@ #ifndef MIFAREDEFAULT_H__ #define MIFAREDEFAULT_H__ -#include +#include "common.h" static const uint64_t g_mifare_default_keys[] = { 0xffffffffffff, // Default key (first key used by program if no user defined key) diff --git a/client/mifare/mifarehost.c b/client/mifare/mifarehost.c index ff63004e97..f7c7ce4f24 100644 --- a/client/mifare/mifarehost.c +++ b/client/mifare/mifarehost.c @@ -8,7 +8,22 @@ // mifare commands //----------------------------------------------------------------------------- #include "mifarehost.h" -#include "cmdmain.h" + +#include +#include +#include +#include + +#include "comms.h" +#include "commonutil.h" +#include "mifare4.h" +#include "ui.h" // PrintAndLog... +#include "crapto1/crapto1.h" +#include "crc16.h" +#include "protocols.h" +#include "mfkey.h" +#include "util_posix.h" // msclock + int mfDarkside(uint8_t blockno, uint8_t key_type, uint64_t *key) { uint32_t uid = 0; diff --git a/client/mifare/mifarehost.h b/client/mifare/mifarehost.h index 90837bcf72..11bd3f29ce 100644 --- a/client/mifare/mifarehost.h +++ b/client/mifare/mifarehost.h @@ -10,22 +10,9 @@ #ifndef __MIFARE_HOST_H #define __MIFARE_HOST_H -#include -#include -#include -#include -#include - -#include "proxmark3.h" // time_t #include "common.h" + #include "util.h" // FILE_PATH_SIZE -#include "ui.h" // PrintAndLog... -#include "crapto1/crapto1.h" -#include "crc16.h" -#include "protocols.h" -#include "mifare.h" -#include "mfkey.h" -#include "util_posix.h" // msclock #define MIFARE_SECTOR_RETRY 10 diff --git a/client/mifare/ndef.c b/client/mifare/ndef.c index 7d0100d700..95c66bd72e 100644 --- a/client/mifare/ndef.c +++ b/client/mifare/ndef.c @@ -9,7 +9,11 @@ //----------------------------------------------------------------------------- #include "ndef.h" + +#include + #include "ui.h" +#include "util.h" // sprint_hex... #include "emv/dump.h" #include "crypto/asn1utils.h" diff --git a/client/mifare/ndef.h b/client/mifare/ndef.h index 1737a60823..7d9ca2fbfe 100644 --- a/client/mifare/ndef.h +++ b/client/mifare/ndef.h @@ -11,9 +11,7 @@ #ifndef _NDEF_H_ #define _NDEF_H_ -#include -#include -#include +#include "common.h" typedef enum { tnfEmptyRecord = 0x00, diff --git a/client/pm3_bit_limits.h b/client/pm3_bit_limits.h index 9bf06e16ec..a2deda4c89 100644 --- a/client/pm3_bit_limits.h +++ b/client/pm3_bit_limits.h @@ -1,7 +1,9 @@ #ifndef __BITLIB_LIMITS_H #define __BITLIB_LIMITS_H + #define BITLIB_FLOAT_BITS 53 #define BITLIB_FLOAT_MAX 0xfffffffffffffL #define BITLIB_FLOAT_MIN (-0x10000000000000L) #define BITLIB_FLOAT_UMAX 0x1fffffffffffffUL + #endif diff --git a/common/prng.c b/client/prng.c similarity index 100% rename from common/prng.c rename to client/prng.c diff --git a/common/prng.h b/client/prng.h similarity index 94% rename from common/prng.h rename to client/prng.h index b9f49c6b69..3762f9f72c 100644 --- a/common/prng.h +++ b/client/prng.h @@ -6,8 +6,9 @@ #ifndef __PRNG_H #define __PRNG_H -#include -#include + +#include "common.h" + typedef struct prng_ctx { uint32_t a; uint32_t b; @@ -21,4 +22,5 @@ void burtle_init_mod(prng_ctx *x, uint32_t seed); void burtle_init(prng_ctx *x, uint32_t seed); uint32_t GetSimplePrng(uint32_t seed); + #endif /* __PRNG_H */ diff --git a/client/proxendian.h b/client/proxendian.h index 44e099547f..fde5126b1c 100644 --- a/client/proxendian.h +++ b/client/proxendian.h @@ -11,7 +11,7 @@ #ifndef PROXENDIAN_H__ #define PROXENDIAN_H__ -#include +#include "common.h" #ifdef _WIN32 # define HOST_LITTLE_ENDIAN diff --git a/client/proxgui.cpp b/client/proxgui.cpp index c213528615..d5f82ffe94 100644 --- a/client/proxgui.cpp +++ b/client/proxgui.cpp @@ -9,6 +9,8 @@ //----------------------------------------------------------------------------- #include "proxgui.h" + +#include #include "proxguiqt.h" #include "proxmark3.h" diff --git a/client/proxgui.h b/client/proxgui.h index 06b5a919ed..c4adbeb01c 100644 --- a/client/proxgui.h +++ b/client/proxgui.h @@ -16,7 +16,8 @@ extern "C" { #endif #include -#include +#include +#include void ShowGraphWindow(void); void HideGraphWindow(void); diff --git a/client/proxmark3.c b/client/proxmark3.c index 9d57eeb7ee..de6fe43af1 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -10,24 +10,24 @@ //----------------------------------------------------------------------------- #include "proxmark3.h" -#include +#include + +#include // for Mingw readline #include -#include -#include #include #include #include +#include "usart_defs.h" + #include "util_posix.h" #include "proxgui.h" #include "cmdmain.h" #include "ui.h" -#include "util.h" -#include "cmdparser.h" #include "cmdhw.h" #include "whereami.h" #include "comms.h" -#include "usart.h" +//#include "usart.h" static void showBanner(void) { PrintAndLogEx(NORMAL, "\n"); diff --git a/client/proxmark3.h b/client/proxmark3.h index c669ebbfeb..6d245da103 100644 --- a/client/proxmark3.h +++ b/client/proxmark3.h @@ -12,8 +12,7 @@ #ifndef PROXMARK3_H__ #define PROXMARK3_H__ -#include "pm3_cmd.h" -#include "cmdscript.h" // CmdScriptRun +#include "common.h" #define PROXPROMPT "pm3 --> " #define PROXPROMPT_USB "[usb] pm3 --> " diff --git a/client/scripting.c b/client/scripting.c index 718c4ed437..429d96fac1 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -10,6 +10,28 @@ //----------------------------------------------------------------------------- #include "scripting.h" +#include +#include + +#include "lauxlib.h" +#include "cmdmain.h" +#include "comms.h" +#include "mifare/mifarehost.h" +#include "crc.h" +#include "crc64.h" +#include "mbedtls/sha1.h" +#include "mbedtls/aes.h" +#include "cmdcrc.h" +#include "cmdhfmfhard.h" +#include "cmdhfmfu.h" +#include "cmdlft55xx.h" // read t55xx etc +#include "mifare/ndef.h" // ndef parsing +#include "commonutil.h" +#include "ui.h" +#include "proxmark3.h" +#include "crc16.h" +#include "protocols.h" + static int returnToLuaWithError(lua_State *L, const char *fmt, ...) { char buffer[200]; va_list args; diff --git a/client/scripting.h b/client/scripting.h index 5b8c15ddda..07b07aa679 100644 --- a/client/scripting.h +++ b/client/scripting.h @@ -10,27 +10,9 @@ #ifndef SCRIPTING_H__ #define SCRIPTING_H__ -#include #include -#include -#include -#include "proxmark3.h" -#include "pm3_cmd.h" -#include "cmdmain.h" -#include "comms.h" -#include "util.h" -#include "mifare/mifarehost.h" -#include "crc.h" -#include "crc16.h" -#include "crc64.h" -#include "mbedtls/sha1.h" -#include "mbedtls/aes.h" -#include "cmdcrc.h" -#include "cmdhfmfhard.h" -#include "cmdhfmfu.h" -#include "protocols.h" -#include "cmdlft55xx.h" // read t55xx etc -#include "mifare/ndef.h" // ndef parsing +//#include +//#include #define LUA_LIBRARIES_DIRECTORY "lualibs/" #define LUA_SCRIPTS_DIRECTORY "scripts/" diff --git a/common/tea.c b/client/tea.c similarity index 97% rename from common/tea.c rename to client/tea.c index 187f8a3bc0..b2a425e11d 100644 --- a/common/tea.c +++ b/client/tea.c @@ -7,6 +7,9 @@ // ref: http://143.53.36.235:8080/source.htm#ansi //----------------------------------------------------------------------------- #include "tea.h" + +#include "commonutil.h" // bytes_to_num etc + #define ROUNDS 32 #define DELTA 0x9E3779B9 #define SUM 0xC6EF3720 diff --git a/common/tea.h b/client/tea.h similarity index 90% rename from common/tea.h rename to client/tea.h index 57be7e8340..3390b9d920 100644 --- a/common/tea.h +++ b/client/tea.h @@ -10,9 +10,9 @@ #ifndef __TEA_H #define __TEA_H -#include "commonutil.h" -#include -#include +#include "common.h" + void tea_encrypt(uint8_t *v, uint8_t *key); void tea_decrypt(uint8_t *v, uint8_t *key); + #endif /* __TEA_H */ diff --git a/uart/README.md b/client/uart/README.md similarity index 100% rename from uart/README.md rename to client/uart/README.md diff --git a/uart/uart.h b/client/uart/uart.h similarity index 91% rename from uart/uart.h rename to client/uart/uart.h index a4f2f1f855..172e7db0d5 100644 --- a/uart/uart.h +++ b/client/uart/uart.h @@ -32,25 +32,7 @@ #ifndef _UART_H_ #define _UART_H_ -#include -#include -#include - -#include -#include #include "common.h" -#include "comms.h" -#include "util_posix.h" // msclock - - - -#if defined (_WIN32) -#define SERIAL_PORT_EXAMPLE_H "com3" -#elif defined(__APPLE__) -#define SERIAL_PORT_EXAMPLE_H "/dev/cu.usbmodem" -#else -#define SERIAL_PORT_EXAMPLE_H "/dev/ttyACM0" -#endif /* serial_port is declared as a void*, which you should cast to whatever type * makes sense to your connection method. Both the posix and win32 diff --git a/uart/uart_posix.c b/client/uart/uart_posix.c similarity index 98% rename from uart/uart_posix.c rename to client/uart/uart_posix.c index ea535fd737..0077924cf7 100644 --- a/uart/uart_posix.c +++ b/client/uart/uart_posix.c @@ -39,22 +39,18 @@ #include "uart.h" +#include +#include +#include #include #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include #include +#include "comms.h" + // Taken from https://github.com/unbit/uwsgi/commit/b608eb1772641d525bfde268fe9d6d8d0d5efde7 #ifndef SOL_TCP # define SOL_TCP IPPROTO_TCP diff --git a/uart/uart_win32.c b/client/uart/uart_win32.c similarity index 98% rename from uart/uart_win32.c rename to client/uart/uart_win32.c index 5a5f8b9d37..bbb5bfcfa7 100644 --- a/uart/uart_win32.c +++ b/client/uart/uart_win32.c @@ -38,6 +38,12 @@ #include "uart.h" +#include +#include +#include + +#include "comms.h" + // The windows serial port implementation #ifdef _WIN32 #include diff --git a/client/ui.c b/client/ui.c index 0dcaca9e67..9927fd6d6c 100644 --- a/client/ui.c +++ b/client/ui.c @@ -16,6 +16,15 @@ #endif #include "ui.h" +#include "commonutil.h" // ARRAYLEN + +#include // for Mingw readline +#include +#include +#include +#include +#include "util.h" + session_arg_t session; double CursorScaleFactor = 1; diff --git a/client/ui.h b/client/ui.h index 6e70b053dc..648dce4c46 100644 --- a/client/ui.h +++ b/client/ui.h @@ -11,18 +11,11 @@ #ifndef UI_H__ #define UI_H__ -#define _USE_MATH_DEFINES -#include -#include -#include -#include -#include -#include -#include +#include "common.h" #include -#include -#include -#include "util.h" +#include "ansi.h" + +#define _USE_MATH_DEFINES typedef struct { bool stdinOnTTY; diff --git a/client/util.c b/client/util.c index 3bb0a96fa5..52321689b7 100644 --- a/client/util.c +++ b/client/util.c @@ -15,6 +15,16 @@ #include "util.h" +#include +#include +#include +#include +#include +#include +#include // Mingw + +#include "ui.h" // PrintAndLog + #define UTIL_BUFFER_SIZE_SPRINT 4097 // global client debug variable uint8_t g_debugMode = 0; diff --git a/client/util.h b/client/util.h index 8861045d85..09aeeaecb6 100644 --- a/client/util.h +++ b/client/util.h @@ -10,16 +10,6 @@ #ifndef __UTIL_H_ #define __UTIL_H_ -#include //included in data.h -#include -#include -#include -#include -#include -#include -#include -#include "ui.h" // PrintAndLog -#include "commonutil.h" #include "common.h" #ifdef ANDROID @@ -31,20 +21,6 @@ # define FILE_PATH_SIZE 1000 #endif -#ifndef DropField -#define DropField() { \ - clearCommandBuffer(); SendCommandNG(CMD_HF_DROPFIELD, NULL, 0); \ - } -#endif - -#ifndef DropFieldEx -#define DropFieldEx(x) { \ - if ( (x) == ECC_CONTACTLESS) { \ - DropField(); \ - } \ - } -#endif - uint8_t g_debugMode; int kbd_enter_pressed(void); diff --git a/client/util_posix.c b/client/util_posix.c index ca54d2ae47..050040a32e 100644 --- a/client/util_posix.c +++ b/client/util_posix.c @@ -8,8 +8,10 @@ // utilities requiring Posix library functions //----------------------------------------------------------------------------- +// ensure availability even with -std=c99; must be included before #if !defined(_WIN32) -#define _POSIX_C_SOURCE 199309L // need nanosleep() +//#define _POSIX_C_SOURCE 199309L // need nanosleep() +#define _POSIX_C_SOURCE 200112L // need localtime_r() #else #include #endif diff --git a/client/util_posix.h b/client/util_posix.h index a0a8c86383..546b4ea352 100644 --- a/client/util_posix.h +++ b/client/util_posix.h @@ -11,16 +11,16 @@ #ifndef UTIL_POSIX_H__ #define UTIL_POSIX_H__ -#include +#include "common.h" #ifdef _WIN32 # include # define sleep(n) Sleep(1000 *(n)) # define msleep(n) Sleep((n)) #else -extern void msleep(uint32_t n); // sleep n milliseconds +void msleep(uint32_t n); // sleep n milliseconds #endif // _WIN32 -extern uint64_t msclock(void); // a milliseconds clock +uint64_t msclock(void); // a milliseconds clock #endif diff --git a/common/bucketsort.h b/common/bucketsort.h index 0a56509c16..9e5123e1a2 100644 --- a/common/bucketsort.h +++ b/common/bucketsort.h @@ -1,8 +1,7 @@ #ifndef BUCKETSORT_H__ #define BUCKETSORT_H__ -#include -#include +#include "common.h" typedef struct bucket { uint32_t *head; @@ -21,4 +20,5 @@ typedef struct bucket_info { void bucket_sort_intersect(uint32_t *const estart, uint32_t *const estop, uint32_t *const ostart, uint32_t *const ostop, bucket_info_t *bucket_info, bucket_array_t bucket); + #endif diff --git a/common/commonutil.h b/common/commonutil.h index 9504abd5bb..a22486fffa 100644 --- a/common/commonutil.h +++ b/common/commonutil.h @@ -11,8 +11,8 @@ #ifndef __COMMONUTIL_H #define __COMMONUTIL_H -#include -#include +#include "common.h" + // endian change for 16bit #ifdef __GNUC__ #ifndef BSWAP_16 @@ -53,11 +53,4 @@ void lsl(uint8_t *data, size_t len); int32_t le24toh(uint8_t data[3]); void htole24(uint32_t val, uint8_t data[3]); -# define _BLUE_(s) "\x1b[34m" s "\x1b[0m " -# define _RED_(s) "\x1b[31m" s "\x1b[0m " -# define _GREEN_(s) "\x1b[32m" s "\x1b[0m " -# define _YELLOW_(s) "\x1b[33m" s "\x1b[0m " -# define _MAGENTA_(s) "\x1b[35m" s "\x1b[0m " -# define _CYAN_(s) "\x1b[36m" s "\x1b[0m " - #endif diff --git a/common/crapto1/crapto1.c b/common/crapto1/crapto1.c index ba55227b5f..66af2f41cf 100644 --- a/common/crapto1/crapto1.c +++ b/common/crapto1/crapto1.c @@ -19,6 +19,8 @@ */ #include "crapto1.h" +#include "bucketsort.h" + #include #include "parity.h" diff --git a/common/crapto1/crapto1.h b/common/crapto1/crapto1.h index 49a784cf95..ab061e2e73 100644 --- a/common/crapto1/crapto1.h +++ b/common/crapto1/crapto1.h @@ -19,13 +19,10 @@ */ #ifndef CRAPTO1_INCLUDED #define CRAPTO1_INCLUDED + #include +#include #include -#include "bucketsort.h" - -#ifdef __cplusplus -extern "C" { -#endif struct Crypto1State {uint32_t odd, even;}; #if defined(__arm__) && !defined(__linux__) && !defined(_WIN32) && !defined(__APPLE__) // bare metal ARM Proxmark lacks malloc()/free() @@ -77,7 +74,4 @@ static inline int filter(uint32_t const x) { f |= 0x0d938 >> (x >> 16 & 0xf) & 1; return BIT(0xEC57E80A, f); } -#ifdef __cplusplus -} -#endif #endif diff --git a/common/crapto1/crypto1.c b/common/crapto1/crypto1.c index 7d6bb6e7d8..9df30b3567 100644 --- a/common/crapto1/crypto1.c +++ b/common/crapto1/crypto1.c @@ -17,9 +17,9 @@ Copyright (C) 2008-2008 bla */ -#include "crapto1.h" - #include + +#include "crapto1.h" #include "parity.h" #define SWAPENDIAN(x)\ diff --git a/common/crc.c b/common/crc.c index e197c0eee9..0237fb36a4 100644 --- a/common/crc.c +++ b/common/crc.c @@ -9,6 +9,8 @@ // #include "crc.h" +#include "commonutil.h" + void crc_init_ref(crc_t *crc, int order, uint32_t polynom, uint32_t initial_value, uint32_t final_xor, bool refin, bool refout) { crc_init(crc, order, polynom, initial_value, final_xor); crc->refin = refin; diff --git a/common/crc.h b/common/crc.h index f0fa91194f..6dcfe918f7 100644 --- a/common/crc.h +++ b/common/crc.h @@ -9,8 +9,7 @@ #ifndef __CRC_H #define __CRC_H -#include "common.h" //stdint, stddef, stdbool -#include "commonutil.h" // reflect, bswap_16 +#include "common.h" typedef struct crc_ctx { uint32_t state; @@ -24,6 +23,18 @@ typedef struct crc_ctx { bool refout; /* Parameter: Reflect output CRC? */ } crc_t; +/* Static initialization of a crc structure */ +#define CRC_INITIALIZER(_order, _polynom, _initial_value, _final_xor) { \ + .state = ((_initial_value) & ((1L<<(_order))-1)), \ + .order = (_order), \ + .polynom = (_polynom), \ + .initial_value = (_initial_value), \ + .final_xor = (_final_xor), \ + .mask = ((1L<<(_order))-1) \ + .refin = false, \ + .refout = false \ +} + /* Initialize a crc structure. order is the order of the polynom, e.g. 32 for a CRC-32 * polynom is the CRC polynom. initial_value is the initial value of a clean state. * final_xor is XORed onto the state before returning it from crc_result(). @@ -62,16 +73,4 @@ uint32_t CRC4Legic(uint8_t *buff, size_t size); // Calculate CRC-8/Legic checksum uint32_t CRC8Legic(uint8_t *buff, size_t size); -/* Static initialization of a crc structure */ -#define CRC_INITIALIZER(_order, _polynom, _initial_value, _final_xor) { \ - .state = ((_initial_value) & ((1L<<(_order))-1)), \ - .order = (_order), \ - .polynom = (_polynom), \ - .initial_value = (_initial_value), \ - .final_xor = (_final_xor), \ - .mask = ((1L<<(_order))-1) \ - .refin = false, \ - .refout = false \ -} - #endif /* __CRC_H */ diff --git a/common/crc16.c b/common/crc16.c index f2a6558b8b..729c15cf4d 100644 --- a/common/crc16.c +++ b/common/crc16.c @@ -7,6 +7,9 @@ //----------------------------------------------------------------------------- #include "crc16.h" +#include +#include "commonutil.h" + static uint16_t crc_table[256]; static bool crc_table_init = false; static CrcType_t current_crc_type = CRC_NONE; diff --git a/common/crc16.h b/common/crc16.h index 9c9df1d1fa..6989af22e6 100644 --- a/common/crc16.h +++ b/common/crc16.h @@ -8,11 +8,7 @@ #ifndef __CRC16_H #define __CRC16_H -#include -#include -#include -#include -#include "commonutil.h" +#include "common.h" #define CRC16_POLY_CCITT 0x1021 #define CRC16_POLY_LEGIC 0xc6c6 //0x6363 diff --git a/common/crc32.h b/common/crc32.h index 308b3a077d..a6bbee16a4 100644 --- a/common/crc32.h +++ b/common/crc32.h @@ -9,18 +9,9 @@ #ifndef __CRC32_H #define __CRC32_H -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif +#include "common.h" void crc32_ex(const uint8_t *data, const size_t len, uint8_t *crc); void crc32_append(uint8_t *data, const size_t len); -#ifdef __cplusplus -} -#endif - #endif diff --git a/common/crc64.c b/common/crc64.c index 23360f6bd8..3bdc596ac7 100644 --- a/common/crc64.c +++ b/common/crc64.c @@ -1,5 +1,3 @@ -#include -#include #include "crc64.h" #define CRC64_ISO_PRESET 0xFFFFFFFFFFFFFFFF diff --git a/common/crc64.h b/common/crc64.h index 3782bdbae6..af6417cb30 100644 --- a/common/crc64.h +++ b/common/crc64.h @@ -9,6 +9,8 @@ #ifndef __CRC64_H #define __CRC64_H +#include "common.h" + void crc64(const uint8_t *data, const size_t len, uint64_t *crc) ; #endif diff --git a/common/fpga.h b/common/fpga.h index eb26d0ccbc..e0704d95cb 100644 --- a/common/fpga.h +++ b/common/fpga.h @@ -7,6 +7,8 @@ #ifndef __FPGA_H #define __FPGA_H +#include "common.h" + #define FPGA_BITSTREAM_FIXED_HEADER_SIZE sizeof(bitparse_fixed_header) #define FPGA_INTERLEAVE_SIZE 288 #define FPGA_CONFIG_SIZE 42336L // our current fpga_[lh]f.bit files are 42175 bytes. Rounded up to next multiple of FPGA_INTERLEAVE_SIZE diff --git a/common/iso15693tools.c b/common/iso15693tools.c index 795d1be60f..66a0f81da2 100644 --- a/common/iso15693tools.c +++ b/common/iso15693tools.c @@ -7,6 +7,8 @@ //----------------------------------------------------------------------------- #include "iso15693tools.h" +#include + // returns a string representation of the UID // UID is transmitted and stored LSB first, displayed MSB first // target char* buffer, where to put the UID, if NULL a static buffer is returned diff --git a/common/iso15693tools.h b/common/iso15693tools.h index e59f6ca398..42b2152cc0 100644 --- a/common/iso15693tools.h +++ b/common/iso15693tools.h @@ -11,10 +11,7 @@ #ifndef ISO15693_H__ #define ISO15693_H__ -#include "proxmark3.h" -#include -#include -#include "crc16.h" +#include "common.h" // REQUEST FLAGS #define ISO15_REQ_SUBCARRIER_SINGLE 0x00 // Tag should respond using one subcarrier (ASK) @@ -70,8 +67,6 @@ #define ISO15_CMD_SYSINFO 0x2B #define ISO15_CMD_SECSTATUS 0x2C -char *Iso15693sprintUID(char *target, uint8_t *uid); - //----------------------------------------------------------------------------- // Map a sequence of octets (~layer 2 command) into the set of bits to feed // to the FPGA, to transmit that command to the tag. @@ -123,4 +118,6 @@ static const int Iso15693FrameEOF[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; +char *Iso15693sprintUID(char *target, uint8_t *uid); + #endif diff --git a/include/legic_prng.h b/common/legic_prng.h similarity index 96% rename from include/legic_prng.h rename to common/legic_prng.h index c34455c4c6..b72c6d8ed2 100644 --- a/include/legic_prng.h +++ b/common/legic_prng.h @@ -9,10 +9,12 @@ #ifndef __LEGIC_PRNG_H #define __LEGIC_PRNG_H -#include +#include "common.h" + void legic_prng_init(uint8_t iv); void legic_prng_forward(int count); uint8_t legic_prng_get_bit(void); uint32_t legic_prng_get_bits(uint8_t len); + #endif diff --git a/common/lfdemod.c b/common/lfdemod.c index ec960c91fe..b0b30a1c8a 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -36,12 +36,9 @@ // marshmellow //----------------------------------------------------------------------------- -#include // for memset, memcmp and size_t #include "lfdemod.h" -#include // for uint_32+ -#include // for bool +#include // for memset, memcmp and size_t #include "parity.h" // for parity test -#include "commonutil.h" // colors #include "pm3_cmd.h" // error codes //********************************************************************************************** //---------------------------------Utilities Section-------------------------------------------- @@ -51,15 +48,12 @@ //to allow debug print calls when used not on dev -//void dummy(char *fmt, ...){} -void Dbprintf(const char *fmt, ...); - #ifndef ON_DEVICE #include "ui.h" -# include "cmdparser.h" # include "cmddata.h" # define prnt(args...) PrintAndLogEx(DEBUG, ## args ); #else +# include "dbprint.h" uint8_t g_debugMode = 0; # define prnt Dbprintf #endif diff --git a/common/lfdemod.h b/common/lfdemod.h index 0acb520634..50d769c6b9 100644 --- a/common/lfdemod.h +++ b/common/lfdemod.h @@ -13,12 +13,8 @@ #ifndef LFDEMOD_H__ #define LFDEMOD_H__ -#include // for uint_32+ -#include // for bool -#include // for strcmp, memset, memcmp and size_t -#include // for -#include // for bool -#include "parity.h" // for parity test + +#include "common.h" //might not be high enough for noisy environments #define NOISE_AMPLITUDE_THRESHOLD 8 @@ -83,4 +79,5 @@ int Em410xDecode(uint8_t *bits, size_t *size, size_t *start_idx, uint32_t *hi, u int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx); int detectIdteck(uint8_t *dest, size_t *size); int detectIOProx(uint8_t *dest, size_t *size, int *waveStartIdx); + #endif diff --git a/common/parity.c b/common/parity.c index 2a1d6281c7..1db224f37d 100644 --- a/common/parity.c +++ b/common/parity.c @@ -6,7 +6,6 @@ // parity functions (all defined in parity.h) //----------------------------------------------------------------------------- #include -#include const uint8_t OddByteParity[256] = { 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, diff --git a/common/parity.h b/common/parity.h index e426169174..a768f51fb0 100644 --- a/common/parity.h +++ b/common/parity.h @@ -11,12 +11,7 @@ #ifndef __PARITY_H #define __PARITY_H -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include +#include "common.h" extern const uint8_t OddByteParity[256]; @@ -52,8 +47,4 @@ static inline bool oddparity32(uint32_t x) { #endif } -#ifdef __cplusplus -} -#endif - #endif /* __PARITY_H */ diff --git a/common/protocols.c b/common/protocols.c deleted file mode 100644 index 809c31704a..0000000000 --- a/common/protocols.c +++ /dev/null @@ -1,150 +0,0 @@ -#include "protocols.h" - -// ATA55xx shared presets & routines -uint32_t GetT55xxClockBit(uint32_t clock) { - switch (clock) { - case 128: - return T55x7_BITRATE_RF_128; - case 100: - return T55x7_BITRATE_RF_100; - case 64: - return T55x7_BITRATE_RF_64; - case 50: - return T55x7_BITRATE_RF_50; - case 40: - return T55x7_BITRATE_RF_40; - case 32: - return T55x7_BITRATE_RF_32; - case 16: - return T55x7_BITRATE_RF_16; - case 8: - return T55x7_BITRATE_RF_8; - default : - return 0; - } -} - -#ifndef ON_DEVICE -#include "ui.h" -#define PrintAndLogDevice(level, format, args...) PrintAndLogEx(level, format , ## args) - -static uint8_t isset(uint8_t val, uint8_t mask) { - return (val & mask); -} - -static uint8_t notset(uint8_t val, uint8_t mask) { - return !(val & mask); -} - -static void fuse_config(const picopass_hdr *hdr) { - uint8_t fuses = hdr->conf.fuses; - - if (isset(fuses, FUSE_FPERS)) - PrintAndLogDevice(SUCCESS, "\tMode: Personalization [Programmable]"); - else - PrintAndLogDevice(NORMAL, "\tMode: Application [Locked]"); - - if (isset(fuses, FUSE_CODING1)) { - PrintAndLogDevice(NORMAL, "\tCoding: RFU"); - } else { - if (isset(fuses, FUSE_CODING0)) - PrintAndLogDevice(NORMAL, "\tCoding: ISO 14443-2 B/ISO 15693"); - else - PrintAndLogDevice(NORMAL, "\tCoding: ISO 14443B only"); - } - // 1 1 - if (isset(fuses, FUSE_CRYPT1) && isset(fuses, FUSE_CRYPT0)) PrintAndLogDevice(SUCCESS, "\tCrypt: Secured page, keys not locked"); - // 1 0 - if (isset(fuses, FUSE_CRYPT1) && notset(fuses, FUSE_CRYPT0)) PrintAndLogDevice(NORMAL, "\tCrypt: Secured page, keys locked"); - // 0 1 - if (notset(fuses, FUSE_CRYPT1) && isset(fuses, FUSE_CRYPT0)) PrintAndLogDevice(SUCCESS, "\tCrypt: Non secured page"); - // 0 0 - if (notset(fuses, FUSE_CRYPT1) && notset(fuses, FUSE_CRYPT0)) PrintAndLogDevice(NORMAL, "\tCrypt: No auth possible. Read only if RA is enabled"); - - if (isset(fuses, FUSE_RA)) - PrintAndLogDevice(NORMAL, "\tRA: Read access enabled"); - else - PrintAndLogDevice(WARNING, "\tRA: Read access not enabled"); -} - -void getMemConfig(uint8_t mem_cfg, uint8_t chip_cfg, uint8_t *max_blk, uint8_t *app_areas, uint8_t *kb) { - // mem-bit 5, mem-bit 7, chip-bit 4: defines chip type - uint8_t k16 = isset(mem_cfg, 0x80); - //uint8_t k2 = isset(mem_cfg, 0x08); - uint8_t book = isset(mem_cfg, 0x20); - - if (isset(chip_cfg, 0x10) && !k16 && !book) { - *kb = 2; - *app_areas = 2; - *max_blk = 31; - } else if (isset(chip_cfg, 0x10) && k16 && !book) { - *kb = 16; - *app_areas = 2; - *max_blk = 255; //16kb - } else if (notset(chip_cfg, 0x10) && !k16 && !book) { - *kb = 16; - *app_areas = 16; - *max_blk = 255; //16kb - } else if (isset(chip_cfg, 0x10) && k16 && book) { - *kb = 32; - *app_areas = 3; - *max_blk = 255; //16kb - } else if (notset(chip_cfg, 0x10) && !k16 && book) { - *kb = 32; - *app_areas = 17; - *max_blk = 255; //16kb - } else { - *kb = 32; - *app_areas = 2; - *max_blk = 255; - } -} - -static void mem_app_config(const picopass_hdr *hdr) { - uint8_t mem = hdr->conf.mem_config; - uint8_t chip = hdr->conf.chip_config; - uint8_t applimit = hdr->conf.app_limit; - uint8_t kb = 2; - uint8_t app_areas = 2; - uint8_t max_blk = 31; - - getMemConfig(mem, chip, &max_blk, &app_areas, &kb); - - if (applimit < 6) applimit = 26; - if (kb == 2 && (applimit > 0x1f)) applimit = 26; - - PrintAndLogDevice(NORMAL, " Mem: %u KBits/%u App Areas (%u * 8 bytes) [%02X]", kb, app_areas, max_blk, mem); - PrintAndLogDevice(NORMAL, "\tAA1: blocks 06-%02X", applimit); - PrintAndLogDevice(NORMAL, "\tAA2: blocks %02X-%02X", applimit + 1, max_blk); - PrintAndLogDevice(NORMAL, "\tOTP: 0x%02X%02X", hdr->conf.otp[1], hdr->conf.otp[0]); - PrintAndLogDevice(NORMAL, "\nKeyAccess:"); - - uint8_t book = isset(mem, 0x20); - if (book) { - PrintAndLogDevice(NORMAL, "\tRead A - Kd"); - PrintAndLogDevice(NORMAL, "\tRead B - Kc"); - PrintAndLogDevice(NORMAL, "\tWrite A - Kd"); - PrintAndLogDevice(NORMAL, "\tWrite B - Kc"); - PrintAndLogDevice(NORMAL, "\tDebit - Kd or Kc"); - PrintAndLogDevice(NORMAL, "\tCredit - Kc"); - } else { - PrintAndLogDevice(NORMAL, "\tRead A - Kd or Kc"); - PrintAndLogDevice(NORMAL, "\tRead B - Kd or Kc"); - PrintAndLogDevice(NORMAL, "\tWrite A - Kc"); - PrintAndLogDevice(NORMAL, "\tWrite B - Kc"); - PrintAndLogDevice(NORMAL, "\tDebit - Kd or Kc"); - PrintAndLogDevice(NORMAL, "\tCredit - Kc"); - } -} -static void print_picopass_info(const picopass_hdr *hdr) { - fuse_config(hdr); - mem_app_config(hdr); -} -void printIclassDumpInfo(uint8_t *iclass_dump) { - print_picopass_info((picopass_hdr *) iclass_dump); -} - -#else -#define PrintAndLogDevice(level, format, ...) { } -#endif -//ON_DEVICE diff --git a/zlib/ChangeLog b/common/zlib/ChangeLog similarity index 100% rename from zlib/ChangeLog rename to common/zlib/ChangeLog diff --git a/zlib/FAQ b/common/zlib/FAQ similarity index 100% rename from zlib/FAQ rename to common/zlib/FAQ diff --git a/zlib/README b/common/zlib/README similarity index 100% rename from zlib/README rename to common/zlib/README diff --git a/zlib/adler32.c b/common/zlib/adler32.c similarity index 100% rename from zlib/adler32.c rename to common/zlib/adler32.c diff --git a/zlib/deflate.c b/common/zlib/deflate.c similarity index 100% rename from zlib/deflate.c rename to common/zlib/deflate.c diff --git a/zlib/deflate.h b/common/zlib/deflate.h similarity index 100% rename from zlib/deflate.h rename to common/zlib/deflate.h diff --git a/zlib/inffast.c b/common/zlib/inffast.c similarity index 100% rename from zlib/inffast.c rename to common/zlib/inffast.c diff --git a/zlib/inffast.h b/common/zlib/inffast.h similarity index 100% rename from zlib/inffast.h rename to common/zlib/inffast.h diff --git a/zlib/inffixed.h b/common/zlib/inffixed.h similarity index 100% rename from zlib/inffixed.h rename to common/zlib/inffixed.h diff --git a/zlib/inflate.c b/common/zlib/inflate.c similarity index 100% rename from zlib/inflate.c rename to common/zlib/inflate.c diff --git a/zlib/inflate.h b/common/zlib/inflate.h similarity index 100% rename from zlib/inflate.h rename to common/zlib/inflate.h diff --git a/zlib/inftrees.c b/common/zlib/inftrees.c similarity index 100% rename from zlib/inftrees.c rename to common/zlib/inftrees.c diff --git a/zlib/inftrees.h b/common/zlib/inftrees.h similarity index 100% rename from zlib/inftrees.h rename to common/zlib/inftrees.h diff --git a/zlib/trees.c b/common/zlib/trees.c similarity index 100% rename from zlib/trees.c rename to common/zlib/trees.c diff --git a/zlib/trees.h b/common/zlib/trees.h similarity index 100% rename from zlib/trees.h rename to common/zlib/trees.h diff --git a/zlib/zconf.h b/common/zlib/zconf.h similarity index 100% rename from zlib/zconf.h rename to common/zlib/zconf.h diff --git a/zlib/zlib.h b/common/zlib/zlib.h similarity index 100% rename from zlib/zlib.h rename to common/zlib/zlib.h diff --git a/zlib/zutil.c b/common/zlib/zutil.c similarity index 100% rename from zlib/zutil.c rename to common/zlib/zutil.c diff --git a/zlib/zutil.h b/common/zlib/zutil.h similarity index 100% rename from zlib/zutil.h rename to common/zlib/zutil.h diff --git a/common/Makefile.common b/common_arm/Makefile.common similarity index 81% rename from common/Makefile.common rename to common_arm/Makefile.common index 282f242d94..30f0f679eb 100644 --- a/common/Makefile.common +++ b/common_arm/Makefile.common @@ -31,10 +31,11 @@ AS = $(CROSS)as LD = $(CROSS)ld OBJCOPY = $(CROSS)objcopy GZIP=gzip +MV=mv OBJDIR = obj -INCLUDE = -I../include -I../common -I. +INCLUDE = -I../include -I../common_arm -I../common -I. TAR=tar TARFLAGS = -C .. -rvf @@ -63,14 +64,19 @@ DETECTED_OS=Windows endif # Also search prerequisites in the common directory (for usb.c), the fpga directory (for fpga.bit), and the zlib directory -VPATH = . ../common ../common/crapto1 ../common/mbedtls ../fpga ../zlib ../armsrc/Standalone ../uart +VPATH = . ../common_arm ../common ../common/crapto1 ../common/mbedtls ../common/zlib ../fpga ../armsrc/Standalone -INCLUDES = ../include/proxmark3.h ../include/at91sam7s512.h ../include/config_gpio.h ../include/pm3_cmd.h $(APP_INCLUDES) +INCLUDES = ../include/proxmark3_arm.h ../include/at91sam7s512.h ../include/config_gpio.h ../include/pm3_cmd.h CFLAGS = -c $(INCLUDE) -Wall -Werror -pedantic -Wunused -std=c99 $(APP_CFLAGS) -Os LDFLAGS = -nostartfiles -nodefaultlibs -Wl,-gc-sections -n LIBS = -lgcc +# Flags to generate temporary dependency files +DEPFLAGS = -MT $@ -MMD -MP -MF $(OBJDIR)/$*.Td +# make temporary to final dependency files after successful compilation +POSTCOMPILE = $(MV) -f $(OBJDIR)/$*.Td $(OBJDIR)/$*.d + THUMBOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(notdir $(THUMBSRC))) ARMOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(notdir $(ARMSRC))) ASMOBJ = $(patsubst %.s,$(OBJDIR)/%.o,$(notdir $(ASMSRC))) @@ -78,11 +84,13 @@ VERSIONOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(notdir $(VERSIONSRC))) $(THUMBOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES) $(info [-] CC $<) - $(Q)$(CC) $(CFLAGS) -mthumb -mthumb-interwork -o $@ $< + $(Q)$(CC) $(CFLAGS) $(DEPFLAGS) -mthumb -mthumb-interwork -o $@ $< + $(Q)$(POSTCOMPILE) $(ARMOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES) $(info [-] CC $<) - $(Q)$(CC) $(CFLAGS) -mthumb-interwork -o $@ $< + $(Q)$(CC) $(CFLAGS) $(DEPFLAGS) -mthumb-interwork -o $@ $< + $(Q)$(POSTCOMPILE) $(ASMOBJ): $(OBJDIR)/%.o: %.s $(info [-] CC $<) @@ -111,11 +119,7 @@ DEPENDENCY_FILES = $(patsubst %.c,$(OBJDIR)/%.d,$(notdir $(THUMBSRC))) \ $(patsubst %.c,$(OBJDIR)/%.d,$(notdir $(ARMSRC))) \ $(patsubst %.s,$(OBJDIR)/%.d,$(notdir $(ASMSRC))) -$(DEPENDENCY_FILES): Makefile ../common/Makefile.common - -$(patsubst %.o,%.d,$(THUMBOBJ) $(ARMOBJ)): $(OBJDIR)/%.d: %.c - @$(CC) -MM -MT "$(@) $(@:.d=.o)" $(CFLAGS) $< > $@ -$(patsubst %.o,%.d,$(ASMOBJ)):$(OBJDIR)/%.d: %.s - @$(CC) -MM -MT "$(@) $(@:.d=.o)" $(CFLAGS) $< > $@ +$(DEPENDENCY_FILES): Makefile ../common_arm/Makefile.common +.PRECIOUS: $(DEPENDENCY_FILES) -include $(DEPENDENCY_FILES) diff --git a/common/Makefile.hal b/common_arm/Makefile.hal similarity index 100% rename from common/Makefile.hal rename to common_arm/Makefile.hal diff --git a/common/default_version.c b/common_arm/default_version.c similarity index 93% rename from common/default_version.c rename to common_arm/default_version.c index b586e4ad1c..e1e5dc64cf 100644 --- a/common/default_version.c +++ b/common_arm/default_version.c @@ -1,4 +1,4 @@ -#include "proxmark3.h" +#include "proxmark3_arm.h" /* This is the default version.c file that Makefile.common falls back to if perl is not available */ const struct version_information __attribute__((section(".version_information"))) version_information = { VERSION_INFORMATION_MAGIC, diff --git a/common/ldscript.common b/common_arm/ldscript.common similarity index 100% rename from common/ldscript.common rename to common_arm/ldscript.common diff --git a/common/usb_cdc.c b/common_arm/usb_cdc.c similarity index 98% rename from common/usb_cdc.c rename to common_arm/usb_cdc.c index 5768a99ab6..dd8d2f7c4b 100644 --- a/common/usb_cdc.c +++ b/common_arm/usb_cdc.c @@ -33,6 +33,9 @@ */ #include "usb_cdc.h" +#include "proxmark3_arm.h" +#include "usart_defs.h" + /* AT91SAM7S256 USB Device Port • Embedded 328-byte dual-port RAM for endpoints @@ -448,17 +451,16 @@ AT91S_CDC_LINE_CODING line = { // purely informative, actual values don't matter // timer counts in 21.3us increments (1024/48MHz), rounding applies // WARNING: timer can't measure more than 1.39s (21.3us * 0xffff) -static void SpinDelay(int ms) { - int us = ms * 1000; +static void SpinDelayUs(int us) { int ticks = ((MCK / 1000000) * us + 512) >> 10; // Borrow a PWM unit for my real-time clock AT91C_BASE_PWMC->PWMC_ENA = PWM_CHANNEL(0); // 48 MHz / 1024 gives 46.875 kHz - AT91C_BASE_PWMC_CH0->PWMC_CMR = PWM_CH_MODE_PRESCALER(10); - AT91C_BASE_PWMC_CH0->PWMC_CDTYR = 0; - AT91C_BASE_PWMC_CH0->PWMC_CPRDR = 0xffff; + AT91C_BASE_PWMC_CH0->PWMC_CMR = PWM_CH_MODE_PRESCALER(10); // Channel Mode Register + AT91C_BASE_PWMC_CH0->PWMC_CDTYR = 0; // Channel Duty Cycle Register + AT91C_BASE_PWMC_CH0->PWMC_CPRDR = 0xffff; // Channel Period Register uint16_t start = AT91C_BASE_PWMC_CH0->PWMC_CCNTR; @@ -512,7 +514,7 @@ void usb_enable() { // Disconnect and reconnect USB controller for 100ms usb_disable(); - SpinDelay(100); + SpinDelayUs(100 * 1000); // Wait for a short while //for (volatile size_t i=0; i<0x100000; i++) {}; diff --git a/common/usb_cdc.h b/common_arm/usb_cdc.h similarity index 95% rename from common/usb_cdc.h rename to common_arm/usb_cdc.h index 64dfbcd4da..b5ec2e8d74 100644 --- a/common/usb_cdc.h +++ b/common_arm/usb_cdc.h @@ -35,12 +35,8 @@ #ifndef _USB_CDC_H_ #define _USB_CDC_H_ -#include -#include "at91sam7s512.h" -#include "usart.h" -#include "config_gpio.h" -#include "proxmark3.h" // USB_CONNECT() #include "common.h" +#include "at91sam7s512.h" void usb_disable(void); void usb_enable(void); @@ -62,4 +58,3 @@ void AT91F_USB_SendStall(AT91PS_UDP pUdp); void AT91F_CDC_Enumerate(void); #endif // _USB_CDC_H_ - diff --git a/fpga/Makefile b/fpga/Makefile index ba9fec28b1..b28c27db92 100644 --- a/fpga/Makefile +++ b/fpga/Makefile @@ -1,5 +1,3 @@ -include ../common/Makefile.common # for $(DETECTED_OS) - all: fpga_lf.bit fpga_hf.bit clean: $(Q)$(DELETE) *.bgn *.drc *.ncd *.ngd *_par.xrpt *-placed.* *-placed_pad.* *_usage.xml xst_hf.srp xst_lf.srp @@ -38,7 +36,6 @@ fpga_lf.ngc: fpga_lf.v fpga.ucf xst_lf.scr util.v clk_divider.v lo_edge_detect.v .PHONY: all clean help help: - @echo Multi-OS Makefile, you are running on $(DETECTED_OS) @echo Possible targets: @echo + all - Make fpga.bit, the FPGA bitstream @echo + clean - Clean intermediate files, does not clean fpga.bit diff --git a/include/ansi.h b/include/ansi.h new file mode 100644 index 0000000000..29df618a14 --- /dev/null +++ b/include/ansi.h @@ -0,0 +1,11 @@ +#ifndef __ANSI_H +#define __ANSI_H + +#define _BLUE_(s) "\x1b[34m" s "\x1b[0m " +#define _RED_(s) "\x1b[31m" s "\x1b[0m " +#define _GREEN_(s) "\x1b[32m" s "\x1b[0m " +#define _YELLOW_(s) "\x1b[33m" s "\x1b[0m " +#define _MAGENTA_(s) "\x1b[35m" s "\x1b[0m " +#define _CYAN_(s) "\x1b[36m" s "\x1b[0m " + +#endif diff --git a/include/common.h b/include/common.h index dec2261ec5..f427cb2211 100644 --- a/include/common.h +++ b/include/common.h @@ -12,26 +12,11 @@ #ifndef __COMMON_H #define __COMMON_H -#ifdef __cplusplus -extern "C" { -#endif - -#include #include +#include #include -typedef unsigned char byte_t; - -#ifdef _MSC_VER -typedef DWORD uint32_t; -typedef BYTE uint8_t; -#define PACKED -// stuff -#else -#include -#include #define PACKED __attribute__((packed)) -#endif // debug #define DBG_NONE 0 // no messages @@ -138,7 +123,4 @@ extern int DBGLEVEL; # define DEC2BCD(dec) HornerScheme(dec, 10, 0x10) #endif -#ifdef __cplusplus -} -#endif #endif diff --git a/include/pmflash.h b/include/pmflash.h index 6e3a20e554..d61b5647d6 100644 --- a/include/pmflash.h +++ b/include/pmflash.h @@ -12,14 +12,6 @@ #ifndef __PMFLASH_H #define __PMFLASH_H -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include - #include "common.h" // Flashmem spi baudrate @@ -90,8 +82,4 @@ typedef struct { uint8_t signature[FLASH_MEM_SIGNATURE_LEN]; } PACKED rdv40_validation_t; -#ifdef __cplusplus -} -#endif - #endif // __PMFLASH_H diff --git a/common/protocols.h b/include/protocols.h similarity index 96% rename from common/protocols.h rename to include/protocols.h index 71a758fbea..5a1e56f4e1 100644 --- a/common/protocols.h +++ b/include/protocols.h @@ -1,10 +1,7 @@ #ifndef PROTOCOLS_H #define PROTOCOLS_H -#include -#include -#include - +#include "common.h" //The following data is taken from http://www.proxmark.org/forum/viewtopic.php?pid=13501#p13501 /* @@ -361,9 +358,6 @@ ISO 7816-4 Basic interindustry commands. For command APDU's. #define LEGIC_READ 0x01 #define LEGIC_WRITE 0x00 -void printIclassDumpInfo(uint8_t *iclass_dump); -void getMemConfig(uint8_t mem_cfg, uint8_t chip_cfg, uint8_t *max_blk, uint8_t *app_areas, uint8_t *kb); - /* T55x7 configuration register definitions */ #define T55x7_POR_DELAY 0x00000001 #define T55x7_ST_TERMINATOR 0x00000008 @@ -420,9 +414,6 @@ void getMemConfig(uint8_t mem_cfg, uint8_t chip_cfg, uint8_t *max_blk, uint8_t * #define T55XX_WRITE_TIMEOUT 1500 -uint32_t GetT55xxClockBit(uint32_t clock); - - // em4x05 & em4x69 chip configuration register definitions #define EM4x05_GET_BITRATE(x) (((x & 0x3F)*2)+2) #define EM4x05_SET_BITRATE(x) ((x-2)/2) @@ -551,27 +542,5 @@ uint32_t GetT55xxClockBit(uint32_t clock); #define CALYPSO_SAM_SV_DEBIT 0x54 #define CALYPSO_SAM_SV_RELOAD 0x56 -// iclass / picopass chip config structures and shared routines -typedef struct { - uint8_t app_limit; //[8] - uint8_t otp[2]; //[9-10] - uint8_t block_writelock;//[11] - uint8_t chip_config; //[12] - uint8_t mem_config; //[13] - uint8_t eas; //[14] - uint8_t fuses; //[15] -} picopass_conf_block; - - -typedef struct { - uint8_t csn[8]; - picopass_conf_block conf; - uint8_t epurse[8]; - uint8_t key_d[8]; - uint8_t key_c[8]; - uint8_t app_issuer_area[8]; -} picopass_hdr; - - #endif // PROTOCOLS_H diff --git a/include/proxmark3.h b/include/proxmark3_arm.h similarity index 99% rename from include/proxmark3.h rename to include/proxmark3_arm.h index f7903d24f7..a2f76e93dd 100644 --- a/include/proxmark3.h +++ b/include/proxmark3_arm.h @@ -11,11 +11,12 @@ #ifndef __PROXMARK3_H #define __PROXMARK3_H +#include "common.h" + // Might as well have the hardware-specific defines everywhere. #include "at91sam7s512.h" #include "config_gpio.h" #include "pm3_cmd.h" -#include "common.h" // Check bootrom.c for actual clock settings #define MAINCK 16000000 diff --git a/include/usart_defs.h b/include/usart_defs.h new file mode 100644 index 0000000000..232e80276f --- /dev/null +++ b/include/usart_defs.h @@ -0,0 +1,26 @@ +#ifndef __USART_DEFS_H +#define __USART_DEFS_H + +//#define USART_BAUD_RATE 9600 +#define USART_BAUD_RATE 115200 +// BT HC-06 physical layer runs at 128kbps +// so it's possible to gain a little bit by using 230400 +// with some risk to overflow its internal buffers: +//#define USART_BAUD_RATE 230400 + +#define USART_BUFFLEN 512 +#define USART_FIFOLEN (2*USART_BUFFLEN) + +// Higher baudrates are pointless, only increasing overflow risk + +#define USART_PARITY 'N' + +#if defined (_WIN32) +#define SERIAL_PORT_EXAMPLE_H "com3" +#elif defined(__APPLE__) +#define SERIAL_PORT_EXAMPLE_H "/dev/cu.usbmodem" +#else +#define SERIAL_PORT_EXAMPLE_H "/dev/ttyACM0" +#endif + +#endif diff --git a/recovery/Makefile b/recovery/Makefile index 601f930550..59f7f37c83 100644 --- a/recovery/Makefile +++ b/recovery/Makefile @@ -1,4 +1,4 @@ -include ../common/Makefile.common +include ../common_arm/Makefile.common BINS = bootrom.bin fullimage.bin proxmark3_recovery.bin diff --git a/client/deprecated-hid-flasher/flasher/Info.plist b/tools/deprecated-hid-flasher/flasher/Info.plist similarity index 100% rename from client/deprecated-hid-flasher/flasher/Info.plist rename to tools/deprecated-hid-flasher/flasher/Info.plist diff --git a/client/deprecated-hid-flasher/flasher/Makefile b/tools/deprecated-hid-flasher/flasher/Makefile similarity index 100% rename from client/deprecated-hid-flasher/flasher/Makefile rename to tools/deprecated-hid-flasher/flasher/Makefile diff --git a/client/deprecated-hid-flasher/flasher/elf.h b/tools/deprecated-hid-flasher/flasher/elf.h similarity index 100% rename from client/deprecated-hid-flasher/flasher/elf.h rename to tools/deprecated-hid-flasher/flasher/elf.h diff --git a/client/deprecated-hid-flasher/flasher/flash.c b/tools/deprecated-hid-flasher/flasher/flash.c similarity index 100% rename from client/deprecated-hid-flasher/flasher/flash.c rename to tools/deprecated-hid-flasher/flasher/flash.c diff --git a/client/deprecated-hid-flasher/flasher/flash.h b/tools/deprecated-hid-flasher/flasher/flash.h similarity index 100% rename from client/deprecated-hid-flasher/flasher/flash.h rename to tools/deprecated-hid-flasher/flasher/flash.h diff --git a/client/deprecated-hid-flasher/flasher/flasher.c b/tools/deprecated-hid-flasher/flasher/flasher.c similarity index 100% rename from client/deprecated-hid-flasher/flasher/flasher.c rename to tools/deprecated-hid-flasher/flasher/flasher.c diff --git a/client/deprecated-hid-flasher/flasher/obj/.dummy b/tools/deprecated-hid-flasher/flasher/obj/.dummy similarity index 100% rename from client/deprecated-hid-flasher/flasher/obj/.dummy rename to tools/deprecated-hid-flasher/flasher/obj/.dummy diff --git a/client/deprecated-hid-flasher/flasher/proxendian.h b/tools/deprecated-hid-flasher/flasher/proxendian.h similarity index 100% rename from client/deprecated-hid-flasher/flasher/proxendian.h rename to tools/deprecated-hid-flasher/flasher/proxendian.h diff --git a/client/deprecated-hid-flasher/flasher/proxmark3.h b/tools/deprecated-hid-flasher/flasher/proxmark3.h similarity index 100% rename from client/deprecated-hid-flasher/flasher/proxmark3.h rename to tools/deprecated-hid-flasher/flasher/proxmark3.h diff --git a/client/deprecated-hid-flasher/flasher/proxusb.c b/tools/deprecated-hid-flasher/flasher/proxusb.c similarity index 100% rename from client/deprecated-hid-flasher/flasher/proxusb.c rename to tools/deprecated-hid-flasher/flasher/proxusb.c diff --git a/client/deprecated-hid-flasher/flasher/proxusb.h b/tools/deprecated-hid-flasher/flasher/proxusb.h similarity index 100% rename from client/deprecated-hid-flasher/flasher/proxusb.h rename to tools/deprecated-hid-flasher/flasher/proxusb.h diff --git a/client/deprecated-hid-flasher/flasher/sleep.h b/tools/deprecated-hid-flasher/flasher/sleep.h similarity index 100% rename from client/deprecated-hid-flasher/flasher/sleep.h rename to tools/deprecated-hid-flasher/flasher/sleep.h diff --git a/client/deprecated-hid-flasher/flasher/usb_cmd.h b/tools/deprecated-hid-flasher/flasher/usb_cmd.h similarity index 100% rename from client/deprecated-hid-flasher/flasher/usb_cmd.h rename to tools/deprecated-hid-flasher/flasher/usb_cmd.h diff --git a/client/deprecated-hid-flasher/unbind-proxmark b/tools/deprecated-hid-flasher/unbind-proxmark similarity index 100% rename from client/deprecated-hid-flasher/unbind-proxmark rename to tools/deprecated-hid-flasher/unbind-proxmark diff --git a/tools/mkversion.pl b/tools/mkversion.pl index aaac146f83..997c2081bf 100644 --- a/tools/mkversion.pl +++ b/tools/mkversion.pl @@ -64,7 +64,7 @@ $fullgitinfo = substr $fullgitinfo, 0, 49; print < -#ifdef __cplusplus -extern "C" { -#endif struct Crypto1State {uint32_t odd, even;}; struct Crypto1State *crypto1_create(uint64_t); @@ -87,7 +84,4 @@ static inline int filter(uint32_t const x) { f |= 0x0d938 >> (x >> 16 & 0xf) & 1; return BIT(0xEC57E80A, f); } -#ifdef __cplusplus -} -#endif #endif