diff --git a/client/src/cmdlf.c b/client/src/cmdlf.c index bcdf78ef0..c9a8c24e1 100644 --- a/client/src/cmdlf.c +++ b/client/src/cmdlf.c @@ -58,6 +58,7 @@ #include "cmdlfti.h" // for ti menu #include "cmdlfviking.h" // for viking menu #include "cmdlfvisa2000.h" // for VISA2000 menu +#include "crc.h" #include "pm3_cmd.h" // for LF_CMDREAD_MAX_EXTRA_SYMBOLS static bool gs_lf_threshold_set = false; @@ -232,6 +233,7 @@ int CmdLFCommandRead(const char *Cmd) { arg_u64_0("s", "samples", "", "number of samples to collect"), arg_lit0("v", "verbose", "verbose output"), arg_lit0("k", "keep", "keep signal field ON after receive"), + arg_lit0(NULL, "crc", "calculate and append CRC-8 Hitag/ZX8211"), arg_lit0("@", NULL, "continuous mode"), arg_param_end }; @@ -251,7 +253,8 @@ int CmdLFCommandRead(const char *Cmd) { uint32_t samples = arg_get_u32_def(ctx, 6, 0); bool verbose = arg_get_lit(ctx, 7); bool keep_field_on = arg_get_lit(ctx, 8); - bool cm = arg_get_lit(ctx, 9); + bool add_crc = arg_get_lit(ctx, 9); + bool cm = arg_get_lit(ctx, 10); CLIParserFree(ctx); if (g_session.pm3_present == false) @@ -275,6 +278,36 @@ int CmdLFCommandRead(const char *Cmd) { payload.samples = samples; payload.keep_field_on = keep_field_on; payload.verbose = verbose; + + if (add_crc && (cmd_len <= 120)) { + crc_t crc; + uint8_t data = 0; + uint8_t n = 0; + crc_init_ref(&crc, 8, 0x1d, 0xff, 0, false, false); + uint8_t i; + for (i=0;i 0) { + crc_update2(&crc, data, n); + } + uint8_t crc_final = crc_finish(&crc); + for (int j=7; j>=0; j--) { + cmd[cmd_len] = ((crc_final >> j) & 1) ? '1' : '0'; + cmd_len++; + } + } + memcpy(payload.data, cmd, cmd_len); // extra symbol definition