set debug log level

This commit is contained in:
merlokk 2023-12-11 18:46:25 +02:00
commit ebe9d72cc2
4 changed files with 49 additions and 11 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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",

View file

@ -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