Update em4x70 info to use cliparser

This commit is contained in:
Christian Molson 2020-12-09 16:22:52 -05:00
commit 76bf80a8dd

View file

@ -11,29 +11,14 @@
#include "cmdlfem4x70.h" #include "cmdlfem4x70.h"
#include <ctype.h> #include <ctype.h>
#include "cmdparser.h" // command_t #include "cmdparser.h" // command_t
#include "cliparser.h"
#include "fileutils.h" #include "fileutils.h"
#include "comms.h"
#include "commonutil.h" #include "commonutil.h"
#include "em4x70.h" #include "em4x70.h"
static int CmdHelp(const char *Cmd); static int CmdHelp(const char *Cmd);
static int usage_lf_em4x70_info(void) {
PrintAndLogEx(NORMAL, "Read all information of EM4x70. Tag must be on antenna.");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: lf em 4x70_info [h] [v] [p <pwd>]");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h - this help");
PrintAndLogEx(NORMAL, " p - use even parity for commands");
PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x70_info"));
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x70_info p"));
PrintAndLogEx(NORMAL, "");
return PM3_SUCCESS;
}
static void print_info_result(uint8_t *data) { static void print_info_result(uint8_t *data) {
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
@ -88,32 +73,28 @@ int CmdEM4x70Info(const char *Cmd) {
// envoke reading of a EM4x70 tag which has to be on the antenna because // envoke reading of a EM4x70 tag which has to be on the antenna because
// decoding is done by the device (not on client side) // decoding is done by the device (not on client side)
bool errors = false;
uint8_t cmdp = 0;
em4x70_data_t etd = {0}; em4x70_data_t etd = {0};
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { CLIParserContext *ctx;
switch (tolower(param_getchar(Cmd, cmdp))) {
case 'h': CLIParserInit(&ctx, "lf em 4x10 info",
return usage_lf_em4x70_info(); "Tag Information EM4x70\n"
" Tag variants include ID48 automotive transponder.\n"
case 'p': " ID48 does not use command parity (default).\n"
etd.parity = true; " V4070 and EM4170 do require parity bit.",
cmdp +=1; "lf em 4x70 info\n"
break; "lf em 4x70 -p -> adds parity bit to commands\n"
);
default: void *argtable[] = {
PrintAndLogEx(WARNING, " Unknown parameter '%c'", param_getchar(Cmd, cmdp)); arg_param_begin,
errors = true; arg_lit0("p", "parity", "Add parity bit when sending commands"),
break; arg_param_end
} };
}
// validation CLIExecWithReturn(ctx, Cmd, argtable, true);
if (errors) etd.parity = arg_get_lit(ctx, 0);
return usage_lf_em4x70_info(); CLIParserFree(ctx);
clearCommandBuffer(); clearCommandBuffer();
SendCommandNG(CMD_LF_EM4X70_INFO, (uint8_t *)&etd, sizeof(etd)); SendCommandNG(CMD_LF_EM4X70_INFO, (uint8_t *)&etd, sizeof(etd));