mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-02-23 07:37:23 +08:00
lf cmdread: add --crc to add Hitag/ZX8211 CRC
This commit is contained in:
parent
c3864a0ce5
commit
b7ad0c450f
1 changed files with 34 additions and 1 deletions
|
@ -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", "<dec>", "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<cmd_len;i++) {
|
||||
if ((cmd[i] != '0') && (cmd[i] != '1')) {
|
||||
continue;
|
||||
}
|
||||
data <<= 1;
|
||||
data += cmd[i] - '0';
|
||||
n += 1;
|
||||
if (n==8) {
|
||||
crc_update2(&crc, data, n);
|
||||
n = 0;
|
||||
data = 0;
|
||||
}
|
||||
}
|
||||
if (n > 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
|
||||
|
|
Loading…
Reference in a new issue