From 983c3a3a637a1d493d69ffa1b93d3eedf4a4b077 Mon Sep 17 00:00:00 2001 From: mwalker33 <51802811+mwalker33@users.noreply.github.com> Date: Sun, 8 Nov 2020 21:03:33 +1100 Subject: [PATCH] Detect with wakeup Detect with wake option to address init deley or AOR set. --- client/src/cmdlft55xx.c | 88 ++++++++++++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 23 deletions(-) diff --git a/client/src/cmdlft55xx.c b/client/src/cmdlft55xx.c index ab1a86fbd..e34d14718 100644 --- a/client/src/cmdlft55xx.c +++ b/client/src/cmdlft55xx.c @@ -1024,6 +1024,9 @@ static void T55xx_Print_DownlinkMode(uint8_t downlink_mode) { PrintAndLogEx(NORMAL, msg); } +// Define prototype to call from within detect. +static int CmdT55xxWakeUp (const char *Cmd); + static int CmdT55xxDetect(const char *Cmd) { bool errors = false; @@ -1032,9 +1035,16 @@ static int CmdT55xxDetect(const char *Cmd) { bool try_with_pwd = false; bool try_all_dl_modes = true; bool found = false; + bool usewake = false; uint64_t password = -1; uint8_t cmdp = 0; uint8_t downlink_mode = 0; + char wakecmd[20] = { 0x00 }; + struct timespec sleepperiod; + + // Setup the 90ms time value to sleep for after the wake, to allow delay init to complete (~70ms) + sleepperiod.tv_sec = 0; + sleepperiod.tv_nsec = 90000000; while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { switch (tolower(param_getchar(Cmd, cmdp))) { @@ -1042,6 +1052,7 @@ static int CmdT55xxDetect(const char *Cmd) { return usage_t55xx_detect(); case 'p': password = param_get32ex(Cmd, cmdp + 1, 0, 16); + sprintf (wakecmd,"p %08x q",(uint32_t)(password & 0xFFFFFFFF)); usepwd = true; cmdp += 2; break; @@ -1064,6 +1075,7 @@ static int CmdT55xxDetect(const char *Cmd) { } if (errors) return usage_t55xx_detect(); + // detect called so clear data blocks T55x7_ClearAllBlockData(); @@ -1072,38 +1084,61 @@ static int CmdT55xxDetect(const char *Cmd) { return PM3_ESOFT; if (useGB == false) { - // do ... while to check without password then loop back if password supplied + // do ... while not found and not yet tried with wake (for AOR or Init Delay) do { + // do ... while to check without password then loop back if password supplied + do { - if (try_all_dl_modes) { - for (uint8_t m = downlink_mode; m < 4; m++) { + if (try_all_dl_modes) { + for (uint8_t m = downlink_mode; m < 4; m++) { + if (usewake) { + // call wake + if (try_with_pwd) + CmdT55xxWakeUp (wakecmd); + else + CmdT55xxWakeUp ("q"); + // sleep 90 ms + nanosleep (&sleepperiod, &sleepperiod); + } - if (AcquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, (try_with_pwd && usepwd), password, m) == false) - continue; + if (AcquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, (try_with_pwd && usepwd), password, m) == false) + continue; - if (t55xxTryDetectModulationEx(m, T55XX_PrintConfig, 0, (try_with_pwd && usepwd) ? password : -1) == false) - continue; + if (t55xxTryDetectModulationEx(m, T55XX_PrintConfig, 0, (try_with_pwd && usepwd) ? password : -1) == false) + continue; - found = true; + found = true; - break; + break; + } + } else { + if (usewake) { + // call wake + if (try_with_pwd) + CmdT55xxWakeUp (wakecmd); + else + CmdT55xxWakeUp ("q"); + // sleep 90 ms + nanosleep (&sleepperiod, &sleepperiod); + } + + if (AcquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, usepwd, password, downlink_mode)) { + found = t55xxTryDetectModulationEx(downlink_mode, T55XX_PrintConfig, 0, (usepwd) ? password : -1); + } } - } else { - if (AcquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, usepwd, password, downlink_mode)) { - found = t55xxTryDetectModulationEx(downlink_mode, T55XX_PrintConfig, 0, (usepwd) ? password : -1); - } - } - // toggle so we loop back if not found and try with pwd - if (!found && usepwd) - try_with_pwd = !try_with_pwd; + // toggle so we loop back if not found and try with pwd + if (!found && usepwd) + try_with_pwd = !try_with_pwd; - // force exit as detect block has been found - if (found) - try_with_pwd = false; - - } while (try_with_pwd); + // force exit as detect block has been found + if (found) + try_with_pwd = false; + } while (try_with_pwd); + // Toggle so we loop back and try with wakeup. + usewake = !usewake; + } while (!found && usewake); } else { found = t55xxTryDetectModulation(downlink_mode, T55XX_PrintConfig); } @@ -1619,6 +1654,7 @@ static int CmdT55xxWakeUp(const char *Cmd) { uint8_t cmdp = 0; bool errors = false; uint8_t downlink_mode = config.downlink_mode; + bool quiet = false; while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { switch (tolower(param_getchar(Cmd, cmdp))) { @@ -1635,6 +1671,10 @@ static int CmdT55xxWakeUp(const char *Cmd) { cmdp += 2; break; + case 'q': + quiet = true; + cmdp++; + break; default: PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); errors = true; @@ -1659,7 +1699,9 @@ static int CmdT55xxWakeUp(const char *Cmd) { return PM3_ETIMEOUT; } - PrintAndLogEx(SUCCESS, "Wake up command sent. Try read now"); + if (!quiet) + PrintAndLogEx(SUCCESS, "Wake up command sent. Try read now"); + return PM3_SUCCESS; }