Skip to content

Commit 11fe8f7

Browse files
committed
Add --skip to hw tearoff, to cope with more complex commands. Example provided for hf mfu wrbl
1 parent 1d55a2d commit 11fe8f7

File tree

4 files changed

+39
-10
lines changed

4 files changed

+39
-10
lines changed

armsrc/appmain.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ static int button_status = BUTTON_NO_CLICK;
9494
static bool allow_send_wtx = false;
9595
uint16_t g_tearoff_delay_us = 0;
9696
bool g_tearoff_enabled = false;
97+
uint8_t g_tearoff_skip = 0;
9798

9899
int tearoff_hook(void) {
99100
if (g_tearoff_enabled) {
@@ -102,6 +103,11 @@ int tearoff_hook(void) {
102103
g_tearoff_enabled = false;
103104
return PM3_SUCCESS; // SUCCESS = the hook didn't do anything
104105
}
106+
if (g_tearoff_skip > 0) {
107+
Dbprintf(_GREEN_("Tear-off skipped!"));
108+
g_tearoff_skip--;
109+
return PM3_SUCCESS; // SUCCESS = the hook didn't do anything
110+
}
105111
SpinDelayUsPrecision(g_tearoff_delay_us);
106112
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
107113
g_tearoff_enabled = false;
@@ -882,12 +888,7 @@ static void PacketReceived(PacketCommandNG *packet) {
882888
break;
883889
}
884890
case CMD_SET_TEAROFF: {
885-
struct p {
886-
uint16_t delay_us;
887-
bool on;
888-
bool off;
889-
} PACKED;
890-
struct p *payload = (struct p *)packet->data.asBytes;
891+
tearoff_params_t *payload = (tearoff_params_t *)packet->data.asBytes;
891892
if (payload->on && payload->off) {
892893
reply_ng(CMD_SET_TEAROFF, PM3_EINVARG, NULL, 0);
893894
}
@@ -903,6 +904,10 @@ static void PacketReceived(PacketCommandNG *packet) {
903904
if (payload->delay_us > 0) {
904905
g_tearoff_delay_us = payload->delay_us;
905906
}
907+
908+
if (payload->skip > -1) {
909+
g_tearoff_skip = payload->skip;
910+
}
906911
reply_ng(CMD_SET_TEAROFF, PM3_SUCCESS, NULL, 0);
907912
break;
908913
}

armsrc/mifareutil.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ uint16_t mifare_sendcmd(uint8_t cmd, uint8_t *data, uint8_t data_size, uint8_t *
8787

8888
AddCrc14A(dcmd, data_size + 1);
8989
ReaderTransmit(dcmd, sizeof(dcmd), timing);
90+
if (tearoff_hook() == PM3_ETEAROFF) { // tearoff occurred
91+
return 0;
92+
}
9093
uint16_t len = ReaderReceive(answer, answer_len, answer_parity);
9194
if (len == 0) {
9295
if (g_dbglevel >= DBG_ERROR) Dbprintf("%02X Cmd failed. Card timeout.", cmd);
@@ -114,6 +117,9 @@ uint16_t mifare_sendcmd_short(struct Crypto1State *pcs, uint8_t crypted, uint8_t
114117
} else {
115118
ReaderTransmit(dcmd, sizeof(dcmd), timing);
116119
}
120+
if (tearoff_hook() == PM3_ETEAROFF) { // tearoff occurred
121+
return 0;
122+
}
117123

118124
uint16_t len = ReaderReceive(answer, answer_len, par);
119125

client/src/cmdhw.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,11 @@ int handle_tearoff(tearoff_params_t *params, bool verbose) {
11741174
if (params->delay_us > 0 && verbose)
11751175
PrintAndLogEx(INFO, "Tear-off hook configured with delay of " _GREEN_("%i us"), params->delay_us);
11761176

1177+
if (params->skip > 0 && verbose)
1178+
PrintAndLogEx(INFO, "Tear-off hook will be skipped " _YELLOW_("%i times") " before being activated", params->skip);
1179+
if (params->skip == 0 && verbose)
1180+
PrintAndLogEx(INFO, "Tear-off hook skipping " _GREEN_("disabled"));
1181+
11771182
if (params->on && verbose)
11781183
PrintAndLogEx(INFO, "Tear-off hook " _GREEN_("enabled"));
11791184

@@ -1201,6 +1206,7 @@ static int CmdTearoff(const char *Cmd) {
12011206
arg_int0(NULL, "delay", "<dec>", "Delay in us before triggering tear-off, must be between 1 and 43000"),
12021207
arg_lit0(NULL, "on", "Activate tear-off hook"),
12031208
arg_lit0(NULL, "off", "Deactivate tear-off hook"),
1209+
arg_int0(NULL, "skip", "<dec>", "Skip N triggers before activating the hook"),
12041210
arg_lit0("s", "silent", "less verbose output"),
12051211
arg_lit0(NULL, "list", "List commands implementing tear-off hooks"),
12061212
arg_param_end
@@ -1211,8 +1217,9 @@ static int CmdTearoff(const char *Cmd) {
12111217
int delay = arg_get_int_def(ctx, 1, -1);
12121218
params.on = arg_get_lit(ctx, 2);
12131219
params.off = arg_get_lit(ctx, 3);
1214-
bool silent = arg_get_lit(ctx, 4);
1215-
bool list = arg_get_lit(ctx, 5);
1220+
int skip = arg_get_int_def(ctx, 4, -1);
1221+
bool silent = arg_get_lit(ctx, 5);
1222+
bool list = arg_get_lit(ctx, 6);
12161223
CLIParserFree(ctx);
12171224

12181225
if (list) {
@@ -1223,8 +1230,8 @@ static int CmdTearoff(const char *Cmd) {
12231230
PrintAndLogEx(INFO, " hf 15 raw");
12241231
PrintAndLogEx(INFO, " hf iclass creditepurse");
12251232
PrintAndLogEx(INFO, " hf iclass wrbl");
1226-
PrintAndLogEx(INFO, " hf mfc wrbl");
1227-
// PrintAndLogEx(INFO, " hf mfu wrbl");
1233+
PrintAndLogEx(INFO, " hf mf wrbl");
1234+
PrintAndLogEx(INFO, " hf mfu wrbl (with --skip 3)");
12281235
PrintAndLogEx(INFO, " hf topaz wrbl");
12291236
PrintAndLogEx(INFO, " lf em 4x05 write");
12301237
PrintAndLogEx(INFO, " lf em 4x50 wrbl");
@@ -1251,6 +1258,16 @@ static int CmdTearoff(const char *Cmd) {
12511258
}
12521259

12531260
params.delay_us = delay;
1261+
1262+
if (skip != -1) {
1263+
if ((skip < 0) || (skip > 127)) {
1264+
PrintAndLogEx(WARNING, "You can't set skip out of 0..127 range!");
1265+
return PM3_EINVARG;
1266+
}
1267+
}
1268+
1269+
params.skip = skip;
1270+
12541271
if (params.on && params.off) {
12551272
PrintAndLogEx(WARNING, "You can't set both --on and --off!");
12561273
return PM3_EINVARG;

include/pm3_cmd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ typedef struct {
371371

372372
typedef struct {
373373
uint16_t delay_us;
374+
int8_t skip;
374375
bool on;
375376
bool off;
376377
} PACKED tearoff_params_t;

0 commit comments

Comments
 (0)