diff --git a/armsrc/appmain.c b/armsrc/appmain.c index fc07d66f8..ce6d79dbb 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -799,7 +799,8 @@ static void PacketReceived(PacketCommandNG *packet) { // emulator case CMD_SET_DBGMODE: { g_dbglevel = packet->data.asBytes[0]; - print_debug_level(); + if (packet->length == 1 || packet->data.asBytes[1] != 0) + print_debug_level(); reply_ng(CMD_SET_DBGMODE, PM3_SUCCESS, NULL, 0); break; } diff --git a/client/src/cmdhw.c b/client/src/cmdhw.c index b355e66cb..184aa58e8 100644 --- a/client/src/cmdhw.c +++ b/client/src/cmdhw.c @@ -31,6 +31,7 @@ #include "cmdhw.h" #include "cmddata.h" #include "commonutil.h" +#include "preferences.h" #include "pm3_cmd.h" #include "pmflash.h" // rdv40validation_t #include "cmdflashmem.h" // get_signature.. @@ -476,14 +477,9 @@ static int CmdDbg(const char *Cmd) { return PM3_EINVARG; } - clearCommandBuffer(); - SendCommandNG(CMD_GET_DBGMODE, NULL, 0); - PacketResponseNG resp; - if (WaitForResponseTimeout(CMD_GET_DBGMODE, &resp, 2000) == false) { - PrintAndLogEx(WARNING, "Failed to get current device debug level"); - return PM3_ETIMEOUT; - } - uint8_t curr = resp.data.asBytes[0]; + uint8_t curr = DBG_NONE; + if (getDeviceDebugLevel(&curr) != PM3_SUCCESS) + return PM3_EFAILED; const char *dbglvlstr; switch (curr) { @@ -522,8 +518,8 @@ static int CmdDbg(const char *Cmd) { else if (lv4) dbg = 4; - clearCommandBuffer(); - SendCommandNG(CMD_SET_DBGMODE, &dbg, sizeof(dbg)); + if (setDeviceDebugLevel(dbg, true) != PM3_SUCCESS) + return PM3_EFAILED; } return PM3_SUCCESS; } diff --git a/client/src/preferences.c b/client/src/preferences.c index dd697da74..4effb1bef 100644 --- a/client/src/preferences.c +++ b/client/src/preferences.c @@ -762,6 +762,44 @@ static int setCmdDeviceDebug (const char *Cmd) } */ +int getDeviceDebugLevel (uint8_t *debug_level) { + if (!g_session.pm3_present) + return PM3_EFAILED; + + clearCommandBuffer(); + SendCommandNG(CMD_GET_DBGMODE, NULL, 0); + PacketResponseNG resp; + if (WaitForResponseTimeout(CMD_GET_DBGMODE, &resp, 2000) == false) { + PrintAndLogEx(WARNING, "Failed to get current device debug level"); + return PM3_ETIMEOUT; + } + + if (debug_level) + *debug_level = resp.data.asBytes[0]; + + return PM3_SUCCESS; +} + +int setDeviceDebugLevel (uint8_t debug_level, bool verbose) { + if (!g_session.pm3_present) + return PM3_EFAILED; + + if (verbose) + PrintAndLogEx (INFO,"setting device debug loglevel to %u", debug_level); + + uint8_t cdata[] = {debug_level, verbose}; + clearCommandBuffer(); + SendCommandNG(CMD_SET_DBGMODE, cdata, sizeof(cdata)); + PacketResponseNG resp; + if (WaitForResponseTimeout(CMD_SET_DBGMODE, &resp, 2000) == false) { + PrintAndLogEx (WARNING,"failed to set device debug loglevel"); + return PM3_EFAILED; + } + + return PM3_SUCCESS; +} + + static int setCmdOutput(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "prefs set output", diff --git a/client/src/preferences.h b/client/src/preferences.h index 56ba72fa3..74e3bc2a8 100644 --- a/client/src/preferences.h +++ b/client/src/preferences.h @@ -31,4 +31,7 @@ int preferences_save(void); void preferences_save_callback(json_t *root); void preferences_load_callback(json_t *root); +int getDeviceDebugLevel (uint8_t *debug_level); +int setDeviceDebugLevel (uint8_t debug_level, bool verbose); + #endif