From b35ea2e352cc15075670eafb2718488e76f19589 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 13 Mar 2019 16:44:32 +0100 Subject: [PATCH] chg: 'lf hitag writer' - refactored with timeouts etc. chg: 'lf hitag' test without toggle mode enabled --- armsrc/hitag2.c | 3 ++- client/amiitool/amiitool.c | 2 +- client/cmdlfhitag.c | 51 ++++++++++++++++++++++---------------- 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/armsrc/hitag2.c b/armsrc/hitag2.c index d474cf895..4abc99e10 100644 --- a/armsrc/hitag2.c +++ b/armsrc/hitag2.c @@ -705,7 +705,8 @@ void SniffHitag(uint32_t type) { // Set up eavesdropping mode, frequency divisor which will drive the FPGA // and analog mux selection. - FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT | FPGA_LF_EDGE_DETECT_TOGGLE_MODE); + //FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT | FPGA_LF_EDGE_DETECT_TOGGLE_MODE); + FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT); //125Khz FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); diff --git a/client/amiitool/amiitool.c b/client/amiitool/amiitool.c index a687cb0b1..78c8f4d1e 100644 --- a/client/amiitool/amiitool.c +++ b/client/amiitool/amiitool.c @@ -8,7 +8,7 @@ #include #include #include -#include "../loclass/fileutil.h" +#include "../loclass/fileutils.h" #define NTAG215_SIZE 540 diff --git a/client/cmdlfhitag.c b/client/cmdlfhitag.c index 2907fd861..5a245a345 100644 --- a/client/cmdlfhitag.c +++ b/client/cmdlfhitag.c @@ -30,6 +30,7 @@ size_t nbytes(size_t nbits) { } int usage_hitag_reader(void) { + PrintAndLogEx(NORMAL, "Hitag reader functions"); PrintAndLogEx(NORMAL, "Usage: lf hitag reader [h] "); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h This help"); @@ -45,6 +46,19 @@ int usage_hitag_reader(void) { PrintAndLogEx(NORMAL, " 26 Just read UID"); return 0; } +int usage_hitag_writer(void) { + PrintAndLogEx(NORMAL, "Hitag writer functions"); + PrintAndLogEx(NORMAL, "Usage: lf hitag write [h] "); + PrintAndLogEx(NORMAL, "Options:"); + PrintAndLogEx(NORMAL, " h This help"); + PrintAndLogEx(NORMAL, " HitagS (0*)"); + PrintAndLogEx(NORMAL, " 03 (Challenge) write page on a Hitag S tag"); + PrintAndLogEx(NORMAL, " 04 (set to 0 if no authentication is needed) write page on a Hitag S tag"); + PrintAndLogEx(NORMAL, " Hitag1 (1*)"); + PrintAndLogEx(NORMAL, " Hitag2 (2*)"); + PrintAndLogEx(NORMAL, " 24 (set to 0 if no authentication is needed) write page on a Hitag2 tag"); + return 0; +} int CmdLFHitagList(const char *Cmd) { uint8_t *got = calloc(USB_CMD_DATA_SIZE, sizeof(uint8_t)); @@ -256,7 +270,6 @@ int CmdLFHitagReader(const char *Cmd) { break; } default: { - PrintAndLogEx(NORMAL, "\nError: unkown reader function %d", htf); return usage_hitag_reader(); } } @@ -368,44 +381,40 @@ int CmdLFHitagWP(const char *Cmd) { UsbCommand c = { CMD_WR_HITAG_S }; hitag_data *htd = (hitag_data *)c.d.asBytes; hitag_function htf = param_get32ex(Cmd, 0, 0, 10); + switch (htf) { - case 03: { //WHTSF_CHALLENGE + case WHTSF_CHALLENGE: { num_to_bytes(param_get64ex(Cmd, 1, 0, 16), 8, htd->auth.NrAr); c.arg[2] = param_get32ex(Cmd, 2, 0, 10); num_to_bytes(param_get32ex(Cmd, 3, 0, 16), 4, htd->auth.data); + break; } - break; - case 04: - case 24: { - //WHTSF_KEY + case WHTSF_KEY: + case WHT2F_CRYPTO: { num_to_bytes(param_get64ex(Cmd, 1, 0, 16), 6, htd->crypto.key); c.arg[2] = param_get32ex(Cmd, 2, 0, 10); num_to_bytes(param_get32ex(Cmd, 3, 0, 16), 4, htd->crypto.data); - + break; } - break; default: { - PrintAndLogEx(WARNING, "Error: unkown writer function %d", htf); - PrintAndLogEx(NORMAL, "Hitag writer functions"); - PrintAndLogEx(NORMAL, " HitagS (0*)"); - PrintAndLogEx(NORMAL, " 03 (Challenge) write page on a Hitag S tag"); - PrintAndLogEx(NORMAL, " 04 (set to 0 if no authentication is needed) write page on a Hitag S tag"); - PrintAndLogEx(NORMAL, " Hitag1 (1*)"); - PrintAndLogEx(NORMAL, " Hitag2 (2*)"); - return 1; + return usage_hitag_writer(); } - break; } - // Copy the hitag function into the first argument + c.arg[0] = htf; clearCommandBuffer(); SendCommand(&c); UsbCommand resp; - WaitForResponse(CMD_ACK, &resp); + if (!WaitForResponseTimeout(CMD_ACK, &resp, 4000)) { + PrintAndLogEx(WARNING, "timeout while waiting for reply."); + return 1; + } - // Check the return status, stored in the first argument - if (resp.arg[0] == false) return 1; + if (resp.arg[0] == false) { + PrintAndLogEx(DEBUG, "DEBUG: Error - hitag failed"); + return 1; + } return 0; }