From 2fcd46f2786d30507b0bb1d8823a15151e50637a Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 29 Nov 2020 14:00:51 +0100 Subject: [PATCH] lf ti write - now uses NG, cliparser (untested) --- armsrc/appmain.c | 8 ++++++- armsrc/lfops.c | 2 +- client/src/cmdlfidteck.c | 8 +++---- client/src/cmdlfti.c | 46 ++++++++++++++++++++++++++++++---------- 4 files changed, 47 insertions(+), 17 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index f43de6f47..8be0c9ab9 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -907,7 +907,13 @@ static void PacketReceived(PacketCommandNG *packet) { break; } case CMD_LF_TI_WRITE: { - WriteTItag(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2]); + struct p { + uint32_t high; + uint32_t low; + uint16_t crc; + } PACKED; + struct p *payload = (struct p *)packet->data.asBytes; + WriteTItag(payload->high, payload->low, packet->crc); break; } case CMD_LF_SIMULATE: { diff --git a/armsrc/lfops.c b/armsrc/lfops.c index 0d578295f..2bd5dc279 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -803,7 +803,7 @@ void WriteTItag(uint32_t idhi, uint32_t idlo, uint16_t crc) { AcquireTiType(); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); - DbpString("Now use `lf ti read` to check"); + DbpString("Now use `lf ti reader` to check"); StopTicks(); } diff --git a/client/src/cmdlfidteck.c b/client/src/cmdlfidteck.c index 3f61f0eb4..076f3fc8e 100644 --- a/client/src/cmdlfidteck.c +++ b/client/src/cmdlfidteck.c @@ -101,7 +101,7 @@ static int CmdIdteckDemod(const char *Cmd) { return demodIdteck(true); } -static int CmdIdteckRead(const char *Cmd) { +static int CmdIdteckReader(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "lf idteck reader", "read a Idteck tag", @@ -126,9 +126,9 @@ static int CmdIdteckRead(const char *Cmd) { } static command_t CommandTable[] = { - {"help", CmdHelp, AlwaysAvailable, "This help"}, - {"demod", CmdIdteckDemod, AlwaysAvailable, "Demodulate an Idteck tag from the GraphBuffer"}, - {"read", CmdIdteckRead, IfPm3Lf, "Attempt to read and Extract tag data from the antenna"}, + {"help", CmdHelp, AlwaysAvailable, "This help"}, + {"demod", CmdIdteckDemod, AlwaysAvailable, "Demodulate an Idteck tag from the GraphBuffer"}, + {"reader", CmdIdteckReader, IfPm3Lf, "Attempt to read and Extract tag data from the antenna"}, {NULL, NULL, NULL, NULL} }; diff --git a/client/src/cmdlfti.c b/client/src/cmdlfti.c index 9a8b3847f..f6e8b3027 100644 --- a/client/src/cmdlfti.c +++ b/client/src/cmdlfti.c @@ -314,19 +314,43 @@ static int CmdTIReader(const char *Cmd) { // write new data to a r/w TI tag static int CmdTIWrite(const char *Cmd) { - int res = 0; - uint64_t arg0, arg1, arg2; - res = sscanf(Cmd, "%012" SCNx64 " %012" SCNx64 " %012" SCNx64 "", &arg0, &arg1, &arg2); - if (res == 2) - arg2 = 0; + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf ti write", + "write to a r/w TI tag.", + "lf ti write --raw 1122334455667788\n" + "lf ti write --raw 1122334455667788 --crc 1122\n" + ); + + void *argtable[] = { + arg_param_begin, + arg_str1("r", "raw", "", "raw hex data. 8 bytes max"), + arg_str0(NULL, "crc", "", "optional - crc"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); + + int raw_len = 0; + uint8_t raw[8] = {0}; + CLIGetHexWithReturn(ctx, 1, raw, &raw_len); + + int crc_len = 0; + uint8_t crc[2] = {0}; + CLIGetHexWithReturn(ctx, 2, crc, &crc_len); + CLIParserFree(ctx); + + struct { + uint32_t high; + uint32_t low; + uint16_t crc; + } PACKED payload; + + payload.high = bytes_to_num(raw, 4); + payload.low = bytes_to_num(raw + 4, 4); + payload.crc = bytes_to_num(crc, crc_len); - if (res < 2) { - PrintAndLogEx(WARNING, "Please specify the data as two hex strings, optionally the CRC as a third"); - return PM3_EINVARG; - } clearCommandBuffer(); - SendCommandMIX(CMD_LF_TI_WRITE, arg0, arg1, arg2, NULL, 0); + SendCommandNG(CMD_LF_TI_WRITE, (uint8_t*)&payload, sizeof(payload)); PrintAndLogEx(SUCCESS, "Done"); PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`lf ti reader`") " to verify"); return PM3_SUCCESS; @@ -334,7 +358,7 @@ static int CmdTIWrite(const char *Cmd) { static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, - {"demod", CmdTIDemod, AlwaysAvailable, "Demodulate raw bits for TI-type LF tag from the GraphBuffer"}, + {"demod", CmdTIDemod, AlwaysAvailable, "Demodulate raw bits for TI LF tag from the GraphBuffer"}, {"reader", CmdTIReader, IfPm3Lf, "Read and decode a TI 134 kHz tag"}, {"write", CmdTIWrite, IfPm3Lf, "Write new data to a r/w TI 134 kHz tag"}, {NULL, NULL, NULL, NULL}