From 3eb594ce29cfc7db8cd320c4c6448722947ba47f Mon Sep 17 00:00:00 2001 From: michael Date: Wed, 18 Feb 2026 20:44:08 -0800 Subject: [PATCH] Cleaned up verbiage in user feedback --- client/src/cmdhw.c | 1533 ++++++++++++++++++++++++-------------------- include/pm3_cmd.h | 1124 ++++++++++++++++---------------- 2 files changed, 1399 insertions(+), 1258 deletions(-) diff --git a/client/src/cmdhw.c b/client/src/cmdhw.c index 6491c3fd6..d57a568e1 100644 --- a/client/src/cmdhw.c +++ b/client/src/cmdhw.c @@ -29,7 +29,7 @@ #include #endif -#include "cmdparser.h" // command_t +#include "cmdparser.h" // command_t #include "cliparser.h" #include "comms.h" #include "usart_defs.h" @@ -40,382 +40,385 @@ #include "commonutil.h" #include "preferences.h" #include "pm3_cmd.h" -#include "pmflash.h" // rdv40validation_t -#include "cmdflashmem.h" // get_signature.. -#include "uart/uart.h" // configure timeout +#include "pmflash.h" // rdv40validation_t +#include "cmdflashmem.h" // get_signature.. +#include "uart/uart.h" // configure timeout #include "util_posix.h" -#include "flash.h" // reboot to bootloader mode +#include "flash.h" // reboot to bootloader mode #include "proxgui.h" -#include "graph.h" // for graph data +#include "graph.h" // for graph data #include "lua.h" static int CmdHelp(const char *Cmd); -static void lookup_chipid_short(uint32_t iChipID, uint32_t mem_used) { +static void lookup_chipid_short(uint32_t iChipID, uint32_t mem_used) +{ const char *asBuff; - switch (iChipID) { - case 0x270B0A40: - asBuff = "AT91SAM7S512 Rev A"; - break; - case 0x270B0A4E: - case 0x270B0A4F: - asBuff = "AT91SAM7S512 Rev B"; - break; - case 0x270D0940: - asBuff = "AT91SAM7S256 Rev A"; - break; - case 0x270B0941: - asBuff = "AT91SAM7S256 Rev B"; - break; - case 0x270B0942: - asBuff = "AT91SAM7S256 Rev C"; - break; - case 0x270B0943: - asBuff = "AT91SAM7S256 Rev D"; - break; - case 0x270C0740: - asBuff = "AT91SAM7S128 Rev A"; - break; - case 0x270A0741: - asBuff = "AT91SAM7S128 Rev B"; - break; - case 0x270A0742: - asBuff = "AT91SAM7S128 Rev C"; - break; - case 0x270A0743: - asBuff = "AT91SAM7S128 Rev D"; - break; - case 0x27090540: - asBuff = "AT91SAM7S64 Rev A"; - break; - case 0x27090543: - asBuff = "AT91SAM7S64 Rev B"; - break; - case 0x27090544: - asBuff = "AT91SAM7S64 Rev C"; - break; - case 0x27080342: - asBuff = "AT91SAM7S321 Rev A"; - break; - case 0x27080340: - asBuff = "AT91SAM7S32 Rev A"; - break; - case 0x27080341: - asBuff = "AT91SAM7S32 Rev B"; - break; - case 0x27050241: - asBuff = "AT9SAM7S161 Rev A"; - break; - case 0x27050240: - asBuff = "AT91SAM7S16 Rev A"; - break; - default: - asBuff = "Unknown"; - break; + switch (iChipID) + { + case 0x270B0A40: + asBuff = "AT91SAM7S512 Rev A"; + break; + case 0x270B0A4E: + case 0x270B0A4F: + asBuff = "AT91SAM7S512 Rev B"; + break; + case 0x270D0940: + asBuff = "AT91SAM7S256 Rev A"; + break; + case 0x270B0941: + asBuff = "AT91SAM7S256 Rev B"; + break; + case 0x270B0942: + asBuff = "AT91SAM7S256 Rev C"; + break; + case 0x270B0943: + asBuff = "AT91SAM7S256 Rev D"; + break; + case 0x270C0740: + asBuff = "AT91SAM7S128 Rev A"; + break; + case 0x270A0741: + asBuff = "AT91SAM7S128 Rev B"; + break; + case 0x270A0742: + asBuff = "AT91SAM7S128 Rev C"; + break; + case 0x270A0743: + asBuff = "AT91SAM7S128 Rev D"; + break; + case 0x27090540: + asBuff = "AT91SAM7S64 Rev A"; + break; + case 0x27090543: + asBuff = "AT91SAM7S64 Rev B"; + break; + case 0x27090544: + asBuff = "AT91SAM7S64 Rev C"; + break; + case 0x27080342: + asBuff = "AT91SAM7S321 Rev A"; + break; + case 0x27080340: + asBuff = "AT91SAM7S32 Rev A"; + break; + case 0x27080341: + asBuff = "AT91SAM7S32 Rev B"; + break; + case 0x27050241: + asBuff = "AT9SAM7S161 Rev A"; + break; + case 0x27050240: + asBuff = "AT91SAM7S16 Rev A"; + break; + default: + asBuff = "Unknown"; + break; } PrintAndLogEx(NORMAL, " MCU....... " _YELLOW_("%s"), asBuff); uint32_t mem_avail = 0; - switch ((iChipID & 0xF00) >> 8) { - case 0: - mem_avail = 0; - break; - case 1: - mem_avail = 8; - break; - case 2: - mem_avail = 16; - break; - case 3: - mem_avail = 32; - break; - case 5: - mem_avail = 64; - break; - case 7: - mem_avail = 128; - break; - case 9: - mem_avail = 256; - break; - case 10: - mem_avail = 512; - break; - case 12: - mem_avail = 1024; - break; - case 14: - mem_avail = 2048; - break; + switch ((iChipID & 0xF00) >> 8) + { + case 0: + mem_avail = 0; + break; + case 1: + mem_avail = 8; + break; + case 2: + mem_avail = 16; + break; + case 3: + mem_avail = 32; + break; + case 5: + mem_avail = 64; + break; + case 7: + mem_avail = 128; + break; + case 9: + mem_avail = 256; + break; + case 10: + mem_avail = 512; + break; + case 12: + mem_avail = 1024; + break; + case 14: + mem_avail = 2048; + break; } - PrintAndLogEx(NORMAL, " Memory.... " _YELLOW_("%u") " KB ( " _YELLOW_("%2.0f%%") " used )" - , mem_avail - , mem_avail == 0 ? 0.0f : (float)mem_used / (mem_avail * 1024) * 100 - ); + PrintAndLogEx(NORMAL, " Memory.... " _YELLOW_("%u") " KB ( " _YELLOW_("%2.0f%%") " used )", mem_avail, mem_avail == 0 ? 0.0f : (float)mem_used / (mem_avail * 1024) * 100); } -static void lookupChipID(uint32_t iChipID, uint32_t mem_used) { +static void lookupChipID(uint32_t iChipID, uint32_t mem_used) +{ const char *asBuff; uint32_t mem_avail = 0; PrintAndLogEx(NORMAL, "\n [ " _YELLOW_("Hardware") " ]"); - switch (iChipID) { - case 0x270B0A40: - asBuff = "AT91SAM7S512 Rev A"; - break; - case 0x270B0A4E: - case 0x270B0A4F: - asBuff = "AT91SAM7S512 Rev B"; - break; - case 0x270D0940: - asBuff = "AT91SAM7S256 Rev A"; - break; - case 0x270B0941: - asBuff = "AT91SAM7S256 Rev B"; - break; - case 0x270B0942: - asBuff = "AT91SAM7S256 Rev C"; - break; - case 0x270B0943: - asBuff = "AT91SAM7S256 Rev D"; - break; - case 0x270C0740: - asBuff = "AT91SAM7S128 Rev A"; - break; - case 0x270A0741: - asBuff = "AT91SAM7S128 Rev B"; - break; - case 0x270A0742: - asBuff = "AT91SAM7S128 Rev C"; - break; - case 0x270A0743: - asBuff = "AT91SAM7S128 Rev D"; - break; - case 0x27090540: - asBuff = "AT91SAM7S64 Rev A"; - break; - case 0x27090543: - asBuff = "AT91SAM7S64 Rev B"; - break; - case 0x27090544: - asBuff = "AT91SAM7S64 Rev C"; - break; - case 0x27080342: - asBuff = "AT91SAM7S321 Rev A"; - break; - case 0x27080340: - asBuff = "AT91SAM7S32 Rev A"; - break; - case 0x27080341: - asBuff = "AT91SAM7S32 Rev B"; - break; - case 0x27050241: - asBuff = "AT9SAM7S161 Rev A"; - break; - case 0x27050240: - asBuff = "AT91SAM7S16 Rev A"; - break; - default: - asBuff = "Unknown"; - break; + switch (iChipID) + { + case 0x270B0A40: + asBuff = "AT91SAM7S512 Rev A"; + break; + case 0x270B0A4E: + case 0x270B0A4F: + asBuff = "AT91SAM7S512 Rev B"; + break; + case 0x270D0940: + asBuff = "AT91SAM7S256 Rev A"; + break; + case 0x270B0941: + asBuff = "AT91SAM7S256 Rev B"; + break; + case 0x270B0942: + asBuff = "AT91SAM7S256 Rev C"; + break; + case 0x270B0943: + asBuff = "AT91SAM7S256 Rev D"; + break; + case 0x270C0740: + asBuff = "AT91SAM7S128 Rev A"; + break; + case 0x270A0741: + asBuff = "AT91SAM7S128 Rev B"; + break; + case 0x270A0742: + asBuff = "AT91SAM7S128 Rev C"; + break; + case 0x270A0743: + asBuff = "AT91SAM7S128 Rev D"; + break; + case 0x27090540: + asBuff = "AT91SAM7S64 Rev A"; + break; + case 0x27090543: + asBuff = "AT91SAM7S64 Rev B"; + break; + case 0x27090544: + asBuff = "AT91SAM7S64 Rev C"; + break; + case 0x27080342: + asBuff = "AT91SAM7S321 Rev A"; + break; + case 0x27080340: + asBuff = "AT91SAM7S32 Rev A"; + break; + case 0x27080341: + asBuff = "AT91SAM7S32 Rev B"; + break; + case 0x27050241: + asBuff = "AT9SAM7S161 Rev A"; + break; + case 0x27050240: + asBuff = "AT91SAM7S16 Rev A"; + break; + default: + asBuff = "Unknown"; + break; } PrintAndLogEx(NORMAL, " --= uC: " _YELLOW_("%s"), asBuff); - switch ((iChipID & 0xE0) >> 5) { - case 1: - asBuff = "ARM946ES"; - break; - case 2: - asBuff = "ARM7TDMI"; - break; - case 4: - asBuff = "ARM920T"; - break; - case 5: - asBuff = "ARM926EJS"; - break; - default: - asBuff = "Unknown"; - break; + switch ((iChipID & 0xE0) >> 5) + { + case 1: + asBuff = "ARM946ES"; + break; + case 2: + asBuff = "ARM7TDMI"; + break; + case 4: + asBuff = "ARM920T"; + break; + case 5: + asBuff = "ARM926EJS"; + break; + default: + asBuff = "Unknown"; + break; } PrintAndLogEx(NORMAL, " --= Embedded Processor: %s", asBuff); - switch ((iChipID & 0xF0000) >> 16) { - case 1: - asBuff = "1K bytes"; - break; - case 2: - asBuff = "2K bytes"; - break; - case 3: - asBuff = "6K bytes"; - break; - case 4: - asBuff = "112K bytes"; - break; - case 5: - asBuff = "4K bytes"; - break; - case 6: - asBuff = "80K bytes"; - break; - case 7: - asBuff = "160K bytes"; - break; - case 8: - asBuff = "8K bytes"; - break; - case 9: - asBuff = "16K bytes"; - break; - case 10: - asBuff = "32K bytes"; - break; - case 11: - asBuff = "64K bytes"; - break; - case 12: - asBuff = "128K bytes"; - break; - case 13: - asBuff = "256K bytes"; - break; - case 14: - asBuff = "96K bytes"; - break; - case 15: - asBuff = "512K bytes"; - break; - default: - asBuff = "Unknown"; - break; + switch ((iChipID & 0xF0000) >> 16) + { + case 1: + asBuff = "1K bytes"; + break; + case 2: + asBuff = "2K bytes"; + break; + case 3: + asBuff = "6K bytes"; + break; + case 4: + asBuff = "112K bytes"; + break; + case 5: + asBuff = "4K bytes"; + break; + case 6: + asBuff = "80K bytes"; + break; + case 7: + asBuff = "160K bytes"; + break; + case 8: + asBuff = "8K bytes"; + break; + case 9: + asBuff = "16K bytes"; + break; + case 10: + asBuff = "32K bytes"; + break; + case 11: + asBuff = "64K bytes"; + break; + case 12: + asBuff = "128K bytes"; + break; + case 13: + asBuff = "256K bytes"; + break; + case 14: + asBuff = "96K bytes"; + break; + case 15: + asBuff = "512K bytes"; + break; + default: + asBuff = "Unknown"; + break; } PrintAndLogEx(NORMAL, " --= Internal SRAM size: %s", asBuff); - switch ((iChipID & 0xFF00000) >> 20) { - case 0x19: - asBuff = "AT91SAM9xx Series"; - break; - case 0x29: - asBuff = "AT91SAM9XExx Series"; - break; - case 0x34: - asBuff = "AT91x34 Series"; - break; - case 0x37: - asBuff = "CAP7 Series"; - break; - case 0x39: - asBuff = "CAP9 Series"; - break; - case 0x3B: - asBuff = "CAP11 Series"; - break; - case 0x40: - asBuff = "AT91x40 Series"; - break; - case 0x42: - asBuff = "AT91x42 Series"; - break; - case 0x55: - asBuff = "AT91x55 Series"; - break; - case 0x60: - asBuff = "AT91SAM7Axx Series"; - break; - case 0x61: - asBuff = "AT91SAM7AQxx Series"; - break; - case 0x63: - asBuff = "AT91x63 Series"; - break; - case 0x70: - asBuff = "AT91SAM7Sxx Series"; - break; - case 0x71: - asBuff = "AT91SAM7XCxx Series"; - break; - case 0x72: - asBuff = "AT91SAM7SExx Series"; - break; - case 0x73: - asBuff = "AT91SAM7Lxx Series"; - break; - case 0x75: - asBuff = "AT91SAM7Xxx Series"; - break; - case 0x92: - asBuff = "AT91x92 Series"; - break; - case 0xF0: - asBuff = "AT75Cxx Series"; - break; - default: - asBuff = "Unknown"; - break; + switch ((iChipID & 0xFF00000) >> 20) + { + case 0x19: + asBuff = "AT91SAM9xx Series"; + break; + case 0x29: + asBuff = "AT91SAM9XExx Series"; + break; + case 0x34: + asBuff = "AT91x34 Series"; + break; + case 0x37: + asBuff = "CAP7 Series"; + break; + case 0x39: + asBuff = "CAP9 Series"; + break; + case 0x3B: + asBuff = "CAP11 Series"; + break; + case 0x40: + asBuff = "AT91x40 Series"; + break; + case 0x42: + asBuff = "AT91x42 Series"; + break; + case 0x55: + asBuff = "AT91x55 Series"; + break; + case 0x60: + asBuff = "AT91SAM7Axx Series"; + break; + case 0x61: + asBuff = "AT91SAM7AQxx Series"; + break; + case 0x63: + asBuff = "AT91x63 Series"; + break; + case 0x70: + asBuff = "AT91SAM7Sxx Series"; + break; + case 0x71: + asBuff = "AT91SAM7XCxx Series"; + break; + case 0x72: + asBuff = "AT91SAM7SExx Series"; + break; + case 0x73: + asBuff = "AT91SAM7Lxx Series"; + break; + case 0x75: + asBuff = "AT91SAM7Xxx Series"; + break; + case 0x92: + asBuff = "AT91x92 Series"; + break; + case 0xF0: + asBuff = "AT75Cxx Series"; + break; + default: + asBuff = "Unknown"; + break; } PrintAndLogEx(NORMAL, " --= Architecture identifier: %s", asBuff); - switch ((iChipID & 0x70000000) >> 28) { - case 0: - asBuff = "ROM"; - break; - case 1: - asBuff = "ROMless or on-chip Flash"; - break; - case 2: - asBuff = "Embedded flash memory"; - break; - case 3: - asBuff = "ROM and Embedded flash memory\nNVPSIZ is ROM size\nNVPSIZ2 is Flash size"; - break; - case 4: - asBuff = "SRAM emulating ROM"; - break; - default: - asBuff = "Unknown"; - break; + switch ((iChipID & 0x70000000) >> 28) + { + case 0: + asBuff = "ROM"; + break; + case 1: + asBuff = "ROMless or on-chip Flash"; + break; + case 2: + asBuff = "Embedded flash memory"; + break; + case 3: + asBuff = "ROM and Embedded flash memory\nNVPSIZ is ROM size\nNVPSIZ2 is Flash size"; + break; + case 4: + asBuff = "SRAM emulating ROM"; + break; + default: + asBuff = "Unknown"; + break; } - switch ((iChipID & 0xF00) >> 8) { - case 0: - mem_avail = 0; - break; - case 1: - mem_avail = 8; - break; - case 2: - mem_avail = 16; - break; - case 3: - mem_avail = 32; - break; - case 5: - mem_avail = 64; - break; - case 7: - mem_avail = 128; - break; - case 9: - mem_avail = 256; - break; - case 10: - mem_avail = 512; - break; - case 12: - mem_avail = 1024; - break; - case 14: - mem_avail = 2048; - break; + switch ((iChipID & 0xF00) >> 8) + { + case 0: + mem_avail = 0; + break; + case 1: + mem_avail = 8; + break; + case 2: + mem_avail = 16; + break; + case 3: + mem_avail = 32; + break; + case 5: + mem_avail = 64; + break; + case 7: + mem_avail = 128; + break; + case 9: + mem_avail = 256; + break; + case 10: + mem_avail = 512; + break; + case 12: + mem_avail = 1024; + break; + case 14: + mem_avail = 2048; + break; } - PrintAndLogEx(NORMAL, " --= %s " _YELLOW_("%uK") " bytes ( " _YELLOW_("%2.0f%%") " used )" - , asBuff - , mem_avail - , mem_avail == 0 ? 0.0f : (float)mem_used / (mem_avail * 1024) * 100 - ); + PrintAndLogEx(NORMAL, " --= %s " _YELLOW_("%uK") " bytes ( " _YELLOW_("%2.0f%%") " used )", asBuff, mem_avail, mem_avail == 0 ? 0.0f : (float)mem_used / (mem_avail * 1024) * 100); /* switch ((iChipID & 0xF000) >> 12) { @@ -454,7 +457,8 @@ static void lookupChipID(uint32_t iChipID, uint32_t mem_used) { */ } -static int CmdDbg(const char *Cmd) { +static int CmdDbg(const char *Cmd) +{ CLIParserContext *ctx; CLIParserInit(&ctx, "hw dbg", @@ -462,8 +466,7 @@ static int CmdDbg(const char *Cmd) { "Note: option `-4`, this option may cause malfunction itself by\n" "introducing delays in time critical functions like simulation or sniffing", "hw dbg --> get current log level\n" - "hw dbg -1 --> set log level to _error_\n" - ); + "hw dbg -1 --> set log level to _error_\n"); void *argtable[] = { arg_param_begin, @@ -472,8 +475,7 @@ static int CmdDbg(const char *Cmd) { arg_lit0("2", NULL, "plus information messages"), arg_lit0("3", NULL, "plus debug messages"), arg_lit0("4", NULL, "print even debug messages in timing critical functions"), - arg_param_end - }; + arg_param_end}; CLIExecWithReturn(ctx, Cmd, argtable, true); bool lv0 = arg_get_lit(ctx, 1); bool lv1 = arg_get_lit(ctx, 2); @@ -482,7 +484,8 @@ static int CmdDbg(const char *Cmd) { bool lv4 = arg_get_lit(ctx, 5); CLIParserFree(ctx); - if ((lv0 + lv1 + lv2 + lv3 + lv4) > 1) { + if ((lv0 + lv1 + lv2 + lv3 + lv4) > 1) + { PrintAndLogEx(INFO, "Can only set one debug level"); return PM3_EINVARG; } @@ -492,30 +495,31 @@ static int CmdDbg(const char *Cmd) { return PM3_EFAILED; const char *dbglvlstr; - switch (curr) { - case DBG_NONE: - dbglvlstr = "none"; - break; - case DBG_ERROR: - dbglvlstr = "error"; - break; - case DBG_INFO: - dbglvlstr = "info"; - break; - case DBG_DEBUG: - dbglvlstr = "debug"; - break; - case DBG_EXTENDED: - dbglvlstr = "extended"; - break; - default: - dbglvlstr = "unknown"; - break; + switch (curr) + { + case DBG_NONE: + dbglvlstr = "none"; + break; + case DBG_ERROR: + dbglvlstr = "error"; + break; + case DBG_INFO: + dbglvlstr = "info"; + break; + case DBG_DEBUG: + dbglvlstr = "debug"; + break; + case DBG_EXTENDED: + dbglvlstr = "extended"; + break; + default: + dbglvlstr = "unknown"; + break; } - PrintAndLogEx(INFO, " Current debug log level..... %d ( " _YELLOW_("%s")" )", curr, dbglvlstr); + PrintAndLogEx(INFO, " Current debug log level..... %d ( " _YELLOW_("%s") " )", curr, dbglvlstr); - - if ((lv0 + lv1 + lv2 + lv3 + lv4) == 1) { + if ((lv0 + lv1 + lv2 + lv3 + lv4) == 1) + { uint8_t dbg = 0; if (lv0) dbg = 0; @@ -534,20 +538,19 @@ static int CmdDbg(const char *Cmd) { return PM3_SUCCESS; } -static int CmdDetectReader(const char *Cmd) { +static int CmdDetectReader(const char *Cmd) +{ CLIParserContext *ctx; CLIParserInit(&ctx, "hw detectreader", "Start to detect presences of reader field", "hw detectreader\n" - "hw detectreader -L\n" - ); + "hw detectreader -L\n"); void *argtable[] = { arg_param_begin, arg_lit0("L", "LF", "only detect low frequency 125/134 kHz"), arg_lit0("H", "HF", "only detect high frequency 13.56 MHZ"), - arg_param_end - }; + arg_param_end}; CLIExecWithReturn(ctx, Cmd, argtable, true); bool lf = arg_get_lit(ctx, 1); bool hf = arg_get_lit(ctx, 2); @@ -557,9 +560,12 @@ static int CmdDetectReader(const char *Cmd) { // 1: LF_ONLY // 2: HF_ONLY uint8_t arg = 0; - if (lf == true && hf == false) { + if (lf == true && hf == false) + { arg = 1; - } else if (hf == true && lf == false) { + } + else if (hf == true && lf == false) + { arg = 2; } @@ -567,15 +573,19 @@ static int CmdDetectReader(const char *Cmd) { SendCommandNG(CMD_LISTEN_READER_FIELD, (uint8_t *)&arg, sizeof(arg)); PrintAndLogEx(INFO, "Press " _GREEN_("pm3 button") " or " _GREEN_("") " to change modes and exit"); - for (;;) { - if (kbd_enter_pressed()) { + for (;;) + { + if (kbd_enter_pressed()) + { SendCommandNG(CMD_BREAK_LOOP, NULL, 0); PrintAndLogEx(DEBUG, _GREEN_("") " pressed"); } PacketResponseNG resp; - if (WaitForResponseTimeout(CMD_LISTEN_READER_FIELD, &resp, 1000)) { - if (resp.status != PM3_EOPABORTED) { + if (WaitForResponseTimeout(CMD_LISTEN_READER_FIELD, &resp, 1000)) + { + if (resp.status != PM3_EOPABORTED) + { PrintAndLogEx(ERR, "Unexpected response: %d", resp.status); } break; @@ -586,17 +596,16 @@ static int CmdDetectReader(const char *Cmd) { } // ## FPGA Control -static int CmdFPGAOff(const char *Cmd) { +static int CmdFPGAOff(const char *Cmd) +{ CLIParserContext *ctx; CLIParserInit(&ctx, "hw fpgaoff", "Turn of fpga and antenna field", - "hw fpgaoff\n" - ); + "hw fpgaoff\n"); void *argtable[] = { arg_param_begin, - arg_param_end - }; + arg_param_end}; CLIExecWithReturn(ctx, Cmd, argtable, true); CLIParserFree(ctx); @@ -605,19 +614,18 @@ static int CmdFPGAOff(const char *Cmd) { return PM3_SUCCESS; } -static int CmdLCD(const char *Cmd) { +static int CmdLCD(const char *Cmd) +{ CLIParserContext *ctx; CLIParserInit(&ctx, "hw lcd", "Send command/data to LCD", - "hw lcd -r AA -c 03 -> sends 0xAA three times" - ); + "hw lcd -r AA -c 03 -> sends 0xAA three times"); void *argtable[] = { arg_param_begin, - arg_int1("r", "raw", "", "data "), - arg_int1("c", "cnt", "", "number of times to send"), - arg_param_end - }; + arg_int1("r", "raw", "", "data "), + arg_int1("c", "cnt", "", "number of times to send"), + arg_param_end}; CLIExecWithReturn(ctx, Cmd, argtable, true); int r_len = 0; @@ -625,29 +633,30 @@ static int CmdLCD(const char *Cmd) { CLIGetHexWithReturn(ctx, 1, raw, &r_len); int j = arg_get_int_def(ctx, 2, 1); CLIParserFree(ctx); - if (j < 1) { + if (j < 1) + { PrintAndLogEx(WARNING, "Count must be larger than zero"); return PM3_EINVARG; } - while (j--) { + while (j--) + { clearCommandBuffer(); SendCommandMIX(CMD_LCD, raw[0], 0, 0, NULL, 0); } return PM3_SUCCESS; } -static int CmdLCDReset(const char *Cmd) { +static int CmdLCDReset(const char *Cmd) +{ CLIParserContext *ctx; CLIParserInit(&ctx, "hw lcdreset", "Hardware reset LCD", - "hw lcdreset\n" - ); + "hw lcdreset\n"); void *argtable[] = { arg_param_begin, - arg_param_end - }; + arg_param_end}; CLIExecWithReturn(ctx, Cmd, argtable, true); CLIParserFree(ctx); clearCommandBuffer(); @@ -655,13 +664,13 @@ static int CmdLCDReset(const char *Cmd) { return PM3_SUCCESS; } -static int CmdReadmem(const char *Cmd) { +static int CmdReadmem(const char *Cmd) +{ CLIParserContext *ctx; CLIParserInit(&ctx, "hw readmem", "Reads processor flash memory into a file or views on console", "hw readmem -f myfile -> save 512KB processor flash memory to file\n" - "hw readmem -a 8192 -l 512 -> display 512 bytes from offset 8192\n" - ); + "hw readmem -a 8192 -l 512 -> display 512 bytes from offset 8192\n"); void *argtable[] = { arg_param_begin, @@ -670,8 +679,7 @@ static int CmdReadmem(const char *Cmd) { arg_str0("f", "file", "", "save to file"), arg_u64_0("c", "cols", "", "column breaks"), arg_lit0("r", "raw", "use raw address mode: read from anywhere, not just flash"), - arg_param_end - }; + arg_param_end}; CLIExecWithReturn(ctx, Cmd, argtable, false); // check for -file option first to determine the output mode @@ -690,25 +698,30 @@ static int CmdReadmem(const char *Cmd) { CLIParserFree(ctx); uint8_t *buffer = calloc(len, sizeof(uint8_t)); - if (buffer == NULL) { + if (buffer == NULL) + { PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } const char *flash_str = raw ? "" : " flash"; - PrintAndLogEx(INFO, "reading "_YELLOW_("%u")" bytes from processor%s memory", + PrintAndLogEx(INFO, "reading " _YELLOW_("%u") " bytes from processor%s memory", len, flash_str); DeviceMemType_t type = raw ? MCU_MEM : MCU_FLASH; - if (!GetFromDevice(type, buffer, len, address, NULL, 0, NULL, -1, true)) { + if (!GetFromDevice(type, buffer, len, address, NULL, 0, NULL, -1, true)) + { PrintAndLogEx(FAILED, "ERROR; reading from MCU flash memory"); free(buffer); return PM3_EFLASH; } - if (save_to_file) { + if (save_to_file) + { saveFile(filename, ".bin", buffer, len); - } else { + } + else + { PrintAndLogEx(INFO, "---- " _CYAN_("processor%s memory") " ----", flash_str); print_hex_break(buffer, len, breaks); } @@ -717,17 +730,16 @@ static int CmdReadmem(const char *Cmd) { return PM3_SUCCESS; } -static int CmdReset(const char *Cmd) { +static int CmdReset(const char *Cmd) +{ CLIParserContext *ctx; CLIParserInit(&ctx, "hw reset", "Reset the Proxmark3 device.", - "hw reset" - ); + "hw reset"); void *argtable[] = { arg_param_begin, - arg_param_end - }; + arg_param_end}; CLIExecWithReturn(ctx, Cmd, argtable, true); CLIParserFree(ctx); clearCommandBuffer(); @@ -740,52 +752,52 @@ static int CmdReset(const char *Cmd) { * Sets the divisor for LF frequency clock: lets the user choose any LF frequency below * 600kHz. */ -static int CmdSetDivisor(const char *Cmd) { +static int CmdSetDivisor(const char *Cmd) +{ CLIParserContext *ctx; CLIParserInit(&ctx, "hw setlfdivisor", "Drive LF antenna at 12 MHz / (divisor + 1).", - "hw setlfdivisor -d 88" - ); + "hw setlfdivisor -d 88"); void *argtable[] = { arg_param_begin, arg_u64_1("d", "div", "", "19 - 255 divisor value (def 95)"), - arg_param_end - }; + arg_param_end}; CLIExecWithReturn(ctx, Cmd, argtable, true); uint8_t arg = arg_get_u32_def(ctx, 1, 95); CLIParserFree(ctx); - if (arg < 19) { + if (arg < 19) + { PrintAndLogEx(ERR, "Divisor must be between " _YELLOW_("19") " and " _YELLOW_("255")); return PM3_EINVARG; } // 12 000 000 (12MHz) clearCommandBuffer(); SendCommandNG(CMD_LF_SET_DIVISOR, (uint8_t *)&arg, sizeof(arg)); - PrintAndLogEx(SUCCESS, "Divisor set, expected " _YELLOW_("%.1f")" kHz", ((double)12000 / (arg + 1))); + PrintAndLogEx(SUCCESS, "Divisor set, expected " _YELLOW_("%.1f") " kHz", ((double)12000 / (arg + 1))); return PM3_SUCCESS; } -static int CmdSetHFThreshold(const char *Cmd) { +static int CmdSetHFThreshold(const char *Cmd) +{ CLIParserContext *ctx; CLIParserInit(&ctx, "hw sethfthresh", "Set thresholds in HF/14a and Legic mode.", - "hw sethfthresh -t 7 -i 20 -l 8" - ); + "hw sethfthresh -t 7 -i 20 -l 8"); void *argtable[] = { arg_param_begin, arg_int0("t", "thresh", "", "threshold, used in 14a reader mode (def 7)"), arg_int0("i", "high", "", "high threshold, used in 14a sniff mode (def 20)"), arg_int0("l", "legic", "", "threshold used in Legic mode (def 8)"), - arg_param_end - }; + arg_param_end}; CLIExecWithReturn(ctx, Cmd, argtable, true); - struct { + struct + { uint8_t threshold; uint8_t threshold_high; uint8_t legic_threshold; @@ -796,7 +808,8 @@ static int CmdSetHFThreshold(const char *Cmd) { params.legic_threshold = arg_get_int_def(ctx, 3, 8); CLIParserFree(ctx); - if ((params.threshold < 1) || (params.threshold > 63) || (params.threshold_high < 1) || (params.threshold_high > 63)) { + if ((params.threshold < 1) || (params.threshold > 63) || (params.threshold_high < 1) || (params.threshold_high > 63)) + { PrintAndLogEx(ERR, "Thresholds must be between " _YELLOW_("1") " and " _YELLOW_("63")); return PM3_EINVARG; } @@ -807,13 +820,13 @@ static int CmdSetHFThreshold(const char *Cmd) { return PM3_SUCCESS; } -static int CmdSetMux(const char *Cmd) { +static int CmdSetMux(const char *Cmd) +{ CLIParserContext *ctx; CLIParserInit(&ctx, "hw setmux", "Set the ADC mux to a specific value", - "hw setmux --hipkd -> set HIGH PEAK\n" - ); + "hw setmux --hipkd -> set HIGH PEAK\n"); void *argtable[] = { arg_param_begin, @@ -821,8 +834,7 @@ static int CmdSetMux(const char *Cmd) { arg_lit0(NULL, "loraw", "low raw"), arg_lit0(NULL, "hipkd", "high peak"), arg_lit0(NULL, "hiraw", "high raw"), - arg_param_end - }; + arg_param_end}; CLIExecWithReturn(ctx, Cmd, argtable, true); bool lopkd = arg_get_lit(ctx, 1); bool loraw = arg_get_lit(ctx, 2); @@ -830,13 +842,15 @@ static int CmdSetMux(const char *Cmd) { bool hiraw = arg_get_lit(ctx, 4); CLIParserFree(ctx); - if ((lopkd + loraw + hipkd + hiraw) > 1) { + if ((lopkd + loraw + hipkd + hiraw) > 1) + { PrintAndLogEx(INFO, "Can only set one mux"); return PM3_EINVARG; } #ifdef WITH_FPC_USART - if (loraw || hiraw) { + if (loraw || hiraw) + { PrintAndLogEx(INFO, "this ADC mux option is unavailable on RDV4 compiled with FPC USART"); return PM3_EINVARG; } @@ -857,23 +871,23 @@ static int CmdSetMux(const char *Cmd) { return PM3_SUCCESS; } -static int CmdStandalone(const char *Cmd) { +static int CmdStandalone(const char *Cmd) +{ CLIParserContext *ctx; CLIParserInit(&ctx, "hw standalone", "Start standalone mode", "hw standalone -> start \n" - "hw standalone -a 1 -> start and send arg 1" - ); + "hw standalone -a 1 -> start and send arg 1"); void *argtable[] = { arg_param_begin, arg_u64_0("a", "arg", "", "argument byte"), arg_str0("b", NULL, "", "UniSniff arg: 14a, 14b, 15, iclass"), - arg_param_end - }; + arg_param_end}; CLIExecWithReturn(ctx, Cmd, argtable, true); - struct p { + struct p + { uint8_t arg; uint8_t mlen; uint8_t mode[10]; @@ -882,7 +896,8 @@ static int CmdStandalone(const char *Cmd) { packet.arg = arg_get_u32_def(ctx, 1, 1); int mlen = 0; CLIParamStrToBuf(arg_get_str(ctx, 2), packet.mode, sizeof(packet.mode), &mlen); - if (mlen) { + if (mlen) + { packet.mlen = mlen; } CLIParserFree(ctx); @@ -891,7 +906,8 @@ static int CmdStandalone(const char *Cmd) { return PM3_SUCCESS; } -static int CmdDecay(const char *Cmd) { +static int CmdDecay(const char *Cmd) +{ CLIParserContext *ctx; CLIParserInit(&ctx, "hw decay", @@ -901,15 +917,13 @@ static int CmdDecay(const char *Cmd) { "(unloaded, booster board, damaged) produces different decay profiles.", "hw decay\n" "hw decay --ms 100 --> stabilize for 100ms before measurement\n" - "hw decay --us 5000 --> measure 5ms decay window\n" - ); + "hw decay --us 5000 --> measure 5ms decay window\n"); void *argtable[] = { arg_param_begin, arg_int0(NULL, "ms", "", "Field stabilization time in ms (default: 50)"), arg_int0(NULL, "us", "", "Measurement window in us (default: 2000)"), - arg_param_end - }; + arg_param_end}; CLIExecWithReturn(ctx, Cmd, argtable, true); uint16_t stabilize_ms = arg_get_int_def(ctx, 1, 50); @@ -917,7 +931,8 @@ static int CmdDecay(const char *Cmd) { CLIParserFree(ctx); // Build parameter packet - struct { + struct + { uint16_t stabilize_ms; uint16_t measure_us; uint8_t num_pulses; @@ -926,8 +941,7 @@ static int CmdDecay(const char *Cmd) { .stabilize_ms = stabilize_ms, .measure_us = measure_us, .num_pulses = 1, - .padding = {0} - }; + .padding = {0}}; PrintAndLogEx(INFO, "Measuring HF antenna decay..."); PrintAndLogEx(INFO, " Field stabilization: " _YELLOW_("%d") " ms", stabilize_ms); @@ -937,12 +951,14 @@ static int CmdDecay(const char *Cmd) { SendCommandNG(CMD_HF_DECAY, (uint8_t *)¶ms, sizeof(params)); PacketResponseNG resp; - if (WaitForResponseTimeout(CMD_HF_DECAY, &resp, 5000) == false) { + if (WaitForResponseTimeout(CMD_HF_DECAY, &resp, 5000) == false) + { PrintAndLogEx(WARNING, "Timeout waiting for decay measurement"); return PM3_ETIMEOUT; } - if (resp.status != PM3_SUCCESS) { + if (resp.status != PM3_SUCCESS) + { PrintAndLogEx(WARNING, "Decay measurement failed"); return PM3_ESOFT; } @@ -962,7 +978,8 @@ static int CmdDecay(const char *Cmd) { PrintAndLogEx(SUCCESS, "Sample interval........ ~%d us", sample_interval_us); PrintAndLogEx(SUCCESS, "Total window........... %d us", measure_window_us); - if (num_samples == 0) { + if (num_samples == 0) + { PrintAndLogEx(WARNING, "No samples captured"); return PM3_ESOFT; } @@ -976,13 +993,14 @@ static int CmdDecay(const char *Cmd) { PrintAndLogEx(INFO, " idx | time (us) | raw | %% of peak"); PrintAndLogEx(INFO, "-----+-----------+-------+-------------"); - for (uint16_t i = 0; i < num_samples; i++) { + for (uint16_t i = 0; i < num_samples; i++) + { uint32_t time_us = (num_samples > 1) - ? (uint32_t)i * measure_window_us / (num_samples - 1) - : 0; + ? (uint32_t)i * measure_window_us / (num_samples - 1) + : 0; double pct = (ref_mv > 0) - ? 100.0 * samples[i] / ref_mv - : 0; + ? 100.0 * samples[i] / ref_mv + : 0; PrintAndLogEx(INFO, " %3d | %7d | %5d | %.1f%%", i, time_us, samples[i], pct); } @@ -990,20 +1008,25 @@ static int CmdDecay(const char *Cmd) { // Find time to 50% decay (relative to first sample) uint16_t half_ref = ref_mv / 2; int t_half_idx = -1; - for (uint16_t i = 0; i < num_samples; i++) { - if (samples[i] <= half_ref) { + for (uint16_t i = 0; i < num_samples; i++) + { + if (samples[i] <= half_ref) + { t_half_idx = i; break; } } PrintAndLogEx(NORMAL, ""); - if (t_half_idx >= 0) { + if (t_half_idx >= 0) + { uint32_t t_half_us = (num_samples > 1) - ? (uint32_t)t_half_idx * measure_window_us / (num_samples - 1) - : 0; + ? (uint32_t)t_half_idx * measure_window_us / (num_samples - 1) + : 0; PrintAndLogEx(SUCCESS, "Time to 50%% decay..... ~" _YELLOW_("%d") " us (sample %d)", t_half_us, t_half_idx); - } else { + } + else + { PrintAndLogEx(INFO, "Voltage did not reach 50%% decay within measurement window"); } @@ -1014,7 +1037,8 @@ static int CmdDecay(const char *Cmd) { PrintAndLogEx(INFO, "Note: decay samples use fast ADC (~5us/sample, relative values)"); // Load into graph window - for (uint16_t i = 0; i < num_samples; i++) { + for (uint16_t i = 0; i < num_samples; i++) + { g_GraphBuffer[i] = (int)samples[i]; } g_GraphTraceLen = num_samples; @@ -1028,28 +1052,27 @@ static int CmdDecay(const char *Cmd) { return PM3_SUCCESS; } -static int CmdTune(const char *Cmd) { +static int CmdTune(const char *Cmd) +{ CLIParserContext *ctx; CLIParserInit(&ctx, "hw tune", "Measure tuning of device antenna. Results shown in graph window.\n" "This command doesn't actively tune your antennas, \n" "it's only informative by measuring voltage that the antennas will generate", - "hw tune" - ); + "hw tune"); void *argtable[] = { arg_param_begin, - arg_param_end - }; + arg_param_end}; CLIExecWithReturn(ctx, Cmd, argtable, true); CLIParserFree(ctx); -#define NON_VOLTAGE 1000 -#define LF_UNUSABLE_V 2000 -#define LF_MARGINAL_V 10000 -#define HF_UNUSABLE_V 3000 -#define HF_MARGINAL_V 5000 -#define ANTENNA_ERROR 1.00 // current algo has 3% error margin. +#define NON_VOLTAGE 1000 +#define LF_UNUSABLE_V 2000 +#define LF_MARGINAL_V 10000 +#define HF_UNUSABLE_V 3000 +#define HF_MARGINAL_V 5000 +#define ANTENNA_ERROR 1.00 // current algo has 3% error margin. PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "-------- " _CYAN_("Reminder") " ----------------------------"); @@ -1069,10 +1092,12 @@ static int CmdTune(const char *Cmd) { PacketResponseNG resp; PrintAndLogEx(INPLACE, "% 3i", timeout_max - timeout); - while (WaitForResponseTimeout(CMD_MEASURE_ANTENNA_TUNING, &resp, 500) == false) { + while (WaitForResponseTimeout(CMD_MEASURE_ANTENNA_TUNING, &resp, 500) == false) + { fflush(stdout); - if (timeout >= timeout_max) { + if (timeout >= timeout_max) + { PrintAndLogEx(WARNING, "\nNo response from Proxmark3. Aborting..."); return PM3_ETIMEOUT; } @@ -1083,7 +1108,8 @@ static int CmdTune(const char *Cmd) { PrintAndLogEx(NORMAL, ""); - if (resp.status != PM3_SUCCESS) { + if (resp.status != PM3_SUCCESS) + { PrintAndLogEx(WARNING, "Antenna tuning failed"); return PM3_ESOFT; } @@ -1091,7 +1117,8 @@ static int CmdTune(const char *Cmd) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "-------- " _CYAN_("LF Antenna") " ----------"); // in mVolt - struct p { + struct p + { uint32_t v_lf134; uint32_t v_lf125; uint32_t v_lfconf; @@ -1121,16 +1148,20 @@ static int CmdTune(const char *Cmd) { const double vdd_other = 5400; double vdd = IfPm3Rdv4Fw() ? vdd_rdv4 : vdd_other; - if (package->peak_v > NON_VOLTAGE && package->peak_f > 0) { + if (package->peak_v > NON_VOLTAGE && package->peak_f > 0) + { // Q measure with Q=f/delta_f double v_3db_scaled = (double)(package->peak_v * 0.707) / 512; // /512 == >>9 uint32_t s2 = 0, s4 = 0; - for (int i = 1; i < 256; i++) { - if ((s2 == 0) && (package->results[i] > v_3db_scaled)) { + for (int i = 1; i < 256; i++) + { + if ((s2 == 0) && (package->results[i] > v_3db_scaled)) + { s2 = i; } - if ((s2 != 0) && (package->results[i] < v_3db_scaled)) { + if ((s2 != 0) && (package->results[i] < v_3db_scaled)) + { s4 = i; break; } @@ -1139,7 +1170,8 @@ static int CmdTune(const char *Cmd) { PrintAndLogEx(SUCCESS, ""); PrintAndLogEx(SUCCESS, "Approx. Q factor measurement"); double lfq1 = 0; - if (s4 != 0) { // we got all our points of interest + if (s4 != 0) + { // we got all our points of interest double a = package->results[s2 - 1]; double b = package->results[s2]; double f1 = LF_DIV2FREQ(s2 - 1 + (v_3db_scaled - a) / (b - a)); @@ -1154,19 +1186,22 @@ static int CmdTune(const char *Cmd) { double lfq2 = (double)package->peak_v * 3.14 / 2 / vdd; PrintAndLogEx(SUCCESS, "Peak voltage.......... " _YELLOW_("%.1lf"), lfq2); // cross-check results - if (lfq1 > 3) { + if (lfq1 > 3) + { double approx_vdd = (double)package->peak_v * 3.14 / 2 / lfq1; // Got 8858 on a RDV4 with large antenna 134/14 // Got 8761 on a non-RDV4 const double approx_vdd_other_max = 8840; // 1% over threshold and supposedly non-RDV4 - if ((approx_vdd > approx_vdd_other_max * 1.01) && (!IfPm3Rdv4Fw())) { + if ((approx_vdd > approx_vdd_other_max * 1.01) && (!IfPm3Rdv4Fw())) + { PrintAndLogEx(WARNING, "Contradicting measures seem to indicate you're running a " _YELLOW_("PM3GENERIC firmware on a RDV4")); PrintAndLogEx(WARNING, "False positives is possible but please check your setup"); } // 1% below threshold and supposedly RDV4 - if ((approx_vdd < approx_vdd_other_max * 0.99) && (IfPm3Rdv4Fw())) { + if ((approx_vdd < approx_vdd_other_max * 0.99) && (IfPm3Rdv4Fw())) + { PrintAndLogEx(WARNING, "Contradicting measures seem to indicate you're running a " _YELLOW_("PM3_RDV4 firmware on a generic device")); PrintAndLogEx(WARNING, "False positives is possible but please check your setup"); } @@ -1183,13 +1218,14 @@ static int CmdTune(const char *Cmd) { else snprintf(judgement, sizeof(judgement), _GREEN_("ok")); - //PrintAndLogEx((package->peak_v < LF_UNUSABLE_V) ? WARNING : SUCCESS, "LF antenna ( %s )", judgement); + // PrintAndLogEx((package->peak_v < LF_UNUSABLE_V) ? WARNING : SUCCESS, "LF antenna ( %s )", judgement); PrintAndLogEx((package->peak_v < LF_UNUSABLE_V) ? WARNING : SUCCESS, "LF antenna............ %s", judgement); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "-------- " _CYAN_("HF Antenna") " ----------"); // HF evaluation - if (package->v_hf > NON_VOLTAGE) { + if (package->v_hf > NON_VOLTAGE) + { PrintAndLogEx(SUCCESS, "13.56 MHz............. " _BACK_GREEN_("%5.2f") " V", (package->v_hf * ANTENNA_ERROR) / 1000.0); } @@ -1199,8 +1235,10 @@ static int CmdTune(const char *Cmd) { // for booster board. With a booster, the first fast-ADC decay sample reads // 50-500 (rapid discharge). Without a booster, it reads >1000. bool hf_booster_detected = false; - if (!IfPm3Rdv4Fw() && package->v_hf < HF_MARGINAL_V) { - struct { + if (!IfPm3Rdv4Fw() && package->v_hf < HF_MARGINAL_V) + { + struct + { uint16_t stabilize_ms; uint16_t measure_us; uint8_t num_pulses; @@ -1209,26 +1247,27 @@ static int CmdTune(const char *Cmd) { .stabilize_ms = 50, .measure_us = 50, .num_pulses = 1, - .padding = {0} - }; + .padding = {0}}; clearCommandBuffer(); SendCommandNG(CMD_HF_DECAY, (uint8_t *)&decay_params, sizeof(decay_params)); PacketResponseNG decay_resp; - if (WaitForResponseTimeout(CMD_HF_DECAY, &decay_resp, 3000) - && decay_resp.status == PM3_SUCCESS) { + if (WaitForResponseTimeout(CMD_HF_DECAY, &decay_resp, 3000) && decay_resp.status == PM3_SUCCESS) + { uint16_t decay_num = decay_resp.data.asBytes[2] | (decay_resp.data.asBytes[3] << 8); uint16_t *decay_samples = (uint16_t *)(decay_resp.data.asBytes + 8); - if (decay_num > 0 && decay_samples[0] >= 50 && decay_samples[0] <= 500) { + if (decay_num > 0 && decay_samples[0] >= 50 && decay_samples[0] <= 500) + { hf_booster_detected = true; } } } - if (hf_booster_detected) { + if (hf_booster_detected) + { PrintAndLogEx(SUCCESS, ""); PrintAndLogEx(SUCCESS, "Your HF antenna measurement shows"); PrintAndLogEx(SUCCESS, "low voltage that is consistent"); @@ -1237,11 +1276,14 @@ static int CmdTune(const char *Cmd) { PrintAndLogEx(SUCCESS, "booster board installed, either"); PrintAndLogEx(SUCCESS, "your antenna is malfunctioning or"); PrintAndLogEx(SUCCESS, "you have a tag on the HF antenna."); - } else { + } + else + { PrintAndLogEx(SUCCESS, ""); PrintAndLogEx(SUCCESS, "Approx. Q factor measurement"); - if (package->v_hf >= HF_UNUSABLE_V) { + if (package->v_hf >= HF_UNUSABLE_V) + { // Q measure with Vlr=Q*(2*Vdd/pi) double hfq = (double)package->v_hf * 3.14 / 2 / vdd; PrintAndLogEx(SUCCESS, "Peak voltage.......... " _YELLOW_("%.1lf"), hfq); @@ -1259,11 +1301,11 @@ static int CmdTune(const char *Cmd) { // If HF voltage is ok/marginal but below 13V, check for // surface interference via decay measurement. // Only on PM3 Easy — RDV4 has different voltage divider. - if (!IfPm3Rdv4Fw() - && package->v_hf >= HF_MARGINAL_V - && package->v_hf < 13000) { + if (!IfPm3Rdv4Fw() && package->v_hf >= HF_MARGINAL_V && package->v_hf < 13000) + { - struct { + struct + { uint16_t stabilize_ms; uint16_t measure_us; uint8_t num_pulses; @@ -1272,8 +1314,7 @@ static int CmdTune(const char *Cmd) { .stabilize_ms = 50, .measure_us = 50, .num_pulses = 1, - .padding = {0} - }; + .padding = {0}}; clearCommandBuffer(); SendCommandNG(CMD_HF_DECAY, @@ -1282,26 +1323,27 @@ static int CmdTune(const char *Cmd) { PacketResponseNG surface_resp; if (WaitForResponseTimeout( - CMD_HF_DECAY, - &surface_resp, 3000) - && surface_resp.status == PM3_SUCCESS) { + CMD_HF_DECAY, + &surface_resp, 3000) && + surface_resp.status == PM3_SUCCESS) + { - uint16_t sn = surface_resp.data.asBytes[2] - | (surface_resp.data.asBytes[3] << 8); + uint16_t sn = surface_resp.data.asBytes[2] | (surface_resp.data.asBytes[3] << 8); uint16_t *ss = (uint16_t *)(surface_resp.data.asBytes + 8); - if (sn > 0 && ss[0] >= 600 && ss[0] <= 900) { + if (sn > 0 && ss[0] >= 600 && ss[0] <= 900) + { PrintAndLogEx(SUCCESS, ""); PrintAndLogEx(SUCCESS, - "The surface your proxmark" - " may be on could"); + "The surface your proxmark" + " is on could"); PrintAndLogEx(SUCCESS, - "contain interfering" - " materials. Try again"); + "contain interfering" + " materials. Try again"); PrintAndLogEx(SUCCESS, - "while holding the" - " proxmark in free space."); + "while holding the" + " proxmark in free space."); } } } @@ -1310,28 +1352,26 @@ static int CmdTune(const char *Cmd) { // graph LF measurements // even here, these values has 3% error. uint16_t test1 = 0; - for (int i = 0; i < 256; i++) { + for (int i = 0; i < 256; i++) + { g_GraphBuffer[i] = package->results[i] - 128; test1 += package->results[i]; } - if (test1 > 0) { + if (test1 > 0) + { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "-------- " _CYAN_("LF tuning graph") " ------------"); - PrintAndLogEx(SUCCESS, "Orange line - divisor %d / %.2f kHz" - , LF_DIVISOR_125 - , LF_DIV2FREQ(LF_DIVISOR_125) - ); - PrintAndLogEx(SUCCESS, "Blue line - divisor %d / %.2f kHz\n\n" - , LF_DIVISOR_134 - , LF_DIV2FREQ(LF_DIVISOR_134) - ); + PrintAndLogEx(SUCCESS, "Orange line - divisor %d / %.2f kHz", LF_DIVISOR_125, LF_DIV2FREQ(LF_DIVISOR_125)); + PrintAndLogEx(SUCCESS, "Blue line - divisor %d / %.2f kHz\n\n", LF_DIVISOR_134, LF_DIV2FREQ(LF_DIVISOR_134)); g_GraphTraceLen = 256; g_MarkerC.pos = LF_DIVISOR_125; g_MarkerD.pos = LF_DIVISOR_134; ShowGraphWindow(); RepaintGraphWindow(); - } else { + } + else + { PrintAndLogEx(FAILED, "\nAll values are zero. Not showing LF tuning graph\n\n"); } @@ -1341,57 +1381,60 @@ static int CmdTune(const char *Cmd) { return PM3_SUCCESS; } -static int CmdVersion(const char *Cmd) { +static int CmdVersion(const char *Cmd) +{ CLIParserContext *ctx; CLIParserInit(&ctx, "hw version", "Show version information about the client and the connected Proxmark3", - "hw version" - ); + "hw version"); void *argtable[] = { arg_param_begin, - arg_param_end - }; + arg_param_end}; CLIExecWithReturn(ctx, Cmd, argtable, true); CLIParserFree(ctx); pm3_version(true, false); return PM3_SUCCESS; } -static int CmdStatus(const char *Cmd) { +static int CmdStatus(const char *Cmd) +{ CLIParserContext *ctx; CLIParserInit(&ctx, "hw status", "Show runtime status information about the connected Proxmark3", "hw status\n" - "hw status --ms 1000 -> Test connection speed with 1000ms timeout\n" - ); + "hw status --ms 1000 -> Test connection speed with 1000ms timeout\n"); void *argtable[] = { arg_param_begin, arg_int0("m", "ms", "", "speed test timeout in micro seconds"), - arg_param_end - }; + arg_param_end}; CLIExecWithReturn(ctx, Cmd, argtable, true); int32_t speedTestTimeout = arg_get_int_def(ctx, 1, -1); CLIParserFree(ctx); clearCommandBuffer(); PacketResponseNG resp; - if (speedTestTimeout < 0) { + if (speedTestTimeout < 0) + { speedTestTimeout = 0; SendCommandNG(CMD_STATUS, NULL, 0); - } else { + } + else + { SendCommandNG(CMD_STATUS, (uint8_t *)&speedTestTimeout, sizeof(speedTestTimeout)); } - if (WaitForResponseTimeout(CMD_STATUS, &resp, 2000 + speedTestTimeout) == false) { + if (WaitForResponseTimeout(CMD_STATUS, &resp, 2000 + speedTestTimeout) == false) + { PrintAndLogEx(WARNING, "Status command timeout. Communication speed test timed out"); return PM3_ETIMEOUT; } return PM3_SUCCESS; } -int handle_tearoff(tearoff_params_t *params, bool verbose) { +int handle_tearoff(tearoff_params_t *params, bool verbose) +{ if (params == NULL) return PM3_EINVARG; @@ -1399,12 +1442,14 @@ int handle_tearoff(tearoff_params_t *params, bool verbose) { clearCommandBuffer(); SendCommandNG(CMD_SET_TEAROFF, (uint8_t *)params, sizeof(tearoff_params_t)); PacketResponseNG resp; - if (WaitForResponseTimeout(CMD_SET_TEAROFF, &resp, 500) == false) { + if (WaitForResponseTimeout(CMD_SET_TEAROFF, &resp, 500) == false) + { PrintAndLogEx(WARNING, "Tear-off command timeout."); return PM3_ETIMEOUT; } - if (resp.status == PM3_SUCCESS) { + if (resp.status == PM3_SUCCESS) + { if (params->delay_us > 0 && verbose) PrintAndLogEx(INFO, "Tear-off hook configured with delay of " _GREEN_("%i us"), params->delay_us); @@ -1418,13 +1463,14 @@ int handle_tearoff(tearoff_params_t *params, bool verbose) { if (params->off && verbose) PrintAndLogEx(INFO, "Tear-off hook " _RED_("disabled")); - } else if (verbose) + } + else if (verbose) PrintAndLogEx(WARNING, "Tear-off command failed."); return resp.status; } - -static int CmdTearoff(const char *Cmd) { +static int CmdTearoff(const char *Cmd) +{ CLIParserContext *ctx; CLIParserInit(&ctx, "hw tearoff", "Configure a tear-off hook for the next write command supporting tear-off\n" @@ -1443,8 +1489,7 @@ static int CmdTearoff(const char *Cmd) { arg_int0(NULL, "skip", "", "Skip N triggers before activating the hook"), arg_lit0("s", "silent", "less verbose output"), arg_lit0(NULL, "list", "List commands implementing tear-off hooks"), - arg_param_end - }; + arg_param_end}; CLIExecWithReturn(ctx, Cmd, argtable, false); tearoff_params_t params; @@ -1456,7 +1501,8 @@ static int CmdTearoff(const char *Cmd) { bool list = arg_get_lit(ctx, 6); CLIParserFree(ctx); - if (list) { + if (list) + { PrintAndLogEx(INFO, "Commands implementing tear-off hooks:"); PrintAndLogEx(INFO, " hf 14a raw"); PrintAndLogEx(INFO, " hf 14b apdu"); @@ -1482,19 +1528,25 @@ static int CmdTearoff(const char *Cmd) { return PM3_SUCCESS; } - if (delay != -1) { - if ((delay < 1) || (delay > 43000)) { + if (delay != -1) + { + if ((delay < 1) || (delay > 43000)) + { PrintAndLogEx(WARNING, "You can't set delay out of 1..43000 range!"); return PM3_EINVARG; } - } else { + } + else + { delay = 0; // will be ignored by ARM } params.delay_us = delay; - if (skip != -1) { - if ((skip < 0) || (skip > 127)) { + if (skip != -1) + { + if ((skip < 0) || (skip > 127)) + { PrintAndLogEx(WARNING, "You can't set skip out of 0..127 range!"); return PM3_EINVARG; } @@ -1502,7 +1554,8 @@ static int CmdTearoff(const char *Cmd) { params.skip = skip; - if (params.on && params.off) { + if (params.on && params.off) + { PrintAndLogEx(WARNING, "You can't set both --on and --off!"); return PM3_EINVARG; } @@ -1510,17 +1563,16 @@ static int CmdTearoff(const char *Cmd) { return handle_tearoff(¶ms, !silent); } -static int CmdTia(const char *Cmd) { +static int CmdTia(const char *Cmd) +{ CLIParserContext *ctx; CLIParserInit(&ctx, "hw tia", "Trigger a Timing Interval Acquisition to re-adjust the RealTimeCounter divider", - "hw tia" - ); + "hw tia"); void *argtable[] = { arg_param_begin, - arg_param_end - }; + arg_param_end}; CLIExecWithReturn(ctx, Cmd, argtable, true); CLIParserFree(ctx); @@ -1528,7 +1580,8 @@ static int CmdTia(const char *Cmd) { clearCommandBuffer(); SendCommandNG(CMD_TIA, NULL, 0); PacketResponseNG resp; - if (WaitForResponseTimeout(CMD_TIA, &resp, 2000) == false) { + if (WaitForResponseTimeout(CMD_TIA, &resp, 2000) == false) + { PrintAndLogEx(WARNING, "TIA command timeout. You probably need to unplug the Proxmark3."); return PM3_ETIMEOUT; } @@ -1536,21 +1589,20 @@ static int CmdTia(const char *Cmd) { return PM3_SUCCESS; } -static int CmdTimeout(const char *Cmd) { +static int CmdTimeout(const char *Cmd) +{ CLIParserContext *ctx; CLIParserInit(&ctx, "hw timeout", "Set the communication timeout on the client side", "hw timeout --> Show current timeout\n" "hw timeout -m 20 --> Set the timeout to 20ms\n" - "hw timeout --ms 500 --> Set the timeout to 500ms\n" - ); + "hw timeout --ms 500 --> Set the timeout to 500ms\n"); void *argtable[] = { arg_param_begin, arg_int0("m", "ms", "", "timeout in micro seconds"), - arg_param_end - }; + arg_param_end}; CLIExecWithReturn(ctx, Cmd, argtable, true); int32_t arg = arg_get_int_def(ctx, 1, -1); CLIParserFree(ctx); @@ -1558,16 +1610,20 @@ static int CmdTimeout(const char *Cmd) { uint32_t oldTimeout = uart_get_timeouts(); // timeout is not given/invalid, just show the current timeout then return - if (arg < 0) { + if (arg < 0) + { PrintAndLogEx(INFO, "Current communication timeout... " _GREEN_("%u") " ms", oldTimeout); return PM3_SUCCESS; } uint32_t newTimeout = arg; // UART_USB_CLIENT_RX_TIMEOUT_MS is considered as the minimum required timeout. - if (newTimeout < UART_USB_CLIENT_RX_TIMEOUT_MS) { + if (newTimeout < UART_USB_CLIENT_RX_TIMEOUT_MS) + { PrintAndLogEx(WARNING, "Timeout less than %u ms might cause errors.", UART_USB_CLIENT_RX_TIMEOUT_MS); - } else if (newTimeout > 5000) { + } + else if (newTimeout > 5000) + { PrintAndLogEx(WARNING, "Timeout greater than 5000 ms makes the client unresponsive."); } uart_reconfigure_timeouts(newTimeout); @@ -1576,19 +1632,18 @@ static int CmdTimeout(const char *Cmd) { return PM3_SUCCESS; } -static int CmdPing(const char *Cmd) { +static int CmdPing(const char *Cmd) +{ CLIParserContext *ctx; CLIParserInit(&ctx, "hw ping", "Test if the Proxmark3 is responsive", "hw ping\n" - "hw ping --len 32" - ); + "hw ping --len 32"); void *argtable[] = { arg_param_begin, arg_u64_0("l", "len", "", "length of payload to send"), - arg_param_end - }; + arg_param_end}; CLIExecWithReturn(ctx, Cmd, argtable, true); uint32_t len = arg_get_u32_def(ctx, 1, 32); @@ -1597,9 +1652,12 @@ static int CmdPing(const char *Cmd) { if (len > PM3_CMD_DATA_SIZE) len = PM3_CMD_DATA_SIZE; - if (len) { + if (len) + { PrintAndLogEx(INFO, "Ping sent with payload len... " _YELLOW_("%d"), len); - } else { + } + else + { PrintAndLogEx(INFO, "Ping sent"); } @@ -1607,44 +1665,47 @@ static int CmdPing(const char *Cmd) { PacketResponseNG resp; uint8_t data[PM3_CMD_DATA_SIZE] = {0}; - for (uint16_t i = 0; i < len; i++) { + for (uint16_t i = 0; i < len; i++) + { data[i] = i & 0xFF; } uint64_t tms = msclock(); SendCommandNG(CMD_PING, data, len); - if (WaitForResponseTimeout(CMD_PING, &resp, 1000)) { + if (WaitForResponseTimeout(CMD_PING, &resp, 1000)) + { tms = msclock() - tms; - if (len) { + if (len) + { bool error = (memcmp(data, resp.data.asBytes, len) != 0); - PrintAndLogEx((error) ? ERR : SUCCESS, "Ping response " _GREEN_("received") - " in " _YELLOW_("%" PRIu64) " ms and content ( %s )", + PrintAndLogEx((error) ? ERR : SUCCESS, "Ping response " _GREEN_("received") " in " _YELLOW_("%" PRIu64) " ms and content ( %s )", tms, error ? _RED_("fail") : _GREEN_("ok")); - } else { - PrintAndLogEx(SUCCESS, "Ping response " _GREEN_("received") - " in " _YELLOW_("%" PRIu64) " ms", tms); } - } else + else + { + PrintAndLogEx(SUCCESS, "Ping response " _GREEN_("received") " in " _YELLOW_("%" PRIu64) " ms", tms); + } + } + else PrintAndLogEx(WARNING, "Ping response " _RED_("timeout")); return PM3_SUCCESS; } -static int CmdConnect(const char *Cmd) { +static int CmdConnect(const char *Cmd) +{ CLIParserContext *ctx; CLIParserInit(&ctx, "hw connect", "Connects to a Proxmark3 device via specified serial port.\n" "Baudrate here is only for physical UART or UART-BT, NOT for USB-CDC or blue shark add-on", - "hw connect -p "SERIAL_PORT_EXAMPLE_H"\n" - "hw connect -p "SERIAL_PORT_EXAMPLE_H" -b 115200" - ); + "hw connect -p " SERIAL_PORT_EXAMPLE_H "\n" + "hw connect -p " SERIAL_PORT_EXAMPLE_H " -b 115200"); void *argtable[] = { arg_param_begin, arg_str0("p", "port", "", "Serial port to connect to, else retry the last used one"), arg_u64_0("b", "baud", "", "Baudrate"), - arg_param_end - }; + arg_param_end}; CLIExecWithReturn(ctx, Cmd, argtable, true); char port[FILE_PATH_SIZE] = {0}; @@ -1653,28 +1714,33 @@ static int CmdConnect(const char *Cmd) { uint32_t baudrate = arg_get_u32_def(ctx, 2, USART_BAUD_RATE); CLIParserFree(ctx); - if (baudrate == 0) { + if (baudrate == 0) + { PrintAndLogEx(WARNING, "Baudrate can't be zero"); return PM3_EINVARG; } // default back to previous used serial port - if (strlen(port) == 0) { - if (strlen(g_conn.serial_port_name) == 0) { + if (strlen(port) == 0) + { + if (strlen(g_conn.serial_port_name) == 0) + { PrintAndLogEx(WARNING, "Must specify a serial port"); return PM3_EINVARG; } memcpy(port, g_conn.serial_port_name, sizeof(port)); } - if (g_session.pm3_present) { + if (g_session.pm3_present) + { CloseProxmark(g_session.current_device); } // 10 second timeout OpenProxmark(&g_session.current_device, port, false, 10, false, baudrate); - if (g_session.pm3_present && (TestProxmark(g_session.current_device) != PM3_SUCCESS)) { + if (g_session.pm3_present && (TestProxmark(g_session.current_device) != PM3_SUCCESS)) + { PrintAndLogEx(ERR, _RED_("ERROR:") " cannot communicate with the Proxmark3\n"); CloseProxmark(g_session.current_device); return PM3_ENOTTY; @@ -1682,18 +1748,17 @@ static int CmdConnect(const char *Cmd) { return PM3_SUCCESS; } -static int CmdBreak(const char *Cmd) { +static int CmdBreak(const char *Cmd) +{ CLIParserContext *ctx; CLIParserInit(&ctx, "hw break", "send break loop package", - "hw break\n" - ); + "hw break\n"); void *argtable[] = { arg_param_begin, - arg_param_end - }; + arg_param_end}; CLIExecWithReturn(ctx, Cmd, argtable, true); CLIParserFree(ctx); clearCommandBuffer(); @@ -1701,18 +1766,17 @@ static int CmdBreak(const char *Cmd) { return PM3_SUCCESS; } -static int CmdBootloader(const char *Cmd) { +static int CmdBootloader(const char *Cmd) +{ CLIParserContext *ctx; CLIParserInit(&ctx, "hw bootloader", "Reboot Proxmark3 into bootloader mode", - "hw bootloader\n" - ); + "hw bootloader\n"); void *argtable[] = { arg_param_begin, - arg_param_end - }; + arg_param_end}; CLIExecWithReturn(ctx, Cmd, argtable, true); CLIParserFree(ctx); clearCommandBuffer(); @@ -1720,131 +1784,139 @@ static int CmdBootloader(const char *Cmd) { return PM3_SUCCESS; } -int set_fpga_mode(uint8_t mode) { - if (mode < FPGA_BITSTREAM_MIN || mode > FPGA_BITSTREAM_MAX) { +int set_fpga_mode(uint8_t mode) +{ + if (mode < FPGA_BITSTREAM_MIN || mode > FPGA_BITSTREAM_MAX) + { return PM3_EINVARG; } uint8_t d[] = {mode}; clearCommandBuffer(); SendCommandNG(CMD_SET_FPGAMODE, d, sizeof(d)); PacketResponseNG resp; - if (WaitForResponseTimeout(CMD_SET_FPGAMODE, &resp, 1000) == false) { + if (WaitForResponseTimeout(CMD_SET_FPGAMODE, &resp, 1000) == false) + { PrintAndLogEx(WARNING, "command execution time out"); return PM3_ETIMEOUT; } - if (resp.status != PM3_SUCCESS) { + if (resp.status != PM3_SUCCESS) + { PrintAndLogEx(ERR, "failed to set FPGA mode"); } return resp.status; } static command_t CommandTable[] = { - {"help", CmdHelp, AlwaysAvailable, "This help"}, - {"-------------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("Operation") " -----------------------"}, - {"detectreader", CmdDetectReader, IfPm3Present, "Detect external reader field"}, - {"status", CmdStatus, IfPm3Present, "Show runtime status information about the connected Proxmark3"}, - {"tearoff", CmdTearoff, IfPm3Present, "Program a tearoff hook for the next command supporting tearoff"}, - {"timeout", CmdTimeout, AlwaysAvailable, "Set the communication timeout on the client side"}, - {"version", CmdVersion, AlwaysAvailable, "Show version information about the client and Proxmark3"}, - {"-------------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("Hardware") " -----------------------"}, - {"break", CmdBreak, IfPm3Present, "Send break loop usb command"}, - {"bootloader", CmdBootloader, IfPm3Present, "Reboot into bootloader mode"}, - {"connect", CmdConnect, AlwaysAvailable, "Connect to the device via serial port"}, - {"dbg", CmdDbg, IfPm3Present, "Set device side debug level"}, - {"fpgaoff", CmdFPGAOff, IfPm3Present, "Turn off FPGA on device"}, - {"lcd", CmdLCD, IfPm3Lcd, "Send command/data to LCD"}, - {"lcdreset", CmdLCDReset, IfPm3Lcd, "Hardware reset LCD"}, - {"ping", CmdPing, IfPm3Present, "Test if the Proxmark3 is responsive"}, - {"readmem", CmdReadmem, IfPm3Present, "Read from MCU flash"}, - {"reset", CmdReset, IfPm3Present, "Reset the device"}, - {"setlfdivisor", CmdSetDivisor, IfPm3Lf, "Drive LF antenna at 12MHz / (divisor + 1)"}, - {"sethfthresh", CmdSetHFThreshold, IfPm3Iso14443a, "Set thresholds in HF/14a mode"}, - {"setmux", CmdSetMux, IfPm3Present, "Set the ADC mux to a specific value"}, - {"standalone", CmdStandalone, IfPm3Present, "Start installed standalone mode on device"}, - {"tia", CmdTia, IfPm3Present, "Trigger a Timing Interval Acquisition to re-adjust the RealTimeCounter divider"}, - {"tune", CmdTune, IfPm3Lf, "Measure tuning of device antenna"}, - {"decay", CmdDecay, IfPm3Present, "Measure HF antenna decay after field-off"}, - {NULL, NULL, NULL, NULL} -}; + {"help", CmdHelp, AlwaysAvailable, "This help"}, + {"-------------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("Operation") " -----------------------"}, + {"detectreader", CmdDetectReader, IfPm3Present, "Detect external reader field"}, + {"status", CmdStatus, IfPm3Present, "Show runtime status information about the connected Proxmark3"}, + {"tearoff", CmdTearoff, IfPm3Present, "Program a tearoff hook for the next command supporting tearoff"}, + {"timeout", CmdTimeout, AlwaysAvailable, "Set the communication timeout on the client side"}, + {"version", CmdVersion, AlwaysAvailable, "Show version information about the client and Proxmark3"}, + {"-------------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("Hardware") " -----------------------"}, + {"break", CmdBreak, IfPm3Present, "Send break loop usb command"}, + {"bootloader", CmdBootloader, IfPm3Present, "Reboot into bootloader mode"}, + {"connect", CmdConnect, AlwaysAvailable, "Connect to the device via serial port"}, + {"dbg", CmdDbg, IfPm3Present, "Set device side debug level"}, + {"fpgaoff", CmdFPGAOff, IfPm3Present, "Turn off FPGA on device"}, + {"lcd", CmdLCD, IfPm3Lcd, "Send command/data to LCD"}, + {"lcdreset", CmdLCDReset, IfPm3Lcd, "Hardware reset LCD"}, + {"ping", CmdPing, IfPm3Present, "Test if the Proxmark3 is responsive"}, + {"readmem", CmdReadmem, IfPm3Present, "Read from MCU flash"}, + {"reset", CmdReset, IfPm3Present, "Reset the device"}, + {"setlfdivisor", CmdSetDivisor, IfPm3Lf, "Drive LF antenna at 12MHz / (divisor + 1)"}, + {"sethfthresh", CmdSetHFThreshold, IfPm3Iso14443a, "Set thresholds in HF/14a mode"}, + {"setmux", CmdSetMux, IfPm3Present, "Set the ADC mux to a specific value"}, + {"standalone", CmdStandalone, IfPm3Present, "Start installed standalone mode on device"}, + {"tia", CmdTia, IfPm3Present, "Trigger a Timing Interval Acquisition to re-adjust the RealTimeCounter divider"}, + {"tune", CmdTune, IfPm3Lf, "Measure tuning of device antenna"}, + {"decay", CmdDecay, IfPm3Present, "Measure HF antenna decay after field-off"}, + {NULL, NULL, NULL, NULL}}; -static int CmdHelp(const char *Cmd) { +static int CmdHelp(const char *Cmd) +{ (void)Cmd; // Cmd is not used so far CmdsHelp(CommandTable); return PM3_SUCCESS; } -int CmdHW(const char *Cmd) { +int CmdHW(const char *Cmd) +{ clearCommandBuffer(); return CmdsParse(CommandTable, Cmd); } - #if defined(__MINGW64__) -# define PM3CLIENTCOMPILER "MinGW-w64 " +#define PM3CLIENTCOMPILER "MinGW-w64 " #elif defined(__MINGW32__) -# define PM3CLIENTCOMPILER "MinGW " +#define PM3CLIENTCOMPILER "MinGW " #elif defined(__clang__) -# define PM3CLIENTCOMPILER "Clang/LLVM " +#define PM3CLIENTCOMPILER "Clang/LLVM " #elif defined(__GNUC__) || defined(__GNUG__) -# define PM3CLIENTCOMPILER "GCC " +#define PM3CLIENTCOMPILER "GCC " #else -# define PM3CLIENTCOMPILER "unknown compiler " +#define PM3CLIENTCOMPILER "unknown compiler " #endif #if defined(__APPLE__) || defined(__MACH__) -# define PM3HOSTOS "OSX" +#define PM3HOSTOS "OSX" #elif defined(__ANDROID__) || defined(ANDROID) // must be tested before __linux__ -# define PM3HOSTOS "Android" +#define PM3HOSTOS "Android" #elif defined(__linux__) -# define PM3HOSTOS "Linux" +#define PM3HOSTOS "Linux" #elif defined(__FreeBSD__) -# define PM3HOSTOS "FreeBSD" +#define PM3HOSTOS "FreeBSD" #elif defined(__NetBSD__) -# define PM3HOSTOS "NetBSD" +#define PM3HOSTOS "NetBSD" #elif defined(__OpenBSD__) -# define PM3HOSTOS "OpenBSD" +#define PM3HOSTOS "OpenBSD" #elif defined(__CYGWIN__) -# define PM3HOSTOS "Cygwin" +#define PM3HOSTOS "Cygwin" #elif defined(_WIN64) || defined(__WIN64__) // must be tested before _WIN32 -# define PM3HOSTOS "Windows (64b)" +#define PM3HOSTOS "Windows (64b)" #elif defined(_WIN32) || defined(__WIN32__) -# define PM3HOSTOS "Windows (32b)" +#define PM3HOSTOS "Windows (32b)" #else -# define PM3HOSTOS "unknown" +#define PM3HOSTOS "unknown" #endif #if defined(__x86_64__) -# define PM3HOSTARCH "x86_64" +#define PM3HOSTARCH "x86_64" #elif defined(__i386__) -# define PM3HOSTARCH "x86" +#define PM3HOSTARCH "x86" #elif defined(__aarch64__) -# define PM3HOSTARCH "aarch64" +#define PM3HOSTARCH "aarch64" #elif defined(__arm__) -# define PM3HOSTARCH "arm" +#define PM3HOSTARCH "arm" #elif defined(__powerpc64__) -# define PM3HOSTARCH "powerpc64" +#define PM3HOSTARCH "powerpc64" #elif defined(__mips__) -# define PM3HOSTARCH "mips" +#define PM3HOSTARCH "mips" #else -# define PM3HOSTARCH "unknown" +#define PM3HOSTARCH "unknown" #endif -void pm3_version_short(void) { -// PrintAndLogEx(NORMAL, " [ " _CYAN_("Proxmark3 RFID instrument") " ]"); +void pm3_version_short(void) +{ + // PrintAndLogEx(NORMAL, " [ " _CYAN_("Proxmark3 RFID instrument") " ]"); PrintAndLogEx(NORMAL, " [ " _CYAN_("Proxmark3") " ]"); PrintAndLogEx(NORMAL, ""); - if (g_session.pm3_present) { + if (g_session.pm3_present) + { PacketResponseNG resp; clearCommandBuffer(); SendCommandNG(CMD_VERSION, NULL, 0); - if (WaitForResponseTimeout(CMD_VERSION, &resp, 1000)) { + if (WaitForResponseTimeout(CMD_VERSION, &resp, 1000)) + { - struct p { + struct p + { uint32_t id; uint32_t section_size; uint32_t versionstr_len; @@ -1855,28 +1927,35 @@ void pm3_version_short(void) { lookup_chipid_short(payload->id, payload->section_size); - if (IfPm3Rdv4Fw()) { - + if (IfPm3Rdv4Fw()) + { // validate signature data rdv40_validation_t mem; signature_e type; - if (pm3_get_signature(&mem) == PM3_SUCCESS) { - if (pm3_validate(&mem, &type) == PM3_SUCCESS) { + if (pm3_get_signature(&mem) == PM3_SUCCESS) + { + if (pm3_validate(&mem, &type) == PM3_SUCCESS) + { - if (type == SIGN_RDV4) { + if (type == SIGN_RDV4) + { PrintAndLogEx(NORMAL, " Target.... %s", _YELLOW_("RDV4")); - } else if (type == SIGN_GENERIC) { + } + else if (type == SIGN_GENERIC) + { PrintAndLogEx(NORMAL, " Target.... %s", _YELLOW_("GENERIC")); - } else { + } + else + { PrintAndLogEx(NORMAL, " Target.... %s", _RED_("device / fw mismatch")); } } } - - - } else { + } + else + { PrintAndLogEx(NORMAL, " Target.... %s", _YELLOW_("PM3 GENERIC")); } PrintAndLogEx(NORMAL, ""); @@ -1888,10 +1967,13 @@ void pm3_version_short(void) { bool armsrc_mismatch = false; char *ptr = strstr(payload->versionstr, "OS......... "); - if (ptr != NULL) { + if (ptr != NULL) + { ptr = strstr(ptr, "\n"); - if ((ptr != NULL) && (strlen(g_version_information.armsrc) == 9)) { - if (strncmp(ptr - 9, g_version_information.armsrc, 9) != 0) { + if ((ptr != NULL) && (strlen(g_version_information.armsrc) == 9)) + { + if (strncmp(ptr - 9, g_version_information.armsrc, 9) != 0) + { armsrc_mismatch = true; } } @@ -1899,9 +1981,11 @@ void pm3_version_short(void) { // bootrom ptr = strstr(payload->versionstr, "Bootrom.... "); - if (ptr != NULL) { + if (ptr != NULL) + { char *ptr_end = strstr(ptr, "\n"); - if (ptr_end != NULL) { + if (ptr_end != NULL) + { uint8_t len = ptr_end - 12 - ptr; PrintAndLogEx(NORMAL, " Bootrom... %.*s", len, ptr + 12); } @@ -1909,16 +1993,19 @@ void pm3_version_short(void) { // os: ptr = strstr(payload->versionstr, "OS......... "); - if (ptr != NULL) { + if (ptr != NULL) + { char *ptr_end = strstr(ptr, "\n"); - if (ptr_end != NULL) { + if (ptr_end != NULL) + { uint8_t len = ptr_end - 12 - ptr; PrintAndLogEx(NORMAL, " OS........ %.*s", len, ptr + 12); } } PrintAndLogEx(NORMAL, ""); - if (armsrc_mismatch) { + if (armsrc_mismatch) + { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(WARNING, " --> " _RED_("ARM firmware does not match the source at the time the client was compiled")); PrintAndLogEx(WARNING, " --> Make sure to flash a correct and up-to-date version"); @@ -1928,18 +2015,21 @@ void pm3_version_short(void) { PrintAndLogEx(NORMAL, ""); } -void pm3_version(bool verbose, bool oneliner) { +void pm3_version(bool verbose, bool oneliner) +{ char temp[PM3_CMD_DATA_SIZE - 12]; // same limit as for ARM image - if (oneliner) { + if (oneliner) + { // For "proxmark3 -v", simple printf, avoid logging FormatVersionInformation(temp, sizeof(temp), "Client: ", &g_version_information); PrintAndLogEx(NORMAL, "%s compiler: " PM3CLIENTCOMPILER __VERSION__ " OS:" PM3HOSTOS " ARCH:" PM3HOSTARCH "\n", temp); return; } - if (!verbose) { + if (!verbose) + { return; } @@ -1987,30 +2077,40 @@ void pm3_version(bool verbose, bool oneliner) { PrintAndLogEx(NORMAL, " Lua SWIG support.......... " _YELLOW_("absent")); #endif - if (g_session.pm3_present) { + if (g_session.pm3_present) + { PrintAndLogEx(NORMAL, "\n [ " _YELLOW_("Model") " ]"); PacketResponseNG resp; clearCommandBuffer(); SendCommandNG(CMD_VERSION, NULL, 0); - if (WaitForResponseTimeout(CMD_VERSION, &resp, 1000)) { - if (IfPm3Rdv4Fw()) { + if (WaitForResponseTimeout(CMD_VERSION, &resp, 1000)) + { + if (IfPm3Rdv4Fw()) + { // validate signature data rdv40_validation_t mem; signature_e type; - if (pm3_get_signature(&mem) == PM3_SUCCESS) { - if (pm3_validate(&mem, &type) == PM3_SUCCESS) { + if (pm3_get_signature(&mem) == PM3_SUCCESS) + { + if (pm3_validate(&mem, &type) == PM3_SUCCESS) + { - if (type == SIGN_RDV4) { + if (type == SIGN_RDV4) + { PrintAndLogEx(NORMAL, " Device.................... " _GREEN_("RDV4")); PrintAndLogEx(NORMAL, " Firmware.................. " _GREEN_("RDV4")); - } else if (type == SIGN_GENERIC) { + } + else if (type == SIGN_GENERIC) + { PrintAndLogEx(NORMAL, " Device.................... ", _GREEN_("GENERIC")); PrintAndLogEx(NORMAL, " Firmware.................. ", _GREEN_("GENERIC")); - } else { + } + else + { PrintAndLogEx(NORMAL, " Device.................... " _RED_("Bad signature detected!")); PrintAndLogEx(NORMAL, " Firmware.................. " _YELLOW_("N/A")); } @@ -2020,24 +2120,30 @@ void pm3_version(bool verbose, bool oneliner) { PrintAndLogEx(NORMAL, " External flash............ %s", IfPm3Flash() ? _GREEN_("present") : _YELLOW_("absent")); PrintAndLogEx(NORMAL, " Smartcard reader.......... %s", IfPm3Smartcard() ? _GREEN_("present") : _YELLOW_("absent")); PrintAndLogEx(NORMAL, " FPC USART for BT add-on... %s", IfPm3FpcUsartHost() ? _GREEN_("present") : _YELLOW_("absent")); - } else { + } + else + { PrintAndLogEx(NORMAL, " Firmware.................. %s", _YELLOW_("PM3 GENERIC")); - if (IfPm3Flash()) { + if (IfPm3Flash()) + { PrintAndLogEx(NORMAL, " External flash............ %s", _GREEN_("present")); } - if (IfPm3FpcUsartHost()) { + if (IfPm3FpcUsartHost()) + { PrintAndLogEx(NORMAL, " FPC USART for BT add-on... %s", _GREEN_("present")); } } - if (IfPm3FpcUsartDevFromUsb()) { + if (IfPm3FpcUsartDevFromUsb()) + { PrintAndLogEx(NORMAL, " FPC USART for developer... %s", _GREEN_("present")); } PrintAndLogEx(NORMAL, ""); - struct p { + struct p + { uint32_t id; uint32_t section_size; uint32_t versionstr_len; @@ -2048,24 +2154,29 @@ void pm3_version(bool verbose, bool oneliner) { bool armsrc_mismatch = false; char *ptr = strstr(payload->versionstr, "OS......... "); - if (ptr != NULL) { + if (ptr != NULL) + { ptr = strstr(ptr, "\n"); - if ((ptr != NULL) && (strlen(g_version_information.armsrc) == 9)) { - if (strncmp(ptr - 9, g_version_information.armsrc, 9) != 0) { + if ((ptr != NULL) && (strlen(g_version_information.armsrc) == 9)) + { + if (strncmp(ptr - 9, g_version_information.armsrc, 9) != 0) + { armsrc_mismatch = true; } } } - PrintAndLogEx(NORMAL, payload->versionstr); - if (strstr(payload->versionstr, FPGA_TYPE) == NULL) { + PrintAndLogEx(NORMAL, payload->versionstr); + if (strstr(payload->versionstr, FPGA_TYPE) == NULL) + { PrintAndLogEx(NORMAL, " FPGA firmware... %s", _RED_("chip mismatch")); } lookupChipID(payload->id, payload->section_size); - if (armsrc_mismatch) { + if (armsrc_mismatch) + { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(WARNING, _RED_("ARM firmware does not match the source at the time the client was compiled")); - PrintAndLogEx(WARNING, "Make sure to flash a correct and up-to-date version"); + PrintAndLogEx(WARNING, "Make sure to flash a correct and up-to-date version"); } } } diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index 3d6f7a6a9..c4624cff4 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -26,102 +26,117 @@ #define USART_SLOW_LINK #define PM3_CMD_DATA_SIZE 512 -#define PM3_CMD_DATA_SIZE_MIX ( PM3_CMD_DATA_SIZE - 3 * sizeof(uint64_t) ) +#define PM3_CMD_DATA_SIZE_MIX (PM3_CMD_DATA_SIZE - 3 * sizeof(uint64_t)) -typedef struct { +typedef struct +{ uint64_t cmd; uint64_t arg[3]; - union { - uint8_t asBytes[PM3_CMD_DATA_SIZE]; + union + { + uint8_t asBytes[PM3_CMD_DATA_SIZE]; uint32_t asDwords[PM3_CMD_DATA_SIZE / 4]; } d; } PACKED PacketCommandOLD; -typedef struct { +typedef struct +{ uint32_t magic; - uint16_t length : 15; // length of the variable part, 0 if none. + uint16_t length : 15; // length of the variable part, 0 if none. bool ng : 1; uint16_t cmd; } PACKED PacketCommandNGPreamble; -#define COMMANDNG_PREAMBLE_MAGIC 0x61334d50 // PM3a -#define COMMANDNG_POSTAMBLE_MAGIC 0x3361 // a3 +#define COMMANDNG_PREAMBLE_MAGIC 0x61334d50 // PM3a +#define COMMANDNG_POSTAMBLE_MAGIC 0x3361 // a3 -typedef struct { +typedef struct +{ uint16_t crc; } PACKED PacketCommandNGPostamble; // For internal usage -typedef struct { +typedef struct +{ uint16_t cmd; uint16_t length; - uint32_t magic; // NG - uint16_t crc; // NG - uint64_t oldarg[3]; // OLD - union { - uint8_t asBytes[PM3_CMD_DATA_SIZE]; + uint32_t magic; // NG + uint16_t crc; // NG + uint64_t oldarg[3]; // OLD + union + { + uint8_t asBytes[PM3_CMD_DATA_SIZE]; uint32_t asDwords[PM3_CMD_DATA_SIZE / 4]; } data; - bool ng; // does it store NG data or OLD data? + bool ng; // does it store NG data or OLD data? } PacketCommandNG; // For reception and CRC check -typedef struct { +typedef struct +{ PacketCommandNGPreamble pre; uint8_t data[PM3_CMD_DATA_SIZE]; PacketCommandNGPostamble foopost; // Probably not at that offset! } PACKED PacketCommandNGRaw; -typedef struct { +typedef struct +{ uint64_t cmd; uint64_t arg[3]; - union { - uint8_t asBytes[PM3_CMD_DATA_SIZE]; + union + { + uint8_t asBytes[PM3_CMD_DATA_SIZE]; uint32_t asDwords[PM3_CMD_DATA_SIZE / 4]; } d; } PACKED PacketResponseOLD; -typedef struct { +typedef struct +{ uint32_t magic; - uint16_t length : 15; // length of the variable part, 0 if none. - bool ng : 1; - int8_t status; - int8_t reason; + uint16_t length : 15; // length of the variable part, 0 if none. + bool ng : 1; + int8_t status; + int8_t reason; uint16_t cmd; } PACKED PacketResponseNGPreamble; -#define RESPONSENG_PREAMBLE_MAGIC 0x62334d50 // PM3b -#define RESPONSENG_POSTAMBLE_MAGIC 0x3362 // b3 +#define RESPONSENG_PREAMBLE_MAGIC 0x62334d50 // PM3b +#define RESPONSENG_POSTAMBLE_MAGIC 0x3362 // b3 -typedef struct { +typedef struct +{ uint16_t crc; } PACKED PacketResponseNGPostamble; // For internal usage -typedef struct { +typedef struct +{ uint16_t cmd; uint16_t length; - uint32_t magic; // NG - int8_t status; // NG - int8_t reason; // NG - uint16_t crc; // NG - uint64_t oldarg[3]; // OLD - union { - uint8_t asBytes[PM3_CMD_DATA_SIZE]; + uint32_t magic; // NG + int8_t status; // NG + int8_t reason; // NG + uint16_t crc; // NG + uint64_t oldarg[3]; // OLD + union + { + uint8_t asBytes[PM3_CMD_DATA_SIZE]; uint32_t asDwords[PM3_CMD_DATA_SIZE / 4]; } data; - bool ng; // does it store NG data or OLD data? + bool ng; // does it store NG data or OLD data? } PacketResponseNG; // For reception and CRC check -typedef struct { +typedef struct +{ PacketResponseNGPreamble pre; uint8_t data[PM3_CMD_DATA_SIZE]; PacketResponseNGPostamble foopost; // Probably not at that offset! } PACKED PacketResponseNGRaw; // A struct used to send sample-configs over USB -typedef struct { +typedef struct +{ int8_t decimation; int8_t bits_per_sample; int8_t averaging; @@ -131,10 +146,10 @@ typedef struct { bool verbose; } PACKED sample_config; - // Defines a frame that will be used in a polling sequence // Polling loop annotations are up to 20 bytes long, 24 bytes should cover future and other cases -typedef struct { +typedef struct +{ uint8_t frame[24]; // negative values can be used to carry special info int8_t frame_length; @@ -142,30 +157,31 @@ typedef struct { uint16_t extra_delay; } PACKED iso14a_polling_frame_t; - // Defines polling sequence configuration -typedef struct { +typedef struct +{ // 6 would be enough for 4 magsafe, 1 wupa, 1 pla, iso14a_polling_frame_t frames[6]; int8_t frame_count; uint16_t extra_timeout; } PACKED iso14a_polling_parameters_t; - // A struct used to send hf14a-configs over USB -typedef struct { - int8_t forceanticol; // 0:auto 1:force executing anticol 2:force skipping anticol - int8_t forcebcc; // 0:expect valid BCC 1:force using computed BCC 2:force using card BCC - int8_t forcecl2; // 0:auto 1:force executing CL2 2:force skipping CL2 - int8_t forcecl3; // 0:auto 1:force executing CL3 2:force skipping CL3 - int8_t forcerats; // 0:auto 1:force executing RATS 2:force skipping RATS - int8_t magsafe; // 0:disabled 1:enabled +typedef struct +{ + int8_t forceanticol; // 0:auto 1:force executing anticol 2:force skipping anticol + int8_t forcebcc; // 0:expect valid BCC 1:force using computed BCC 2:force using card BCC + int8_t forcecl2; // 0:auto 1:force executing CL2 2:force skipping CL2 + int8_t forcecl3; // 0:auto 1:force executing CL3 2:force skipping CL3 + int8_t forcerats; // 0:auto 1:force executing RATS 2:force skipping RATS + int8_t magsafe; // 0:disabled 1:enabled iso14a_polling_frame_t polling_loop_annotation; // Polling loop annotation } PACKED hf14a_config_t; // Defines a frame that will be used in ISO14443B polling sequence // Polling loop annotations are up to 20 bytes long, 24 bytes should cover future and other cases -typedef struct { +typedef struct +{ uint8_t frame[24]; // negative values can be used to carry special info int8_t frame_length; @@ -174,12 +190,14 @@ typedef struct { } PACKED iso14b_polling_frame_t; // A struct used to send hf14b-configs over USB -typedef struct { +typedef struct +{ iso14b_polling_frame_t polling_loop_annotation; // Polling loop annotation } PACKED hf14b_config_t; // Tracelog Header struct -typedef struct { +typedef struct +{ uint32_t timestamp; uint16_t duration; uint16_t data_len : 15; @@ -189,11 +207,12 @@ typedef struct { // ceil(data_len/8) bytes of parity } PACKED tracelog_hdr_t; -#define TRACELOG_HDR_LEN sizeof(tracelog_hdr_t) -#define TRACELOG_PARITY_LEN(x) (((x)->data_len - 1) / 8 + 1) +#define TRACELOG_HDR_LEN sizeof(tracelog_hdr_t) +#define TRACELOG_PARITY_LEN(x) (((x)->data_len - 1) / 8 + 1) // T55XX - Extended to support 1 of 4 timing -typedef struct { +typedef struct +{ uint16_t start_gap; uint16_t write_gap; uint16_t write_0; @@ -205,68 +224,72 @@ typedef struct { // T55XX - This setup will allow for the 4 downlink modes "m" as well as other items if needed. // Given the one struct we can then read/write to flash/client in one go. -typedef struct { +typedef struct +{ t55xx_config_t m[4]; // mode } t55xx_configurations_t; - // Capabilities struct to keep track of what functions was compiled in the device firmware -typedef struct { +typedef struct +{ uint8_t version; uint32_t baudrate; uint32_t bigbuf_size; - bool via_fpc : 1; - bool via_usb : 1; + bool via_fpc : 1; + bool via_usb : 1; // rdv4 - bool compiled_with_flash : 1; - bool compiled_with_smartcard : 1; - bool compiled_with_fpc_usart : 1; - bool compiled_with_fpc_usart_dev : 1; - bool compiled_with_fpc_usart_host : 1; + bool compiled_with_flash : 1; + bool compiled_with_smartcard : 1; + bool compiled_with_fpc_usart : 1; + bool compiled_with_fpc_usart_dev : 1; + bool compiled_with_fpc_usart_host : 1; // lf - bool compiled_with_lf : 1; - bool compiled_with_hitag : 1; - bool compiled_with_em4x50 : 1; - bool compiled_with_em4x70 : 1; - bool compiled_with_zx8211 : 1; + bool compiled_with_lf : 1; + bool compiled_with_hitag : 1; + bool compiled_with_em4x50 : 1; + bool compiled_with_em4x70 : 1; + bool compiled_with_zx8211 : 1; // hf - bool compiled_with_hfsniff : 1; - bool compiled_with_hfplot : 1; - bool compiled_with_iso14443a : 1; - bool compiled_with_iso14443b : 1; - bool compiled_with_iso15693 : 1; - bool compiled_with_felica : 1; - bool compiled_with_legicrf : 1; - bool compiled_with_iclass : 1; - bool compiled_with_seos : 1; - bool compiled_with_nfcbarcode : 1; + bool compiled_with_hfsniff : 1; + bool compiled_with_hfplot : 1; + bool compiled_with_iso14443a : 1; + bool compiled_with_iso14443b : 1; + bool compiled_with_iso15693 : 1; + bool compiled_with_felica : 1; + bool compiled_with_legicrf : 1; + bool compiled_with_iclass : 1; + bool compiled_with_seos : 1; + bool compiled_with_nfcbarcode : 1; // misc - bool compiled_with_lcd : 1; + bool compiled_with_lcd : 1; // rdv4 - bool hw_available_flash : 1; - bool hw_available_smartcard : 1; - bool is_rdv4 : 1; + bool hw_available_flash : 1; + bool hw_available_smartcard : 1; + bool is_rdv4 : 1; } PACKED capabilities_t; #define CAPABILITIES_VERSION 7 extern capabilities_t g_pm3_capabilities; // For CMD_LF_T55XX_WRITEBL -typedef struct { +typedef struct +{ uint32_t data; uint32_t pwd; uint8_t blockno; uint8_t flags; } PACKED t55xx_write_block_t; -typedef struct { +typedef struct +{ uint8_t data[128]; uint8_t bitlen; uint32_t time; } PACKED t55xx_test_block_t; // For CMD_LF_HID_SIMULATE (FSK) -typedef struct { +typedef struct +{ uint32_t hi2; uint32_t hi; uint32_t lo; @@ -276,7 +299,8 @@ typedef struct { } PACKED lf_hidsim_t; // For CMD_LF_FSK_SIMULATE (FSK) -typedef struct { +typedef struct +{ uint8_t fchigh; uint8_t fclow; uint8_t separator; @@ -285,7 +309,8 @@ typedef struct { } PACKED lf_fsksim_t; // For CMD_LF_ASK_SIMULATE (ASK) -typedef struct { +typedef struct +{ uint8_t encoding; uint8_t invert; uint8_t separator; @@ -294,7 +319,8 @@ typedef struct { } PACKED lf_asksim_t; // For CMD_LF_PSK_SIMULATE (PSK) -typedef struct { +typedef struct +{ uint8_t carrier; uint8_t invert; uint8_t clock; @@ -302,14 +328,16 @@ typedef struct { } PACKED lf_psksim_t; // For CMD_LF_NRZ_SIMULATE (NRZ) -typedef struct { +typedef struct +{ uint8_t invert; uint8_t separator; uint8_t clock; uint8_t data[]; } PACKED lf_nrzsim_t; -typedef struct { +typedef struct +{ uint8_t type; uint16_t len; uint8_t data[]; @@ -319,30 +347,33 @@ typedef struct { #define LF_SAMPLES_BITS 30 #define MAX_LF_SAMPLES ((((uint32_t)1u) << LF_SAMPLES_BITS) - 1) -typedef struct { +typedef struct +{ // 64KB SRAM -> 524288 bits(max sample num) < 2^30 - uint32_t samples : - LF_SAMPLES_BITS; - bool realtime : 1; - bool verbose : 1; + uint32_t samples : LF_SAMPLES_BITS; + bool realtime : 1; + bool verbose : 1; } PACKED lf_sample_payload_t; -typedef struct { +typedef struct +{ uint8_t blockno; uint8_t keytype; uint8_t key[6]; } PACKED mf_readblock_t; -typedef enum { +typedef enum +{ MF_WAKE_NONE, - MF_WAKE_WUPA, // 52(7) + anticoll - MF_WAKE_REQA, // 26(7) + anticoll - MF_WAKE_GEN1A, // 40(7)/43 - MF_WAKE_GEN1B, // 40(7) + MF_WAKE_WUPA, // 52(7) + anticoll + MF_WAKE_REQA, // 26(7) + anticoll + MF_WAKE_GEN1A, // 40(7)/43 + MF_WAKE_GEN1B, // 40(7) MF_WAKE_GDM_ALT, // 20(7)/23 } PACKED MifareWakeupType; -typedef struct { +typedef struct +{ MifareWakeupType wakeup; uint8_t auth_cmd; uint8_t key[6]; @@ -350,7 +381,8 @@ typedef struct { uint8_t block_no; } PACKED mf_readblock_ex_t; -typedef struct { +typedef struct +{ MifareWakeupType wakeup; uint8_t auth_cmd; uint8_t key[6]; @@ -359,13 +391,15 @@ typedef struct { uint8_t block_data[16]; } PACKED mf_writeblock_ex_t; -typedef struct { +typedef struct +{ uint8_t sectorcnt; uint8_t keytype; uint8_t key[6]; } PACKED mfc_eload_t; -typedef struct { +typedef struct +{ uint8_t turn_off_field : 1; uint8_t check_answer : 1; uint8_t keyno : 2; @@ -375,11 +409,13 @@ typedef struct { uint8_t key[16]; } PACKED mful_3passauth_t; -enum { +enum +{ MIFAREU3P_KEY_SIZE = 16, MIFAREU3P_CHKKEY_HEADER = 2 + MIFAREU3P_KEY_SIZE }; -typedef struct { +typedef struct +{ uint8_t key_index : 2; uint8_t firstchunk : 1; uint8_t lastchunk : 1; @@ -391,7 +427,8 @@ typedef struct { uint8_t data[PM3_CMD_DATA_SIZE - MIFAREU3P_CHKKEY_HEADER]; } PACKED mful_3passchk_t; -typedef struct { +typedef struct +{ bool use_schann; uint8_t block_no; uint8_t num_of_blocks; @@ -400,12 +437,14 @@ typedef struct { uint8_t key[16]; } PACKED mful_readblock_t; -typedef struct { +typedef struct +{ uint16_t bytelen; uint16_t startidx; } PACKED mful_readblock_resp_t; -typedef struct { +typedef struct +{ bool use_schann; uint8_t block_no; uint8_t keytype; @@ -414,7 +453,8 @@ typedef struct { uint8_t data[16]; } PACKED mful_writeblock_t; -typedef struct { +typedef struct +{ bool has_auth_key; bool use_schann; uint8_t auth_key[16]; @@ -423,7 +463,8 @@ typedef struct { uint8_t key[16]; } PACKED mful_setkey_t; -typedef struct { +typedef struct +{ uint8_t status; uint8_t CSN[8]; uint8_t CONFIG[8]; @@ -431,13 +472,14 @@ typedef struct { uint8_t AIA[8]; } PACKED iclass_reader_t; -typedef struct { +typedef struct +{ const char *desc; const char *value; } PACKED ecdsa_publickey_t; - -typedef struct { +typedef struct +{ uint16_t delay_us; int8_t skip; bool on; @@ -445,7 +487,8 @@ typedef struct { } PACKED tearoff_params_t; // when writing to SPIFFS -typedef struct { +typedef struct +{ bool append : 1; uint16_t bytes_in_packet : 15; uint8_t fnlen; @@ -454,22 +497,24 @@ typedef struct { } PACKED flashmem_write_t; // when CMD_FLASHMEM_WRITE old flashmem commands -typedef struct { +typedef struct +{ uint32_t startidx; uint16_t len; uint8_t data[PM3_CMD_DATA_SIZE - sizeof(uint32_t) - sizeof(uint16_t)]; } PACKED flashmem_old_write_t; - //----------------------------------------------------------------------------- // ISO 7618 Smart Card //----------------------------------------------------------------------------- -typedef struct { +typedef struct +{ uint8_t atr_len; uint8_t atr[50]; } PACKED smart_card_atr_t; -typedef enum SMARTCARD_COMMAND { +typedef enum SMARTCARD_COMMAND +{ SC_CONNECT = (1 << 0), SC_NO_DISCONNECT = (1 << 1), SC_RAW = (1 << 2), @@ -480,592 +525,578 @@ typedef enum SMARTCARD_COMMAND { SC_WAIT = (1 << 7), } smartcard_command_t; -typedef struct { +typedef struct +{ uint8_t flags; uint32_t wait_delay; uint16_t len; uint8_t data[]; } PACKED smart_card_raw_t; - // For the bootloader -#define CMD_DEVICE_INFO 0x0000 -//#define CMD_SETUP_WRITE 0x0001 -#define CMD_FINISH_WRITE 0x0003 -#define CMD_HARDWARE_RESET 0x0004 -#define CMD_START_FLASH 0x0005 -#define CMD_CHIP_INFO 0x0006 -#define CMD_BL_VERSION 0x0007 -#define CMD_NACK 0x00fe -#define CMD_ACK 0x00ff +#define CMD_DEVICE_INFO 0x0000 +// #define CMD_SETUP_WRITE 0x0001 +#define CMD_FINISH_WRITE 0x0003 +#define CMD_HARDWARE_RESET 0x0004 +#define CMD_START_FLASH 0x0005 +#define CMD_CHIP_INFO 0x0006 +#define CMD_BL_VERSION 0x0007 +#define CMD_NACK 0x00fe +#define CMD_ACK 0x00ff // For general mucking around -#define CMD_DEBUG_PRINT_STRING 0x0100 -#define CMD_DEBUG_PRINT_INTEGERS 0x0101 -#define CMD_DEBUG_PRINT_BYTES 0x0102 -#define CMD_LCD_RESET 0x0103 -#define CMD_LCD 0x0104 -#define CMD_BUFF_CLEAR 0x0105 -#define CMD_READ_MEM 0x0106 // legacy -#define CMD_READ_MEM_DOWNLOAD 0x010A -#define CMD_READ_MEM_DOWNLOADED 0x010B -#define CMD_VERSION 0x0107 -#define CMD_STATUS 0x0108 -#define CMD_PING 0x0109 -#define CMD_DOWNLOAD_EML_BIGBUF 0x0110 -#define CMD_DOWNLOADED_EML_BIGBUF 0x0111 -#define CMD_CAPABILITIES 0x0112 -#define CMD_QUIT_SESSION 0x0113 -#define CMD_SET_DBGMODE 0x0114 -#define CMD_STANDALONE 0x0115 -#define CMD_WTX 0x0116 -#define CMD_TIA 0x0117 -#define CMD_BREAK_LOOP 0x0118 -#define CMD_SET_TEAROFF 0x0119 -#define CMD_GET_DBGMODE 0x0120 +#define CMD_DEBUG_PRINT_STRING 0x0100 +#define CMD_DEBUG_PRINT_INTEGERS 0x0101 +#define CMD_DEBUG_PRINT_BYTES 0x0102 +#define CMD_LCD_RESET 0x0103 +#define CMD_LCD 0x0104 +#define CMD_BUFF_CLEAR 0x0105 +#define CMD_READ_MEM 0x0106 // legacy +#define CMD_READ_MEM_DOWNLOAD 0x010A +#define CMD_READ_MEM_DOWNLOADED 0x010B +#define CMD_VERSION 0x0107 +#define CMD_STATUS 0x0108 +#define CMD_PING 0x0109 +#define CMD_DOWNLOAD_EML_BIGBUF 0x0110 +#define CMD_DOWNLOADED_EML_BIGBUF 0x0111 +#define CMD_CAPABILITIES 0x0112 +#define CMD_QUIT_SESSION 0x0113 +#define CMD_SET_DBGMODE 0x0114 +#define CMD_STANDALONE 0x0115 +#define CMD_WTX 0x0116 +#define CMD_TIA 0x0117 +#define CMD_BREAK_LOOP 0x0118 +#define CMD_SET_TEAROFF 0x0119 +#define CMD_GET_DBGMODE 0x0120 // RDV40, Flash memory operations -#define CMD_FLASHMEM_WRITE 0x0121 -#define CMD_FLASHMEM_WIPE 0x0122 -#define CMD_FLASHMEM_DOWNLOAD 0x0123 -#define CMD_FLASHMEM_DOWNLOADED 0x0124 -#define CMD_FLASHMEM_INFO 0x0125 -#define CMD_FLASHMEM_SET_SPIBAUDRATE 0x0126 -#define CMD_FLASHMEM_PAGES64K 0x0127 +#define CMD_FLASHMEM_WRITE 0x0121 +#define CMD_FLASHMEM_WIPE 0x0122 +#define CMD_FLASHMEM_DOWNLOAD 0x0123 +#define CMD_FLASHMEM_DOWNLOADED 0x0124 +#define CMD_FLASHMEM_INFO 0x0125 +#define CMD_FLASHMEM_SET_SPIBAUDRATE 0x0126 +#define CMD_FLASHMEM_PAGES64K 0x0127 // RDV40, High level flashmem SPIFFS Manipulation // ALL function will have a lazy or Safe version // that will be handled as argument of safety level [0..2] respectiveley normal / lazy / safe // However as how design is, MOUNT and UNMOUNT only need/have lazy as safest level so a safe level will still execute a lazy version // see spiffs.c for more about the normal/lazy/safety information) -#define CMD_SPIFFS_MOUNT 0x0130 -#define CMD_SPIFFS_UNMOUNT 0x0131 -#define CMD_SPIFFS_WRITE 0x0132 +#define CMD_SPIFFS_MOUNT 0x0130 +#define CMD_SPIFFS_UNMOUNT 0x0131 +#define CMD_SPIFFS_WRITE 0x0132 -#define CMD_FLASHMEM_GET_SIGNATURE 0x0147 -#define CMD_FLASHMEM_GET_INFO 0x0148 +#define CMD_FLASHMEM_GET_SIGNATURE 0x0147 +#define CMD_FLASHMEM_GET_INFO 0x0148 // We take +0x1000 when having a variant of similar function (todo : make it an argument!) -#define CMD_SPIFFS_APPEND 0x1132 +#define CMD_SPIFFS_APPEND 0x1132 -#define CMD_SPIFFS_READ 0x0133 -//We use no open/close instruction, as they are handled internally. -#define CMD_SPIFFS_REMOVE 0x0134 -#define CMD_SPIFFS_RM CMD_SPIFFS_REMOVE -#define CMD_SPIFFS_RENAME 0x0135 -#define CMD_SPIFFS_MV CMD_SPIFFS_RENAME -#define CMD_SPIFFS_COPY 0x0136 -#define CMD_SPIFFS_CP CMD_SPIFFS_COPY -#define CMD_SPIFFS_STAT 0x0137 -#define CMD_SPIFFS_FSTAT 0x0138 -#define CMD_SPIFFS_INFO 0x0139 -#define CMD_SPIFFS_FORMAT CMD_FLASHMEM_WIPE +#define CMD_SPIFFS_READ 0x0133 +// We use no open/close instruction, as they are handled internally. +#define CMD_SPIFFS_REMOVE 0x0134 +#define CMD_SPIFFS_RM CMD_SPIFFS_REMOVE +#define CMD_SPIFFS_RENAME 0x0135 +#define CMD_SPIFFS_MV CMD_SPIFFS_RENAME +#define CMD_SPIFFS_COPY 0x0136 +#define CMD_SPIFFS_CP CMD_SPIFFS_COPY +#define CMD_SPIFFS_STAT 0x0137 +#define CMD_SPIFFS_FSTAT 0x0138 +#define CMD_SPIFFS_INFO 0x0139 +#define CMD_SPIFFS_FORMAT CMD_FLASHMEM_WIPE -#define CMD_SPIFFS_WIPE 0x013A +#define CMD_SPIFFS_WIPE 0x013A -#define CMD_SET_FPGAMODE 0x013F +#define CMD_SET_FPGAMODE 0x013F // This take a +0x2000 as they are high level helper and special functions // As the others, they may have safety level argument if it makes sense -#define CMD_SPIFFS_PRINT_TREE 0x2130 -#define CMD_SPIFFS_GET_TREE 0x2131 -#define CMD_SPIFFS_TEST 0x2132 -#define CMD_SPIFFS_PRINT_FSINFO 0x2133 -#define CMD_SPIFFS_DOWNLOAD 0x2134 -#define CMD_SPIFFS_DOWNLOADED 0x2135 -#define CMD_SPIFFS_ELOAD 0x2136 -#define CMD_SPIFFS_CHECK 0x3000 +#define CMD_SPIFFS_PRINT_TREE 0x2130 +#define CMD_SPIFFS_GET_TREE 0x2131 +#define CMD_SPIFFS_TEST 0x2132 +#define CMD_SPIFFS_PRINT_FSINFO 0x2133 +#define CMD_SPIFFS_DOWNLOAD 0x2134 +#define CMD_SPIFFS_DOWNLOADED 0x2135 +#define CMD_SPIFFS_ELOAD 0x2136 +#define CMD_SPIFFS_CHECK 0x3000 // RDV40, Smart card operations -#define CMD_SMART_RAW 0x0140 -#define CMD_SMART_UPGRADE 0x0141 -#define CMD_SMART_UPLOAD 0x0142 -#define CMD_SMART_ATR 0x0143 -#define CMD_SMART_SETBAUD 0x0144 -#define CMD_SMART_SETCLOCK 0x0145 +#define CMD_SMART_RAW 0x0140 +#define CMD_SMART_UPGRADE 0x0141 +#define CMD_SMART_UPLOAD 0x0142 +#define CMD_SMART_ATR 0x0143 +#define CMD_SMART_SETBAUD 0x0144 +#define CMD_SMART_SETCLOCK 0x0145 // RDV40, FPC USART -#define CMD_USART_RX 0x0160 -#define CMD_USART_TX 0x0161 -#define CMD_USART_TXRX 0x0162 -#define CMD_USART_CONFIG 0x0163 +#define CMD_USART_RX 0x0160 +#define CMD_USART_TX 0x0161 +#define CMD_USART_TXRX 0x0162 +#define CMD_USART_CONFIG 0x0163 // For low-frequency tags -#define CMD_LF_TI_READ 0x0202 -#define CMD_LF_TI_WRITE 0x0203 -#define CMD_LF_ACQ_RAW_ADC 0x0205 -#define CMD_LF_MOD_THEN_ACQ_RAW_ADC 0x0206 -#define CMD_DOWNLOAD_BIGBUF 0x0207 -#define CMD_DOWNLOADED_BIGBUF 0x0208 -#define CMD_LF_UPLOAD_SIM_SAMPLES 0x0209 -#define CMD_LF_SIMULATE 0x020A -#define CMD_LF_HID_WATCH 0x020B -#define CMD_LF_HID_SIMULATE 0x020C -#define CMD_LF_SET_DIVISOR 0x020D -#define CMD_LF_SIMULATE_BIDIR 0x020E -#define CMD_SET_ADC_MUX 0x020F -#define CMD_LF_HID_CLONE 0x0210 -#define CMD_LF_EM410X_CLONE 0x0211 -#define CMD_LF_T55XX_READBL 0x0214 -#define CMD_LF_T55XX_WRITEBL 0x0215 -#define CMD_LF_T55XX_RESET_READ 0x0216 -#define CMD_LF_PCF7931_READ 0x0217 -#define CMD_LF_PCF7931_WRITE 0x0223 -#define CMD_LF_EM4X_LOGIN 0x0229 -#define CMD_LF_EM4X_READWORD 0x0218 -#define CMD_LF_EM4X_WRITEWORD 0x0219 -#define CMD_LF_EM4X_PROTECTWORD 0x021B -#define CMD_LF_EM4X_BF 0x022A -#define CMD_LF_IO_WATCH 0x021A -#define CMD_LF_EM410X_WATCH 0x021C -#define CMD_LF_EM4X50_INFO 0x0240 -#define CMD_LF_EM4X50_WRITE 0x0241 -#define CMD_LF_EM4X50_WRITEPWD 0x0242 -#define CMD_LF_EM4X50_READ 0x0243 -#define CMD_LF_EM4X50_BRUTE 0x0245 -#define CMD_LF_EM4X50_LOGIN 0x0246 -#define CMD_LF_EM4X50_SIM 0x0250 -#define CMD_LF_EM4X50_READER 0x0251 -#define CMD_LF_EM4X50_ESET 0x0252 -#define CMD_LF_EM4X50_CHK 0x0253 -#define CMD_LF_EM4X70_INFO 0x0260 -#define CMD_LF_EM4X70_WRITE 0x0261 -#define CMD_LF_EM4X70_UNLOCK 0x0262 -#define CMD_LF_EM4X70_AUTH 0x0263 -#define CMD_LF_EM4X70_SETPIN 0x0264 -#define CMD_LF_EM4X70_SETKEY 0x0265 -#define CMD_LF_EM4X70_BRUTE 0x0266 +#define CMD_LF_TI_READ 0x0202 +#define CMD_LF_TI_WRITE 0x0203 +#define CMD_LF_ACQ_RAW_ADC 0x0205 +#define CMD_LF_MOD_THEN_ACQ_RAW_ADC 0x0206 +#define CMD_DOWNLOAD_BIGBUF 0x0207 +#define CMD_DOWNLOADED_BIGBUF 0x0208 +#define CMD_LF_UPLOAD_SIM_SAMPLES 0x0209 +#define CMD_LF_SIMULATE 0x020A +#define CMD_LF_HID_WATCH 0x020B +#define CMD_LF_HID_SIMULATE 0x020C +#define CMD_LF_SET_DIVISOR 0x020D +#define CMD_LF_SIMULATE_BIDIR 0x020E +#define CMD_SET_ADC_MUX 0x020F +#define CMD_LF_HID_CLONE 0x0210 +#define CMD_LF_EM410X_CLONE 0x0211 +#define CMD_LF_T55XX_READBL 0x0214 +#define CMD_LF_T55XX_WRITEBL 0x0215 +#define CMD_LF_T55XX_RESET_READ 0x0216 +#define CMD_LF_PCF7931_READ 0x0217 +#define CMD_LF_PCF7931_WRITE 0x0223 +#define CMD_LF_EM4X_LOGIN 0x0229 +#define CMD_LF_EM4X_READWORD 0x0218 +#define CMD_LF_EM4X_WRITEWORD 0x0219 +#define CMD_LF_EM4X_PROTECTWORD 0x021B +#define CMD_LF_EM4X_BF 0x022A +#define CMD_LF_IO_WATCH 0x021A +#define CMD_LF_EM410X_WATCH 0x021C +#define CMD_LF_EM4X50_INFO 0x0240 +#define CMD_LF_EM4X50_WRITE 0x0241 +#define CMD_LF_EM4X50_WRITEPWD 0x0242 +#define CMD_LF_EM4X50_READ 0x0243 +#define CMD_LF_EM4X50_BRUTE 0x0245 +#define CMD_LF_EM4X50_LOGIN 0x0246 +#define CMD_LF_EM4X50_SIM 0x0250 +#define CMD_LF_EM4X50_READER 0x0251 +#define CMD_LF_EM4X50_ESET 0x0252 +#define CMD_LF_EM4X50_CHK 0x0253 +#define CMD_LF_EM4X70_INFO 0x0260 +#define CMD_LF_EM4X70_WRITE 0x0261 +#define CMD_LF_EM4X70_UNLOCK 0x0262 +#define CMD_LF_EM4X70_AUTH 0x0263 +#define CMD_LF_EM4X70_SETPIN 0x0264 +#define CMD_LF_EM4X70_SETKEY 0x0265 +#define CMD_LF_EM4X70_BRUTE 0x0266 // Sampling configuration for LF reader/sniffer -#define CMD_LF_SAMPLING_SET_CONFIG 0x021D -#define CMD_LF_FSK_SIMULATE 0x021E -#define CMD_LF_ASK_SIMULATE 0x021F -#define CMD_LF_PSK_SIMULATE 0x0220 -#define CMD_LF_NRZ_SIMULATE 0x0232 -#define CMD_LF_AWID_WATCH 0x0221 -#define CMD_LF_VIKING_CLONE 0x0222 -#define CMD_LF_T55XX_WAKEUP 0x0224 -#define CMD_LF_COTAG_READ 0x0225 -#define CMD_LF_T55XX_SET_CONFIG 0x0226 -#define CMD_LF_SAMPLING_PRINT_CONFIG 0x0227 -#define CMD_LF_SAMPLING_GET_CONFIG 0x0228 - -#define CMD_LF_T55XX_CHK_PWDS 0x0230 -#define CMD_LF_T55XX_DANGERRAW 0x0231 +#define CMD_LF_SAMPLING_SET_CONFIG 0x021D +#define CMD_LF_FSK_SIMULATE 0x021E +#define CMD_LF_ASK_SIMULATE 0x021F +#define CMD_LF_PSK_SIMULATE 0x0220 +#define CMD_LF_NRZ_SIMULATE 0x0232 +#define CMD_LF_AWID_WATCH 0x0221 +#define CMD_LF_VIKING_CLONE 0x0222 +#define CMD_LF_T55XX_WAKEUP 0x0224 +#define CMD_LF_COTAG_READ 0x0225 +#define CMD_LF_T55XX_SET_CONFIG 0x0226 +#define CMD_LF_SAMPLING_PRINT_CONFIG 0x0227 +#define CMD_LF_SAMPLING_GET_CONFIG 0x0228 +#define CMD_LF_T55XX_CHK_PWDS 0x0230 +#define CMD_LF_T55XX_DANGERRAW 0x0231 // ZX8211 -#define CMD_LF_ZX_READ 0x0270 -#define CMD_LF_ZX_WRITE 0x0271 +#define CMD_LF_ZX_READ 0x0270 +#define CMD_LF_ZX_WRITE 0x0271 /* CMD_SET_ADC_MUX: ext1 is 0 for lopkd, 1 for loraw, 2 for hipkd, 3 for hiraw */ // For the 13.56 MHz tags -#define CMD_HF_ISO15693_ACQ_RAW_ADC 0x0300 -#define CMD_HF_ACQ_RAW_ADC 0x0301 -#define CMD_HF_SRI_READ 0x0303 -#define CMD_HF_ISO14443B_COMMAND 0x0305 -#define CMD_HF_ISO15693_READER 0x0310 -#define CMD_HF_ISO15693_SIMULATE 0x0311 -#define CMD_HF_ISO15693_SNIFF 0x0312 -#define CMD_HF_ISO15693_COMMAND 0x0313 -#define CMD_HF_ISO15693_FINDAFI 0x0315 -#define CMD_HF_ISO15693_SLIX_ENABLE_PRIVACY 0x0867 -#define CMD_HF_ISO15693_SLIX_DISABLE_PRIVACY 0x0317 -#define CMD_HF_ISO15693_SLIX_DISABLE_EAS 0x0318 -#define CMD_HF_ISO15693_SLIX_ENABLE_EAS 0x0862 -#define CMD_HF_ISO15693_SLIX_PASS_PROTECT_AFI 0x0863 -#define CMD_HF_ISO15693_SLIX_PASS_PROTECT_EAS 0x0864 -#define CMD_HF_ISO15693_SLIX_WRITE_PWD 0x0865 -#define CMD_HF_ISO15693_SLIX_PROTECT_PAGE 0x0868 -#define CMD_HF_ISO15693_WRITE_AFI 0x0866 -#define CMD_HF_TEXKOM_SIMULATE 0x0320 -#define CMD_HF_ISO15693_EML_CLEAR 0x0330 -#define CMD_HF_ISO15693_EML_SETMEM 0x0331 -#define CMD_HF_ISO15693_EML_GETMEM 0x0332 +#define CMD_HF_ISO15693_ACQ_RAW_ADC 0x0300 +#define CMD_HF_ACQ_RAW_ADC 0x0301 +#define CMD_HF_SRI_READ 0x0303 +#define CMD_HF_ISO14443B_COMMAND 0x0305 +#define CMD_HF_ISO15693_READER 0x0310 +#define CMD_HF_ISO15693_SIMULATE 0x0311 +#define CMD_HF_ISO15693_SNIFF 0x0312 +#define CMD_HF_ISO15693_COMMAND 0x0313 +#define CMD_HF_ISO15693_FINDAFI 0x0315 +#define CMD_HF_ISO15693_SLIX_ENABLE_PRIVACY 0x0867 +#define CMD_HF_ISO15693_SLIX_DISABLE_PRIVACY 0x0317 +#define CMD_HF_ISO15693_SLIX_DISABLE_EAS 0x0318 +#define CMD_HF_ISO15693_SLIX_ENABLE_EAS 0x0862 +#define CMD_HF_ISO15693_SLIX_PASS_PROTECT_AFI 0x0863 +#define CMD_HF_ISO15693_SLIX_PASS_PROTECT_EAS 0x0864 +#define CMD_HF_ISO15693_SLIX_WRITE_PWD 0x0865 +#define CMD_HF_ISO15693_SLIX_PROTECT_PAGE 0x0868 +#define CMD_HF_ISO15693_WRITE_AFI 0x0866 +#define CMD_HF_TEXKOM_SIMULATE 0x0320 +#define CMD_HF_ISO15693_EML_CLEAR 0x0330 +#define CMD_HF_ISO15693_EML_SETMEM 0x0331 +#define CMD_HF_ISO15693_EML_GETMEM 0x0332 -#define CMD_HF_ISO15693_CSETUID 0x0316 -#define CMD_HF_ISO15693_CSETUID_V2 0x0333 +#define CMD_HF_ISO15693_CSETUID 0x0316 +#define CMD_HF_ISO15693_CSETUID_V2 0x0333 -#define CMD_LF_SNIFF_RAW_ADC 0x0360 +#define CMD_LF_SNIFF_RAW_ADC 0x0360 // For Hitag 2 transponders -#define CMD_LF_HITAG_SNIFF 0x0370 -#define CMD_LF_HITAG_SIMULATE 0x0371 -#define CMD_LF_HITAG_READER 0x0372 -#define CMD_LF_HITAG2_WRITE 0x0377 -#define CMD_LF_HITAG2_CRACK 0x0378 -#define CMD_LF_HITAG2_CRACK_2 0x0379 +#define CMD_LF_HITAG_SNIFF 0x0370 +#define CMD_LF_HITAG_SIMULATE 0x0371 +#define CMD_LF_HITAG_READER 0x0372 +#define CMD_LF_HITAG2_WRITE 0x0377 +#define CMD_LF_HITAG2_CRACK 0x0378 +#define CMD_LF_HITAG2_CRACK_2 0x0379 // For Hitag S -#define CMD_LF_HITAGS_TEST_TRACES 0x0367 -#define CMD_LF_HITAGS_SIMULATE 0x0368 -#define CMD_LF_HITAGS_READ 0x0373 -#define CMD_LF_HITAGS_WRITE 0x0375 -#define CMD_LF_HITAGS_UID 0x037A +#define CMD_LF_HITAGS_TEST_TRACES 0x0367 +#define CMD_LF_HITAGS_SIMULATE 0x0368 +#define CMD_LF_HITAGS_READ 0x0373 +#define CMD_LF_HITAGS_WRITE 0x0375 +#define CMD_LF_HITAGS_UID 0x037A // For Hitag µ -#define CMD_LF_HITAGU_READ 0x037B -#define CMD_LF_HITAGU_WRITE 0x037C -#define CMD_LF_HITAGU_SIMULATE 0x037D -#define CMD_LF_HITAGU_UID 0x037E +#define CMD_LF_HITAGU_READ 0x037B +#define CMD_LF_HITAGU_WRITE 0x037C +#define CMD_LF_HITAGU_SIMULATE 0x037D +#define CMD_LF_HITAGU_UID 0x037E -#define CMD_LF_HITAG_ELOAD 0x0376 +#define CMD_LF_HITAG_ELOAD 0x0376 -#define CMD_HF_ISO14443A_ANTIFUZZ 0x0380 -#define CMD_HF_ISO14443B_SIMULATE 0x0381 -#define CMD_HF_ISO14443B_SNIFF 0x0382 +#define CMD_HF_ISO14443A_ANTIFUZZ 0x0380 +#define CMD_HF_ISO14443B_SIMULATE 0x0381 +#define CMD_HF_ISO14443B_SNIFF 0x0382 -#define CMD_HF_ISO14443A_SNIFF 0x0383 -#define CMD_HF_ISO14443A_SIMULATE 0x0384 -#define CMD_HF_ISO14443A_SIM_AID 0x1420 +#define CMD_HF_ISO14443A_SNIFF 0x0383 +#define CMD_HF_ISO14443A_SIMULATE 0x0384 +#define CMD_HF_ISO14443A_SIM_AID 0x1420 -#define CMD_HF_ISO14443A_READER 0x0385 -#define CMD_HF_ISO14443A_EMV_SIMULATE 0x0386 +#define CMD_HF_ISO14443A_READER 0x0385 +#define CMD_HF_ISO14443A_EMV_SIMULATE 0x0386 -#define CMD_HF_LEGIC_SIMULATE 0x0387 -#define CMD_HF_LEGIC_READER 0x0388 -#define CMD_HF_LEGIC_WRITER 0x0389 +#define CMD_HF_LEGIC_SIMULATE 0x0387 +#define CMD_HF_LEGIC_READER 0x0388 +#define CMD_HF_LEGIC_WRITER 0x0389 -#define CMD_HF_EPA_COLLECT_NONCE 0x038A -#define CMD_HF_EPA_REPLAY 0x038B -#define CMD_HF_EPA_PACE_SIMULATE 0x038C +#define CMD_HF_EPA_COLLECT_NONCE 0x038A +#define CMD_HF_EPA_REPLAY 0x038B +#define CMD_HF_EPA_PACE_SIMULATE 0x038C -#define CMD_HF_LEGIC_INFO 0x03BC -#define CMD_HF_LEGIC_ESET 0x03BD +#define CMD_HF_LEGIC_INFO 0x03BC +#define CMD_HF_LEGIC_ESET 0x03BD // iCLASS / Picopass -#define CMD_HF_ICLASS_READCHECK 0x038F -#define CMD_HF_ICLASS_DUMP 0x0391 -#define CMD_HF_ICLASS_SNIFF 0x0392 -#define CMD_HF_ICLASS_SIMULATE 0x0393 -#define CMD_HF_ICLASS_READER 0x0394 -#define CMD_HF_ICLASS_READBL 0x0396 -#define CMD_HF_ICLASS_WRITEBL 0x0397 -#define CMD_HF_ICLASS_EML_MEMSET 0x0398 -#define CMD_HF_ICLASS_CHKKEYS 0x039A -#define CMD_HF_ICLASS_RESTORE 0x039B -#define CMD_HF_ICLASS_CREDIT_EPURSE 0x039C -#define CMD_HF_ICLASS_RECOVER 0x039D -#define CMD_HF_ICLASS_TEARBL 0x039E - +#define CMD_HF_ICLASS_READCHECK 0x038F +#define CMD_HF_ICLASS_DUMP 0x0391 +#define CMD_HF_ICLASS_SNIFF 0x0392 +#define CMD_HF_ICLASS_SIMULATE 0x0393 +#define CMD_HF_ICLASS_READER 0x0394 +#define CMD_HF_ICLASS_READBL 0x0396 +#define CMD_HF_ICLASS_WRITEBL 0x0397 +#define CMD_HF_ICLASS_EML_MEMSET 0x0398 +#define CMD_HF_ICLASS_CHKKEYS 0x039A +#define CMD_HF_ICLASS_RESTORE 0x039B +#define CMD_HF_ICLASS_CREDIT_EPURSE 0x039C +#define CMD_HF_ICLASS_RECOVER 0x039D +#define CMD_HF_ICLASS_TEARBL 0x039E // For ISO1092 / FeliCa -#define CMD_HF_FELICA_SIMULATE 0x03A0 -#define CMD_HF_FELICA_SNIFF 0x03A1 -#define CMD_HF_FELICA_COMMAND 0x03A2 -//temp -#define CMD_HF_FELICALITE_DUMP 0x03AA -#define CMD_HF_FELICALITE_SIMULATE 0x03AB +#define CMD_HF_FELICA_SIMULATE 0x03A0 +#define CMD_HF_FELICA_SNIFF 0x03A1 +#define CMD_HF_FELICA_COMMAND 0x03A2 +// temp +#define CMD_HF_FELICALITE_DUMP 0x03AA +#define CMD_HF_FELICALITE_SIMULATE 0x03AB // For 14a config -#define CMD_HF_ISO14443A_PRINT_CONFIG 0x03B0 -#define CMD_HF_ISO14443A_GET_CONFIG 0x03B1 -#define CMD_HF_ISO14443A_SET_CONFIG 0x03B2 +#define CMD_HF_ISO14443A_PRINT_CONFIG 0x03B0 +#define CMD_HF_ISO14443A_GET_CONFIG 0x03B1 +#define CMD_HF_ISO14443A_SET_CONFIG 0x03B2 -#define CMD_HF_ISO14443A_SET_THRESHOLDS 0x03B8 +#define CMD_HF_ISO14443A_SET_THRESHOLDS 0x03B8 // For 14b config -#define CMD_HF_ISO14443B_PRINT_CONFIG 0x03D0 -#define CMD_HF_ISO14443B_GET_CONFIG 0x03D1 -#define CMD_HF_ISO14443B_SET_CONFIG 0x03D2 +#define CMD_HF_ISO14443B_PRINT_CONFIG 0x03D0 +#define CMD_HF_ISO14443B_GET_CONFIG 0x03D1 +#define CMD_HF_ISO14443B_SET_CONFIG 0x03D2 // For measurements of the antenna tuning -#define CMD_MEASURE_ANTENNA_TUNING 0x0400 -#define CMD_MEASURE_ANTENNA_TUNING_HF 0x0401 -#define CMD_MEASURE_ANTENNA_TUNING_LF 0x0402 -#define CMD_LISTEN_READER_FIELD 0x0420 -#define CMD_HF_DROPFIELD 0x0430 -#define CMD_HF_DECAY 0x0440 +#define CMD_MEASURE_ANTENNA_TUNING 0x0400 +#define CMD_MEASURE_ANTENNA_TUNING_HF 0x0401 +#define CMD_MEASURE_ANTENNA_TUNING_LF 0x0402 +#define CMD_LISTEN_READER_FIELD 0x0420 +#define CMD_HF_DROPFIELD 0x0430 +#define CMD_HF_DECAY 0x0440 // For direct FPGA control -#define CMD_FPGA_MAJOR_MODE_OFF 0x0500 +#define CMD_FPGA_MAJOR_MODE_OFF 0x0500 // For mifare commands -#define CMD_HF_MIFARE_EML_MEMCLR 0x0601 -#define CMD_HF_MIFARE_EML_MEMSET 0x0602 -#define CMD_HF_MIFARE_EML_MEMGET 0x0603 -#define CMD_HF_MIFARE_EML_LOAD 0x0604 +#define CMD_HF_MIFARE_EML_MEMCLR 0x0601 +#define CMD_HF_MIFARE_EML_MEMSET 0x0602 +#define CMD_HF_MIFARE_EML_MEMGET 0x0603 +#define CMD_HF_MIFARE_EML_LOAD 0x0604 // magic chinese card commands -#define CMD_HF_MIFARE_CSETBL 0x0605 -#define CMD_HF_MIFARE_CGETBL 0x0606 -#define CMD_HF_MIFARE_CIDENT 0x0607 +#define CMD_HF_MIFARE_CSETBL 0x0605 +#define CMD_HF_MIFARE_CGETBL 0x0606 +#define CMD_HF_MIFARE_CIDENT 0x0607 -#define CMD_HF_MIFARE_SIMULATE 0x0610 +#define CMD_HF_MIFARE_SIMULATE 0x0610 -#define CMD_HF_MIFARE_READER 0x0611 -#define CMD_HF_MIFARE_NESTED 0x0612 -#define CMD_HF_MIFARE_ACQ_ENCRYPTED_NONCES 0x0613 -#define CMD_HF_MIFARE_ACQ_NONCES 0x0614 -#define CMD_HF_MIFARE_STATIC_NESTED 0x0615 -#define CMD_HF_MIFARE_STATIC_ENC 0x0616 -#define CMD_HF_MIFARE_ACQ_STATIC_ENCRYPTED_NONCES 0x0617 +#define CMD_HF_MIFARE_READER 0x0611 +#define CMD_HF_MIFARE_NESTED 0x0612 +#define CMD_HF_MIFARE_ACQ_ENCRYPTED_NONCES 0x0613 +#define CMD_HF_MIFARE_ACQ_NONCES 0x0614 +#define CMD_HF_MIFARE_STATIC_NESTED 0x0615 +#define CMD_HF_MIFARE_STATIC_ENC 0x0616 +#define CMD_HF_MIFARE_ACQ_STATIC_ENCRYPTED_NONCES 0x0617 -#define CMD_HF_MIFARE_READBL 0x0620 -#define CMD_HF_MIFARE_READBL_EX 0x0628 -#define CMD_HF_MIFAREU_READBL 0x0720 -#define CMD_HF_MIFARE_READSC 0x0621 -#define CMD_HF_MIFAREU_READCARD 0x0721 -#define CMD_HF_MIFARE_WRITEBL 0x0622 -#define CMD_HF_MIFARE_WRITEBL_EX 0x0629 -#define CMD_HF_MIFARE_VALUE 0x0627 -#define CMD_HF_MIFAREU_WRITEBL 0x0722 -#define CMD_HF_MIFAREU_WRITEBL_COMPAT 0x0723 +#define CMD_HF_MIFARE_READBL 0x0620 +#define CMD_HF_MIFARE_READBL_EX 0x0628 +#define CMD_HF_MIFAREU_READBL 0x0720 +#define CMD_HF_MIFARE_READSC 0x0621 +#define CMD_HF_MIFAREU_READCARD 0x0721 +#define CMD_HF_MIFARE_WRITEBL 0x0622 +#define CMD_HF_MIFARE_WRITEBL_EX 0x0629 +#define CMD_HF_MIFARE_VALUE 0x0627 +#define CMD_HF_MIFAREU_WRITEBL 0x0722 +#define CMD_HF_MIFAREU_WRITEBL_COMPAT 0x0723 -#define CMD_HF_MIFARE_CHKKEYS 0x0623 -#define CMD_HF_MIFARE_SETMOD 0x0624 -#define CMD_HF_MIFARE_CHKKEYS_FAST 0x0625 -#define CMD_HF_MIFARE_CHKKEYS_FILE 0x0626 +#define CMD_HF_MIFARE_CHKKEYS 0x0623 +#define CMD_HF_MIFARE_SETMOD 0x0624 +#define CMD_HF_MIFARE_CHKKEYS_FAST 0x0625 +#define CMD_HF_MIFARE_CHKKEYS_FILE 0x0626 -#define CMD_HF_MIFARE_SNIFF 0x0630 -#define CMD_HF_MIFARE_MFKEY 0x0631 -#define CMD_HF_MIFARE_PERSONALIZE_UID 0x0632 +#define CMD_HF_MIFARE_SNIFF 0x0630 +#define CMD_HF_MIFARE_MFKEY 0x0631 +#define CMD_HF_MIFARE_PERSONALIZE_UID 0x0632 // ultralight-C & AES -#define CMD_HF_MIFAREU3P_AUTH 0x0724 +#define CMD_HF_MIFAREU3P_AUTH 0x0724 // 0x0725 is free -#define CMD_HF_MIFAREU3P_CHKKEY 0x0726 -#define CMD_HF_MIFAREU_SETKEY 0x0727 +#define CMD_HF_MIFAREU3P_CHKKEY 0x0726 +#define CMD_HF_MIFAREU_SETKEY 0x0727 // mifare desfire -#define CMD_HF_DESFIRE_READBL 0x0728 -#define CMD_HF_DESFIRE_WRITEBL 0x0729 -#define CMD_HF_DESFIRE_AUTH1 0x072a -#define CMD_HF_DESFIRE_AUTH2 0x072b -#define CMD_HF_DESFIRE_READER 0x072c -#define CMD_HF_DESFIRE_INFO 0x072d -#define CMD_HF_DESFIRE_COMMAND 0x072e +#define CMD_HF_DESFIRE_READBL 0x0728 +#define CMD_HF_DESFIRE_WRITEBL 0x0729 +#define CMD_HF_DESFIRE_AUTH1 0x072a +#define CMD_HF_DESFIRE_AUTH2 0x072b +#define CMD_HF_DESFIRE_READER 0x072c +#define CMD_HF_DESFIRE_INFO 0x072d +#define CMD_HF_DESFIRE_COMMAND 0x072e -#define CMD_HF_MIFARE_NACK_DETECT 0x0730 -#define CMD_HF_MIFARE_STATIC_NONCE 0x0731 -#define CMD_HF_MIFARE_STATIC_ENCRYPTED_NONCE 0x0732 +#define CMD_HF_MIFARE_NACK_DETECT 0x0730 +#define CMD_HF_MIFARE_STATIC_NONCE 0x0731 +#define CMD_HF_MIFARE_STATIC_ENCRYPTED_NONCE 0x0732 // MFU OTP TearOff -#define CMD_HF_MFU_OTP_TEAROFF 0x0740 +#define CMD_HF_MFU_OTP_TEAROFF 0x0740 // MFU_Ev1 Counter TearOff -#define CMD_HF_MFU_COUNTER_TEAROFF 0x0741 -#define CMD_HF_MFU_ULC_CHKKEYS 0x0742 -#define CMD_HF_MFU_ULAES_CHKKEYS 0x0743 +#define CMD_HF_MFU_COUNTER_TEAROFF 0x0741 +#define CMD_HF_MFU_ULC_CHKKEYS 0x0742 +#define CMD_HF_MFU_ULAES_CHKKEYS 0x0743 - -#define CMD_HF_SNIFF 0x0800 -#define CMD_HF_PLOT 0x0801 +#define CMD_HF_SNIFF 0x0800 +#define CMD_HF_PLOT 0x0801 // Fpga plot download -#define CMD_FPGAMEM_DOWNLOAD 0x0802 -#define CMD_FPGAMEM_DOWNLOADED 0x0803 +#define CMD_FPGAMEM_DOWNLOAD 0x0802 +#define CMD_FPGAMEM_DOWNLOADED 0x0803 // For ThinFilm Kovio -#define CMD_HF_THINFILM_READ 0x0810 -#define CMD_HF_THINFILM_SIMULATE 0x0811 +#define CMD_HF_THINFILM_READ 0x0810 +#define CMD_HF_THINFILM_SIMULATE 0x0811 -//For Atmel CryptoRF -#define CMD_HF_CRYPTORF_SIM 0x0820 +// For Atmel CryptoRF +#define CMD_HF_CRYPTORF_SIM 0x0820 // Gen 3 magic cards -#define CMD_HF_MIFARE_GEN3UID 0x0850 -#define CMD_HF_MIFARE_GEN3BLK 0x0851 -#define CMD_HF_MIFARE_GEN3FREEZ 0x0852 +#define CMD_HF_MIFARE_GEN3UID 0x0850 +#define CMD_HF_MIFARE_GEN3BLK 0x0851 +#define CMD_HF_MIFARE_GEN3FREEZ 0x0852 // Gen 4 GTU magic cards -#define CMD_HF_MIFARE_G4_RDBL 0x0860 -#define CMD_HF_MIFARE_G4_WRBL 0x0861 +#define CMD_HF_MIFARE_G4_RDBL 0x0860 +#define CMD_HF_MIFARE_G4_WRBL 0x0861 // Gen 4 GDM magic cards -#define CMD_HF_MIFARE_G4_GDM_RDBL 0x0870 -#define CMD_HF_MIFARE_G4_GDM_WRBL 0x0871 +#define CMD_HF_MIFARE_G4_GDM_RDBL 0x0870 +#define CMD_HF_MIFARE_G4_GDM_WRBL 0x0871 // HID SAM -#define CMD_HF_SAM_PICOPASS 0x0900 -#define CMD_HF_SAM_SEOS 0x0901 -#define CMD_HF_SAM_MFC 0x0902 +#define CMD_HF_SAM_PICOPASS 0x0900 +#define CMD_HF_SAM_SEOS 0x0901 +#define CMD_HF_SAM_MFC 0x0902 -#define CMD_HF_SEOS_SIMULATE 0x0903 +#define CMD_HF_SEOS_SIMULATE 0x0903 -#define CMD_UNKNOWN 0xFFFF +#define CMD_UNKNOWN 0xFFFF -//Mifare simulation flags -// In interactive mode, we are expected to finish the operation with an ACK -#define FLAG_INTERACTIVE 0x0001 -#define FLAG_ATQA_IN_DATA 0x0002 -#define FLAG_SAK_IN_DATA 0x0004 -#define FLAG_ATS_IN_DATA 0x0008 -#define FLAG_ENUMERATE_AID 0x0010 +// Mifare simulation flags +// In interactive mode, we are expected to finish the operation with an ACK +#define FLAG_INTERACTIVE 0x0001 +#define FLAG_ATQA_IN_DATA 0x0002 +#define FLAG_SAK_IN_DATA 0x0004 +#define FLAG_ATS_IN_DATA 0x0008 +#define FLAG_ENUMERATE_AID 0x0010 // internal constants, use the function macros instead -#define FLAG_MASK_UID 0x0030 -#define FLAG_UID_IN_EMUL 0x0000 -#define FLAG_4B_UID_IN_DATA 0x0010 -#define FLAG_7B_UID_IN_DATA 0x0020 -#define FLAG_10B_UID_IN_DATA 0x0030 +#define FLAG_MASK_UID 0x0030 +#define FLAG_UID_IN_EMUL 0x0000 +#define FLAG_4B_UID_IN_DATA 0x0010 +#define FLAG_7B_UID_IN_DATA 0x0020 +#define FLAG_10B_UID_IN_DATA 0x0030 // if there is a UID in the data-section to be used: // note: if UIDLEN is wrong, we default to FLAG_UID_IN_EMUL -#define FLAG_SET_UID_IN_DATA(flags, len) {\ - flags = (flags & (~FLAG_MASK_UID))|\ - (len == 4 ? FLAG_4B_UID_IN_DATA : \ - (len == 7 ? FLAG_7B_UID_IN_DATA : \ - (len == 10 ? FLAG_10B_UID_IN_DATA : \ - FLAG_UID_IN_EMUL)));\ +#define FLAG_SET_UID_IN_DATA(flags, len) \ + { \ + flags = (flags & (~FLAG_MASK_UID)) | \ + (len == 4 ? FLAG_4B_UID_IN_DATA : (len == 7 ? FLAG_7B_UID_IN_DATA : (len == 10 ? FLAG_10B_UID_IN_DATA : FLAG_UID_IN_EMUL))); \ } // else we tell to take UID from block 0: -#define FLAG_SET_UID_IN_EMUL(flags) {flags = (flags & (~FLAG_MASK_UID))|FLAG_UID_IN_EMUL;} -#define IS_FLAG_UID_IN_DATA(flags, len) (\ - (flags & FLAG_MASK_UID) == \ - (len == 4 ? FLAG_4B_UID_IN_DATA : \ - (len == 7 ? FLAG_7B_UID_IN_DATA : \ - (len == 10 ? FLAG_10B_UID_IN_DATA : \ - FLAG_UID_IN_EMUL)))\ - ) +#define FLAG_SET_UID_IN_EMUL(flags) \ + { \ + flags = (flags & (~FLAG_MASK_UID)) | FLAG_UID_IN_EMUL; \ + } +#define IS_FLAG_UID_IN_DATA(flags, len) ( \ + (flags & FLAG_MASK_UID) == \ + (len == 4 ? FLAG_4B_UID_IN_DATA : (len == 7 ? FLAG_7B_UID_IN_DATA : (len == 10 ? FLAG_10B_UID_IN_DATA : FLAG_UID_IN_EMUL)))) #define IS_FLAG_UID_IN_EMUL(flags) ((flags & FLAG_MASK_UID) == FLAG_UID_IN_EMUL) // internal constants, use the function macros instead -#define MIFARE_4K_MAX_BYTES 4096 -#define MIFARE_2K_MAX_BYTES 2048 -#define MIFARE_1K_MAX_BYTES 1024 -#define MIFARE_MINI_MAX_BYTES 320 +#define MIFARE_4K_MAX_BYTES 4096 +#define MIFARE_2K_MAX_BYTES 2048 +#define MIFARE_1K_MAX_BYTES 1024 +#define MIFARE_MINI_MAX_BYTES 320 -#define FLAG_MASK_MF_SIZE 0x00C0 -#define FLAG_MF_MINI 0x0000 -#define FLAG_MF_1K 0x0040 -#define FLAG_MF_2K 0x0080 -#define FLAG_MF_4K 0x00C0 +#define FLAG_MASK_MF_SIZE 0x00C0 +#define FLAG_MF_MINI 0x0000 +#define FLAG_MF_1K 0x0040 +#define FLAG_MF_2K 0x0080 +#define FLAG_MF_4K 0x00C0 -#define FLAG_SET_MF_SIZE(flags, size) {\ - flags = (flags & (~FLAG_MASK_MF_SIZE))|\ - (size == MIFARE_MINI_MAX_BYTES ? FLAG_MF_MINI : \ - (size == MIFARE_1K_MAX_BYTES ? FLAG_MF_1K : \ - (size == MIFARE_2K_MAX_BYTES ? FLAG_MF_2K : \ - (size == MIFARE_4K_MAX_BYTES ? FLAG_MF_4K : \ - 0))));\ +#define FLAG_SET_MF_SIZE(flags, size) \ + { \ + flags = (flags & (~FLAG_MASK_MF_SIZE)) | \ + (size == MIFARE_MINI_MAX_BYTES ? FLAG_MF_MINI : (size == MIFARE_1K_MAX_BYTES ? FLAG_MF_1K : (size == MIFARE_2K_MAX_BYTES ? FLAG_MF_2K : (size == MIFARE_4K_MAX_BYTES ? FLAG_MF_4K : 0)))); \ } // else we tell to take UID from block 0: -#define IS_FLAG_MF_SIZE(flags, size) (\ - (flags & FLAG_MASK_MF_SIZE) == \ - (size == MIFARE_MINI_MAX_BYTES ? FLAG_MF_MINI : \ - (size == MIFARE_1K_MAX_BYTES ? FLAG_MF_1K : \ - (size == MIFARE_2K_MAX_BYTES ? FLAG_MF_2K : \ - (size == MIFARE_4K_MAX_BYTES ? FLAG_MF_4K : \ - 0))))\ - ) +#define IS_FLAG_MF_SIZE(flags, size) ( \ + (flags & FLAG_MASK_MF_SIZE) == \ + (size == MIFARE_MINI_MAX_BYTES ? FLAG_MF_MINI : (size == MIFARE_1K_MAX_BYTES ? FLAG_MF_1K : (size == MIFARE_2K_MAX_BYTES ? FLAG_MF_2K : (size == MIFARE_4K_MAX_BYTES ? FLAG_MF_4K : 0))))) -#define FLAG_MF_USE_READ_KEYB 0x0100 -#define FLAG_CVE21_0430 0x0200 +#define FLAG_MF_USE_READ_KEYB 0x0100 +#define FLAG_CVE21_0430 0x0200 // collect NR_AR responses for bruteforcing later -#define FLAG_NR_AR_ATTACK 0x0400 +#define FLAG_NR_AR_ATTACK 0x0400 // support nested authentication attack #define FLAG_NESTED_AUTH_ATTACK 0x0800 -#define FLAG_MF_ALLOW_OOB_AUTH 0x1000 +#define FLAG_MF_ALLOW_OOB_AUTH 0x1000 -#define MODE_SIM_CSN 0 +#define MODE_SIM_CSN 0 #define MODE_EXIT_AFTER_MAC 1 -#define MODE_FULLSIM 2 +#define MODE_FULLSIM 2 // Static Nonce detection -#define NONCE_FAIL 0x01 -#define NONCE_NORMAL 0x02 -#define NONCE_STATIC 0x03 -#define NONCE_STATIC_ENC 0x04 +#define NONCE_FAIL 0x01 +#define NONCE_NORMAL 0x02 +#define NONCE_STATIC 0x03 +#define NONCE_STATIC_ENC 0x04 #define NONCE_SUPERSTATIC 0x05 // Dbprintf flags -#define FLAG_RAWPRINT 0x00 -#define FLAG_LOG 0x01 -#define FLAG_NEWLINE 0x02 -#define FLAG_INPLACE 0x04 -#define FLAG_ANSI 0x08 +#define FLAG_RAWPRINT 0x00 +#define FLAG_LOG 0x01 +#define FLAG_NEWLINE 0x02 +#define FLAG_INPLACE 0x04 +#define FLAG_ANSI 0x08 // Error codes Usages: // NOTE: Positive values should be reserved for commands in case they need to return multiple statuses and error codes simultaneously. // Success (no error) -#define PM3_SUCCESS 0 +#define PM3_SUCCESS 0 // Undefined error -#define PM3_EUNDEF -1 +#define PM3_EUNDEF -1 // Invalid argument(s) client: user input parsing -#define PM3_EINVARG -2 +#define PM3_EINVARG -2 // Operation not supported by device client/pm3: probably only on pm3 once client becomes universal -#define PM3_EDEVNOTSUPP -3 +#define PM3_EDEVNOTSUPP -3 // Operation timed out client: no response in time from pm3 -#define PM3_ETIMEOUT -4 +#define PM3_ETIMEOUT -4 // Operation aborted (by user) client/pm3: kbd/button pressed -#define PM3_EOPABORTED -5 +#define PM3_EOPABORTED -5 // Not (yet) implemented client/pm3: TBD place holder -#define PM3_ENOTIMPL -6 +#define PM3_ENOTIMPL -6 // Error while RF transmission client/pm3: fail between pm3 & card -#define PM3_ERFTRANS -7 +#define PM3_ERFTRANS -7 // Input / output error pm3: error in client frame reception -#define PM3_EIO -8 +#define PM3_EIO -8 // Buffer overflow client/pm3: specified buffer too large for the operation -#define PM3_EOVFLOW -9 +#define PM3_EOVFLOW -9 // Software error client/pm3: e.g. error in parsing some data -#define PM3_ESOFT -10 +#define PM3_ESOFT -10 // Flash error client/pm3: error in RDV4 Flash operation -#define PM3_EFLASH -11 +#define PM3_EFLASH -11 // Memory allocation error client: error in memory allocation (maybe also for pm3 BigBuff?) -#define PM3_EMALLOC -12 +#define PM3_EMALLOC -12 // File error client: error related to file access on host -#define PM3_EFILE -13 +#define PM3_EFILE -13 // Generic TTY error -#define PM3_ENOTTY -14 +#define PM3_ENOTTY -14 // Initialization error pm3: error related to trying to initialize the pm3 / fpga for different operations -#define PM3_EINIT -15 +#define PM3_EINIT -15 // Expected a different answer error client/pm3: error when expecting one answer and got another one -#define PM3_EWRONGANSWER -16 +#define PM3_EWRONGANSWER -16 // Memory out-of-bounds error client/pm3: error when a read/write is outside the expected array -#define PM3_EOUTOFBOUND -17 +#define PM3_EOUTOFBOUND -17 // exchange with card error client/pm3: error when cant get answer from card or got an incorrect answer -#define PM3_ECARDEXCHANGE -18 +#define PM3_ECARDEXCHANGE -18 // Failed to create APDU, -#define PM3_EAPDU_ENCODEFAIL -19 +#define PM3_EAPDU_ENCODEFAIL -19 // APDU responded with a failure code -#define PM3_EAPDU_FAIL -20 +#define PM3_EAPDU_FAIL -20 // execute pm3 cmd failed client/pm3: when one of our pm3 cmd tries and fails. opposite from PM3_SUCCESS -#define PM3_EFAILED -21 +#define PM3_EFAILED -21 // partial success client/pm3: when trying to dump a tag and fails on some blocks. Partial dump. -#define PM3_EPARTIAL -22 +#define PM3_EPARTIAL -22 // tearoff occurred client/pm3: when a tearoff hook was called and a tearoff actually happened -#define PM3_ETEAROFF -23 +#define PM3_ETEAROFF -23 // Got bad CRC client/pm3: error in transfer of data, crc mismatch. -#define PM3_ECRC -24 +#define PM3_ECRC -24 // STATIC Nonce detect pm3: when collecting nonces for hardnested -#define PM3_ESTATIC_NONCE -25 +#define PM3_ESTATIC_NONCE -25 // No PACS data pm3: when using HID SAM to retried PACS data -#define PM3_ENOPACS -26 +#define PM3_ENOPACS -26 // Got wrong length error pm3: when received wrong length of data -#define PM3_ELENGTH -27 +#define PM3_ELENGTH -27 // No key available client/pm3: no cryptographic key available. -#define PM3_ENOKEY -28 +#define PM3_ENOKEY -28 // Cryptographic error client/pm3: cryptographic operation failed -#define PM3_ECRYPTO -29 +#define PM3_ECRYPTO -29 // File error client: error related to file does not exist in search paths -#define PM3_ENOFILE -30 +#define PM3_ENOFILE -30 // No data client/pm3: no data available, no host frame available (not really an error) -#define PM3_ENODATA -98 +#define PM3_ENODATA -98 // Quit program client: reserved, order to quit the program -#define PM3_EFATAL -99 +#define PM3_EFATAL -99 // Regular quit -#define PM3_SQUIT -100 +#define PM3_SQUIT -100 // reserved for future protocol change -#define PM3_RESERVED -128 +#define PM3_RESERVED -128 -#define PM3_REASON_UNKNOWN -1 +#define PM3_REASON_UNKNOWN -1 // LF -#define LF_FREQ2DIV(f) ((int)(((12000.0 + (f)/2.0)/(f))-1)) +#define LF_FREQ2DIV(f) ((int)(((12000.0 + (f) / 2.0) / (f)) - 1)) #define LF_DIVISOR_125 LF_FREQ2DIV(125) #define LF_DIVISOR_134 LF_FREQ2DIV(134.2) -#define LF_DIV2FREQ(d) (12000.0/((d)+1)) +#define LF_DIV2FREQ(d) (12000.0 / ((d) + 1)) #define LF_CMDREAD_MAX_EXTRA_SYMBOLS 4 // Receiving from USART need more than 30ms as we used on USB @@ -1078,51 +1109,50 @@ typedef struct { // took settings from libnfc/buses/uart.c // uart_win32.c & uart_posix.c -# define UART_FPC_CLIENT_RX_TIMEOUT_MS 200 -# define UART_USB_CLIENT_RX_TIMEOUT_MS 20 -# define UART_NET_CLIENT_RX_TIMEOUT_MS 500 -# define UART_TCP_LOCAL_CLIENT_RX_TIMEOUT_MS 40 -# define UART_UDP_LOCAL_CLIENT_RX_TIMEOUT_MS 20 - +#define UART_FPC_CLIENT_RX_TIMEOUT_MS 200 +#define UART_USB_CLIENT_RX_TIMEOUT_MS 20 +#define UART_NET_CLIENT_RX_TIMEOUT_MS 500 +#define UART_TCP_LOCAL_CLIENT_RX_TIMEOUT_MS 40 +#define UART_UDP_LOCAL_CLIENT_RX_TIMEOUT_MS 20 // CMD_DEVICE_INFO response packet has flags in arg[0], flag definitions: /* Whether a bootloader that understands the g_common_area is present */ -#define DEVICE_INFO_FLAG_BOOTROM_PRESENT (1<<0) +#define DEVICE_INFO_FLAG_BOOTROM_PRESENT (1 << 0) /* Whether a osimage that understands the g_common_area is present */ -#define DEVICE_INFO_FLAG_OSIMAGE_PRESENT (1<<1) +#define DEVICE_INFO_FLAG_OSIMAGE_PRESENT (1 << 1) /* Set if the bootloader is currently executing */ -#define DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM (1<<2) +#define DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM (1 << 2) /* Set if the OS is currently executing */ -#define DEVICE_INFO_FLAG_CURRENT_MODE_OS (1<<3) +#define DEVICE_INFO_FLAG_CURRENT_MODE_OS (1 << 3) /* Set if this device understands the extend start flash command */ -#define DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH (1<<4) +#define DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH (1 << 4) /* Set if this device understands the chip info command */ -#define DEVICE_INFO_FLAG_UNDERSTANDS_CHIP_INFO (1<<5) +#define DEVICE_INFO_FLAG_UNDERSTANDS_CHIP_INFO (1 << 5) /* Set if this device understands the version command */ -#define DEVICE_INFO_FLAG_UNDERSTANDS_VERSION (1<<6) +#define DEVICE_INFO_FLAG_UNDERSTANDS_VERSION (1 << 6) /* Set if this device understands the read memory command */ -#define DEVICE_INFO_FLAG_UNDERSTANDS_READ_MEM (1<<7) +#define DEVICE_INFO_FLAG_UNDERSTANDS_READ_MEM (1 << 7) #define BL_VERSION_MAJOR(version) ((uint32_t)(version) >> 22) #define BL_VERSION_MINOR(version) (((uint32_t)(version) >> 12) & 0x3ff) #define BL_VERSION_PATCH(version) ((uint32_t)(version) & 0xfff) #define BL_MAKE_VERSION(major, minor, patch) (((major) << 22) | ((minor) << 12) | (patch)) // Some boundaries to distinguish valid versions from corrupted info -#define BL_VERSION_FIRST_MAJOR 1 -#define BL_VERSION_LAST_MAJOR 99 -#define BL_VERSION_INVALID 0 +#define BL_VERSION_FIRST_MAJOR 1 +#define BL_VERSION_LAST_MAJOR 99 +#define BL_VERSION_INVALID 0 // Different versions here. Each version should increase the numbers -#define BL_VERSION_1_0_0 BL_MAKE_VERSION(1, 0, 0) +#define BL_VERSION_1_0_0 BL_MAKE_VERSION(1, 0, 0) /* CMD_READ_MEM_DOWNLOAD flags */ -#define READ_MEM_DOWNLOAD_FLAG_RAW (1<<0) +#define READ_MEM_DOWNLOAD_FLAG_RAW (1 << 0) /* CMD_START_FLASH may have three arguments: start of area to flash, end of area to flash, optional magic.