diff --git a/armsrc/Standalone/hf_doegox_auth0.c b/armsrc/Standalone/hf_doegox_auth0.c index 7e79ca788..113f15cfc 100644 --- a/armsrc/Standalone/hf_doegox_auth0.c +++ b/armsrc/Standalone/hf_doegox_auth0.c @@ -140,8 +140,8 @@ static bool find_tag(tag_t *tag_type) { switch (version_len) { case 0x0A: { if ((memcmp(version, "\x00\x04\x03\x01\x04\x00\x0F\x03", 8) == 0) || - (memcmp(version, "\x00\x04\x03\x02\x04\x00\x0F\x03", 8) == 0) || - (memcmp(version, "\x00\x04\x03\x03\x04\x00\x0F\x03", 8) == 0)) { + (memcmp(version, "\x00\x04\x03\x02\x04\x00\x0F\x03", 8) == 0) || + (memcmp(version, "\x00\x04\x03\x03\x04\x00\x0F\x03", 8) == 0)) { *tag_type = TAG_ULAES; // DbpString("Found Ultralight AES"); } @@ -342,10 +342,16 @@ static bool write_auth0(tag_t type) { uint8_t cmd[8] = {MIFARE_ULC_WRITE}; if (type == TAG_ULC) { cmd[1] = 0x2A; - cmd[2] = 0x30; cmd[3] = 0x00; cmd[4] = 0x00; cmd[5] = 0x00; + cmd[2] = 0x30; + cmd[3] = 0x00; + cmd[4] = 0x00; + cmd[5] = 0x00; } else if (type == TAG_ULAES) { cmd[1] = 0x29; - cmd[2] = 0x00; cmd[3] = 0x00; cmd[4] = 0x00; cmd[5] = 0x3C; + cmd[2] = 0x00; + cmd[3] = 0x00; + cmd[4] = 0x00; + cmd[5] = 0x3C; } else { goto out; } @@ -387,92 +393,92 @@ void RunMod(void) { } switch (state) { - case ST_LOOK_FOR_CARD: { - if (welcome_state_look) { - Dbprintf("Place an Ultralight C or Ultralight AES tag on the Proxmark3."); - welcome_state_look = false; - } - blink_led_slow(LED_A); - if (find_tag(&tag_type)) { - if (tag_type == TAG_ULC) { - DbpString("Found Ultralight C tag!"); - state = ST_SNIFF_AUTH; - // SpinDelay(1000); - break; - }else if (tag_type == TAG_ULAES) { - DbpString("Found Ultralight AES tag!"); - state = ST_SNIFF_AUTH; - // SpinDelay(1000); - break; - } else { - DbpString("Found other tag type, ignoring..."); - uint32_t t0 = GetTickCount(); - while (GetTickCount() - t0 < 2000) { - blink_led_fast(LED_A); + case ST_LOOK_FOR_CARD: { + if (welcome_state_look) { + Dbprintf("Place an Ultralight C or Ultralight AES tag on the Proxmark3."); + welcome_state_look = false; + } + blink_led_slow(LED_A); + if (find_tag(&tag_type)) { + if (tag_type == TAG_ULC) { + DbpString("Found Ultralight C tag!"); + state = ST_SNIFF_AUTH; + // SpinDelay(1000); + break; + } else if (tag_type == TAG_ULAES) { + DbpString("Found Ultralight AES tag!"); + state = ST_SNIFF_AUTH; + // SpinDelay(1000); + break; + } else { + DbpString("Found other tag type, ignoring..."); + uint32_t t0 = GetTickCount(); + while (GetTickCount() - t0 < 2000) { + blink_led_fast(LED_A); + } } } + break; } - break; - } - case ST_SNIFF_AUTH: { - if (welcome_state_sniff) { - Dbprintf("Bring the tag and Proxmark3 together slowly towards the authenticating reader."); - welcome_state_sniff = false; + case ST_SNIFF_AUTH: { + if (welcome_state_sniff) { + Dbprintf("Bring the tag and Proxmark3 together slowly towards the authenticating reader."); + welcome_state_sniff = false; + } + LED_A_ON(); + LED_B_ON(); + if (sniff_wait_for_rnda_reply(tag_type)) { + LED_B_ON(); + LED_C_ON(); + DbpString("Card is authenticated!"); + state = ST_WAIT_BUTTON; + } + break; } - LED_A_ON(); - LED_B_ON(); - if (sniff_wait_for_rnda_reply(tag_type)) { + case ST_WAIT_BUTTON: { + if (welcome_state_button) { + Dbprintf("Pull the tag and Proxmark3 together away from the reader, then press the button."); + welcome_state_button = false; + } + LED_A_ON(); + LED_B_ON(); + blink_led_slow(LED_C); + if (BUTTON_PRESS()) { + state = ST_WAIT_BUTTON_RELEASE; + } + break; + } + case ST_WAIT_BUTTON_RELEASE: { + LED_A_ON(); + LED_B_ON(); + blink_led_slow(LED_C); + if (BUTTON_PRESS() == false) { + state = ST_WRITE_AUTH0; + } + break; + } + case ST_WRITE_AUTH0: { + LED_A_ON(); LED_B_ON(); LED_C_ON(); - DbpString("Card is authenticated!"); - state = ST_WAIT_BUTTON; - } - break; - } - case ST_WAIT_BUTTON: { - if (welcome_state_button) { - Dbprintf("Pull the tag and Proxmark3 together away from the reader, then press the button."); - welcome_state_button = false; - } - LED_A_ON(); - LED_B_ON(); - blink_led_slow(LED_C); - if (BUTTON_PRESS()) { - state = ST_WAIT_BUTTON_RELEASE; - } - break; - } - case ST_WAIT_BUTTON_RELEASE: { - LED_A_ON(); - LED_B_ON(); - blink_led_slow(LED_C); - if (BUTTON_PRESS() == false) { - state = ST_WRITE_AUTH0; - } - break; - } - case ST_WRITE_AUTH0: { - LED_A_ON(); - LED_B_ON(); - LED_C_ON(); - if (write_auth0(tag_type)) { - Dbprintf("AUTH0 written! Press the button to exit."); - LED_D_ON(); - while (!BUTTON_PRESS()) {} - } else { - Dbprintf("AUTH0 write failed. Press the button to exit."); - while (!BUTTON_PRESS()) { - blink_led_fast(LED_D); + if (write_auth0(tag_type)) { + Dbprintf("AUTH0 written! Press the button to exit."); + LED_D_ON(); + while (!BUTTON_PRESS()) {} + } else { + Dbprintf("AUTH0 write failed. Press the button to exit."); + while (!BUTTON_PRESS()) { + blink_led_fast(LED_D); + } } + state = ST_EXIT; + break; } - state = ST_EXIT; - break; - } - case ST_EXIT: - break; - default: - state = ST_LOOK_FOR_CARD; - break; + case ST_EXIT: + break; + default: + state = ST_LOOK_FOR_CARD; + break; } WDT_HIT(); } diff --git a/armsrc/felica.c b/armsrc/felica.c index 69eece61f..5dafdf7d2 100644 --- a/armsrc/felica.c +++ b/armsrc/felica.c @@ -561,7 +561,7 @@ void felica_sendraw(const PacketCommandNG *c) { param = request->flags; len = request->rawlen; payload = request->raw; - + bool do_connect = ((param & FELICA_CONNECT) == FELICA_CONNECT); bool no_disconnect = ((param & FELICA_NO_DISCONNECT) == FELICA_NO_DISCONNECT); diff --git a/client/src/cmdhfmfu.c b/client/src/cmdhfmfu.c index 29590f87a..4d8b8d6da 100644 --- a/client/src/cmdhfmfu.c +++ b/client/src/cmdhfmfu.c @@ -1472,9 +1472,9 @@ static int ulev1_print_counters(uint64_t tagtype, bool use_schann) { if ((tagtype & MFU_TT_UL_AES) != MFU_TT_UL_AES) { ulev1_readTearing(i, tear, sizeof(tear)); PrintAndLogEx(SUCCESS, " - %02X tearing ( %s )" - , tear[0] - , (tear[0] == 0xBD) ? _GREEN_("ok") : _RED_("fail") - ); + , tear[0] + , (tear[0] == 0xBD) ? _GREEN_("ok") : _RED_("fail") + ); } } } diff --git a/client/src/cmdhw.c b/client/src/cmdhw.c index ba3c410bf..66fc1903f 100644 --- a/client/src/cmdhw.c +++ b/client/src/cmdhw.c @@ -52,370 +52,360 @@ 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); } -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); @@ -457,8 +447,7 @@ 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", @@ -475,7 +464,8 @@ 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); @@ -484,8 +474,7 @@ 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; } @@ -495,31 +484,29 @@ 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); - if ((lv0 + lv1 + lv2 + lv3 + lv4) == 1) - { + if ((lv0 + lv1 + lv2 + lv3 + lv4) == 1) { uint8_t dbg = 0; if (lv0) dbg = 0; @@ -538,8 +525,7 @@ 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", @@ -550,7 +536,8 @@ static int CmdDetectReader(const char *Cmd) 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); @@ -560,12 +547,9 @@ 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; } @@ -573,19 +557,15 @@ 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; @@ -596,8 +576,7 @@ 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", @@ -605,7 +584,8 @@ static int CmdFPGAOff(const char *Cmd) void *argtable[] = { arg_param_begin, - arg_param_end}; + arg_param_end + }; CLIExecWithReturn(ctx, Cmd, argtable, true); CLIParserFree(ctx); @@ -614,8 +594,7 @@ 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", @@ -625,7 +604,8 @@ static int CmdLCD(const char *Cmd) arg_param_begin, arg_int1("r", "raw", "", "data "), arg_int1("c", "cnt", "", "number of times to send"), - arg_param_end}; + arg_param_end + }; CLIExecWithReturn(ctx, Cmd, argtable, true); int r_len = 0; @@ -633,22 +613,19 @@ 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", @@ -656,7 +633,8 @@ static int CmdLCDReset(const char *Cmd) void *argtable[] = { arg_param_begin, - arg_param_end}; + arg_param_end + }; CLIExecWithReturn(ctx, Cmd, argtable, true); CLIParserFree(ctx); clearCommandBuffer(); @@ -664,8 +642,7 @@ 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", @@ -679,7 +656,8 @@ 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 @@ -698,8 +676,7 @@ 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; } @@ -709,19 +686,15 @@ static int CmdReadmem(const char *Cmd) 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); } @@ -730,8 +703,7 @@ 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.", @@ -739,7 +711,8 @@ static int CmdReset(const char *Cmd) void *argtable[] = { arg_param_begin, - arg_param_end}; + arg_param_end + }; CLIExecWithReturn(ctx, Cmd, argtable, true); CLIParserFree(ctx); clearCommandBuffer(); @@ -752,8 +725,7 @@ 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", @@ -763,13 +735,13 @@ static int CmdSetDivisor(const char *Cmd) 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; } @@ -780,8 +752,7 @@ static int CmdSetDivisor(const char *Cmd) return PM3_SUCCESS; } -static int CmdSetHFThreshold(const char *Cmd) -{ +static int CmdSetHFThreshold(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hw sethfthresh", @@ -793,11 +764,11 @@ static int CmdSetHFThreshold(const char *Cmd) 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; @@ -808,8 +779,7 @@ 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; } @@ -820,8 +790,7 @@ 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", @@ -834,7 +803,8 @@ 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); @@ -842,15 +812,13 @@ 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; } @@ -871,8 +839,7 @@ 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", @@ -883,11 +850,11 @@ static int CmdStandalone(const char *Cmd) 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]; @@ -896,8 +863,7 @@ 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); @@ -906,8 +872,7 @@ 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", @@ -923,7 +888,8 @@ static int CmdDecay(const char *Cmd) 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); @@ -931,8 +897,7 @@ 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; @@ -941,7 +906,8 @@ 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); @@ -951,14 +917,12 @@ 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; } @@ -978,8 +942,7 @@ 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; } @@ -993,14 +956,13 @@ 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); } @@ -1008,25 +970,20 @@ 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"); } @@ -1037,8 +994,7 @@ 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; @@ -1052,8 +1008,7 @@ 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", @@ -1063,7 +1018,8 @@ static int CmdTune(const char *Cmd) "hw tune"); void *argtable[] = { arg_param_begin, - arg_param_end}; + arg_param_end + }; CLIExecWithReturn(ctx, Cmd, argtable, true); CLIParserFree(ctx); @@ -1092,12 +1048,10 @@ 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; } @@ -1108,8 +1062,7 @@ 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; } @@ -1117,8 +1070,7 @@ 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; @@ -1148,20 +1100,16 @@ 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; } @@ -1170,8 +1118,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)); @@ -1186,22 +1134,19 @@ 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"); } @@ -1224,8 +1169,7 @@ static int CmdTune(const char *Cmd) 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); } @@ -1235,10 +1179,8 @@ 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; @@ -1247,27 +1189,25 @@ 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"); @@ -1281,8 +1221,7 @@ static int CmdTune(const char *Cmd) 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); @@ -1300,11 +1239,9 @@ 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; @@ -1313,7 +1250,8 @@ static int CmdTune(const char *Cmd) .stabilize_ms = 50, .measure_us = 50, .num_pulses = 1, - .padding = {0}}; + .padding = {0} + }; clearCommandBuffer(); SendCommandNG(CMD_HF_DECAY, @@ -1322,17 +1260,15 @@ 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 *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" @@ -1350,14 +1286,12 @@ 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)); @@ -1367,9 +1301,7 @@ static int CmdTune(const char *Cmd) g_MarkerD.pos = LF_DIVISOR_134; ShowGraphWindow(); RepaintGraphWindow(); - } - else - { + } else { PrintAndLogEx(FAILED, "\nAll values are zero. Not showing LF tuning graph\n\n"); } @@ -1379,8 +1311,7 @@ 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", @@ -1388,15 +1319,15 @@ static int CmdVersion(const char *Cmd) 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", @@ -1406,33 +1337,29 @@ static int CmdStatus(const char *Cmd) 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; @@ -1440,14 +1367,12 @@ 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); @@ -1461,14 +1386,12 @@ 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" @@ -1487,7 +1410,8 @@ 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; @@ -1499,8 +1423,7 @@ 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"); @@ -1526,25 +1449,19 @@ 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; } @@ -1552,8 +1469,7 @@ 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; } @@ -1561,8 +1477,7 @@ 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", @@ -1570,7 +1485,8 @@ static int CmdTia(const char *Cmd) void *argtable[] = { arg_param_begin, - arg_param_end}; + arg_param_end + }; CLIExecWithReturn(ctx, Cmd, argtable, true); CLIParserFree(ctx); @@ -1578,8 +1494,7 @@ 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; } @@ -1587,8 +1502,7 @@ 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", @@ -1600,7 +1514,8 @@ static int CmdTimeout(const char *Cmd) 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); @@ -1608,20 +1523,16 @@ 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); @@ -1630,8 +1541,7 @@ 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", @@ -1641,7 +1551,8 @@ static int CmdPing(const char *Cmd) 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); @@ -1650,12 +1561,9 @@ 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"); } @@ -1663,34 +1571,27 @@ 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 )", tms, error ? _RED_("fail") : _GREEN_("ok")); - } - else - { + } else { PrintAndLogEx(SUCCESS, "Ping response " _GREEN_("received") " in " _YELLOW_("%" PRIu64) " ms", tms); } - } - else + } 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", @@ -1703,7 +1604,8 @@ static int CmdConnect(const char *Cmd) 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}; @@ -1712,33 +1614,28 @@ 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; @@ -1746,8 +1643,7 @@ 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", @@ -1756,7 +1652,8 @@ static int CmdBreak(const char *Cmd) void *argtable[] = { arg_param_begin, - arg_param_end}; + arg_param_end + }; CLIExecWithReturn(ctx, Cmd, argtable, true); CLIParserFree(ctx); clearCommandBuffer(); @@ -1764,8 +1661,7 @@ 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", @@ -1774,7 +1670,8 @@ static int CmdBootloader(const char *Cmd) void *argtable[] = { arg_param_begin, - arg_param_end}; + arg_param_end + }; CLIExecWithReturn(ctx, Cmd, argtable, true); CLIParserFree(ctx); clearCommandBuffer(); @@ -1782,23 +1679,19 @@ 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; @@ -1830,17 +1723,16 @@ static command_t CommandTable[] = { {"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}}; + {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); } @@ -1897,24 +1789,20 @@ int CmdHW(const char *Cmd) #define PM3HOSTARCH "unknown" #endif -void pm3_version_short(void) -{ +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; @@ -1925,35 +1813,25 @@ 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, ""); @@ -1965,13 +1843,10 @@ 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; } } @@ -1979,11 +1854,9 @@ 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); } @@ -1991,19 +1864,16 @@ 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"); @@ -2013,21 +1883,18 @@ 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; } @@ -2075,40 +1942,30 @@ 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")); } @@ -2118,30 +1975,24 @@ 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; @@ -2152,26 +2003,21 @@ 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) - { + 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"); diff --git a/client/src/pm3line_vocabulary.h b/client/src/pm3line_vocabulary.h index 857b79afa..e39cff120 100644 --- a/client/src/pm3line_vocabulary.h +++ b/client/src/pm3line_vocabulary.h @@ -587,6 +587,7 @@ const static vocabulary_t vocabulary[] = { { 0, "hw standalone" }, { 0, "hw tia" }, { 0, "hw tune" }, + { 0, "hw decay" }, { 1, "lf help" }, { 0, "lf config" }, { 0, "lf cmdread" }, diff --git a/doc/commands.json b/doc/commands.json index 3b5982d8c..5fb6b564b 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -8722,6 +8722,22 @@ ], "usage": "hw dbg [-h01234]" }, + "hw decay": { + "command": "hw decay", + "description": "Measure HF antenna decay after field-off. Captures how quickly the peak-detect capacitor voltage drops after the 13.56 MHz field is turned off. Different antenna loading (unloaded, booster board, damaged) produces different decay profiles.", + "notes": [ + "hw decay", + "hw decay --ms 100 -> stabilize for 100ms before measurement", + "hw decay --us 5000 -> measure 5ms decay window" + ], + "offline": false, + "options": [ + "-h, --help This help", + "--ms Field stabilization time in ms (default: 50)", + "--us Measurement window in us (default: 2000)" + ], + "usage": "hw decay [-h] [--ms ] [--us ]" + }, "hw fpgaoff": { "command": "hw fpgaoff", "description": "Turn of fpga and antenna field", @@ -13795,8 +13811,8 @@ } }, "metadata": { - "commands_extracted": 790, + "commands_extracted": 791, "extracted_by": "PM3Help2JSON v1.00", - "extracted_on": "2026-02-09T00:12:02" + "extracted_on": "2026-02-21T11:42:25" } } diff --git a/doc/commands.md b/doc/commands.md index 2d0471998..dd90a58ae 100644 --- a/doc/commands.md +++ b/doc/commands.md @@ -878,6 +878,7 @@ Check column "offline" for their availability. |`hw standalone `|N |`Start installed standalone mode on device` |`hw tia `|N |`Trigger a Timing Interval Acquisition to re-adjust the RealTimeCounter divider` |`hw tune `|N |`Measure tuning of device antenna` +|`hw decay `|N |`Measure HF antenna decay after field-off` ### lf diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index c4624cff4..c22453ef4 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -28,19 +28,16 @@ #define PM3_CMD_DATA_SIZE 512 #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 - { + 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. bool ng : 1; @@ -50,21 +47,18 @@ typedef struct #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 - { + union { uint8_t asBytes[PM3_CMD_DATA_SIZE]; uint32_t asDwords[PM3_CMD_DATA_SIZE / 4]; } data; @@ -72,26 +66,22 @@ typedef struct } 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 - { + 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; @@ -103,14 +93,12 @@ typedef struct #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 @@ -118,8 +106,7 @@ typedef struct int8_t reason; // NG uint16_t crc; // NG uint64_t oldarg[3]; // OLD - union - { + union { uint8_t asBytes[PM3_CMD_DATA_SIZE]; uint32_t asDwords[PM3_CMD_DATA_SIZE / 4]; } data; @@ -127,16 +114,14 @@ typedef struct } 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; @@ -148,8 +133,7 @@ typedef struct // 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; @@ -158,8 +142,7 @@ typedef struct } 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; @@ -167,8 +150,7 @@ typedef struct } PACKED iso14a_polling_parameters_t; // A struct used to send hf14a-configs over USB -typedef struct -{ +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 @@ -180,8 +162,7 @@ typedef struct // 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; @@ -190,14 +171,12 @@ 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; @@ -211,8 +190,7 @@ typedef struct #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; @@ -224,14 +202,12 @@ 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; @@ -272,24 +248,21 @@ typedef struct 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; @@ -299,8 +272,7 @@ 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; @@ -309,8 +281,7 @@ 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; @@ -319,8 +290,7 @@ 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; @@ -328,16 +298,14 @@ 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[]; @@ -347,23 +315,20 @@ 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; } 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 @@ -372,8 +337,7 @@ typedef enum MF_WAKE_GDM_ALT, // 20(7)/23 } PACKED MifareWakeupType; -typedef struct -{ +typedef struct { MifareWakeupType wakeup; uint8_t auth_cmd; uint8_t key[6]; @@ -381,8 +345,7 @@ 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]; @@ -391,15 +354,13 @@ 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; @@ -409,13 +370,11 @@ 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; @@ -427,8 +386,7 @@ 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; @@ -437,14 +395,12 @@ 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; @@ -453,8 +409,7 @@ 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]; @@ -463,8 +418,7 @@ 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]; @@ -472,14 +426,12 @@ 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; @@ -487,8 +439,7 @@ 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; @@ -497,8 +448,7 @@ 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)]; @@ -507,14 +457,12 @@ typedef struct //----------------------------------------------------------------------------- // 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), @@ -525,8 +473,7 @@ 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;