lf t55xx resetread - now uses cliparser

This commit is contained in:
iceman1001 2021-03-07 15:08:38 +01:00
commit 964aee329f

View file

@ -147,17 +147,7 @@ static int usage_t55xx_read(void) {
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
return PM3_SUCCESS; return PM3_SUCCESS;
} }
static int usage_t55xx_resetread(void) {
PrintAndLogEx(NORMAL, "Send Reset Cmd then lf read the stream to attempt to identify the start of it (needs a demod and/or plot after)");
PrintAndLogEx(NORMAL, "Usage: lf t55xx resetread [r <mode>]");
PrintAndLogEx(NORMAL, "Options:");
print_usage_t55xx_downloadlink(T55XX_DLMODE_SINGLE, config.downlink_mode);
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, _YELLOW_(" lf t55xx resetread"));
PrintAndLogEx(NORMAL, "");
return PM3_SUCCESS;
}
static int usage_t55xx_write(void) { static int usage_t55xx_write(void) {
PrintAndLogEx(NORMAL, "Usage: lf t55xx write [r <mode>] b <block> d <data> [p <password>] [1] [t] [v]"); PrintAndLogEx(NORMAL, "Usage: lf t55xx write [r <mode>] b <block> d <data> [p <password>] [1] [t] [v]");
PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, "Options:");
@ -2818,38 +2808,51 @@ static void t55x7_create_config_block(int tagtype) {
static int CmdResetRead(const char *Cmd) { static int CmdResetRead(const char *Cmd) {
uint8_t downlink_mode = config.downlink_mode; CLIParserContext *ctx;
uint8_t flags = 0; CLIParserInit(&ctx, "lf t55xx resetread",
uint8_t cmdp = 0; "Send Reset Cmd then `lf read` the stream to attempt\n"
bool errors = false; "to identify the start of it (needs a demod and/or plot after)",
"lf t55xx resetread"
);
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { // 1 (help) + 0(one user specified params) + (5 T55XX_DLMODE_SINGLE)
switch (tolower(param_getchar(Cmd, cmdp))) { void *argtable[0 + 5] = {
case 'h': arg_param_begin,
return usage_t55xx_resetread(); arg_lit0("1", NULL, "extract using data from graphbuffer"),
case 'r': };
downlink_mode = param_get8ex(Cmd, cmdp + 1, 0, 10); uint8_t idx = 1;
if (downlink_mode > 3) arg_add_t55xx_downloadlink(argtable, &idx, T55XX_DLMODE_SINGLE, config.downlink_mode);
downlink_mode = 0; CLIExecWithReturn(ctx, Cmd, argtable, true);
cmdp += 2; bool r0 = arg_get_lit(ctx, 1);
break; bool r1 = arg_get_lit(ctx, 2);
default: bool r2 = arg_get_lit(ctx, 3);
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); bool r3 = arg_get_lit(ctx, 4);
errors = true; CLIParserFree(ctx);
break;
} if ((r0 + r1 + r2 + r3) > 1) {
PrintAndLogEx(FAILED, "Error multiple downlink encoding");
return PM3_EINVARG;
} }
if (errors) return usage_t55xx_resetread(); uint8_t downlink_mode = config.downlink_mode;
if (r0)
downlink_mode = refFixedBit;
else if (r1)
downlink_mode = refLongLeading;
else if (r2)
downlink_mode = refLeading0;
else if (r3)
downlink_mode = ref1of4;
flags = downlink_mode << 3; uint8_t flags = downlink_mode << 3;
PrintAndLogEx(INFO, "Sending reset command...");
PacketResponseNG resp; PacketResponseNG resp;
clearCommandBuffer(); clearCommandBuffer();
SendCommandNG(CMD_LF_T55XX_RESET_READ, &flags, sizeof(flags)); SendCommandNG(CMD_LF_T55XX_RESET_READ, &flags, sizeof(flags));
if (!WaitForResponseTimeout(CMD_LF_T55XX_RESET_READ, &resp, 2500)) { if (WaitForResponseTimeout(CMD_LF_T55XX_RESET_READ, &resp, 2500) == false) {
PrintAndLogEx(WARNING, "command execution time out"); PrintAndLogEx(WARNING, "command execution time out");
return PM3_ETIMEOUT; return PM3_ETIMEOUT;
} }
@ -2863,6 +2866,7 @@ static int CmdResetRead(const char *Cmd) {
return PM3_EMALLOC; return PM3_EMALLOC;
} }
PrintAndLogEx(INFO, "Downloading samples...");
if (!GetFromDevice(BIG_BUF, got, gotsize, 0, NULL, 0, NULL, 2500, false)) { if (!GetFromDevice(BIG_BUF, got, gotsize, 0, NULL, 0, NULL, 2500, false)) {
PrintAndLogEx(WARNING, "command execution time out"); PrintAndLogEx(WARNING, "command execution time out");
free(got); free(got);
@ -2871,6 +2875,8 @@ static int CmdResetRead(const char *Cmd) {
setGraphBuf(got, gotsize); setGraphBuf(got, gotsize);
free(got); free(got);
} }
PrintAndLogEx(INFO, "Done");
return PM3_SUCCESS; return PM3_SUCCESS;
} }