Add generic tear-off hook
This commit is contained in:
@@ -68,6 +68,24 @@ extern uint32_t _stack_start, _stack_end;
|
||||
struct common_area common_area __attribute__((section(".commonarea")));
|
||||
static int button_status = BUTTON_NO_CLICK;
|
||||
static bool allow_send_wtx = false;
|
||||
static uint32_t tearoff_delay_us = 0;
|
||||
static bool tearoff_enabled = false;
|
||||
|
||||
int tearoff_hook(void) {
|
||||
if (tearoff_enabled) {
|
||||
if (tearoff_delay_us == 0) {
|
||||
Dbprintf(_RED_("No tear-off delay configured!"));
|
||||
return PM3_SUCCESS; // SUCCESS = the hook didn't do anything
|
||||
}
|
||||
WaitUS(tearoff_delay_us);
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
tearoff_enabled = false;
|
||||
Dbprintf(_YELLOW_("Tear-off triggered!"));
|
||||
return PM3_ETEAROFF;
|
||||
} else {
|
||||
return PM3_SUCCESS; // SUCCESS = the hook didn't do anything
|
||||
}
|
||||
}
|
||||
|
||||
void send_wtx(uint16_t wtx) {
|
||||
if (allow_send_wtx) {
|
||||
@@ -731,6 +749,24 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
reply_ng(CMD_SET_DBGMODE, PM3_SUCCESS, NULL, 0);
|
||||
break;
|
||||
}
|
||||
case CMD_SET_TEAROFF: {
|
||||
struct p {
|
||||
uint32_t delay_us;
|
||||
bool on;
|
||||
bool off;
|
||||
} PACKED;
|
||||
struct p *payload = (struct p *)packet->data.asBytes;
|
||||
if (payload->on && payload->off)
|
||||
reply_ng(CMD_SET_TEAROFF, PM3_EINVARG, NULL, 0);
|
||||
if (payload->on)
|
||||
tearoff_enabled = true;
|
||||
if (payload->off)
|
||||
tearoff_enabled = false;
|
||||
if (payload->delay_us > 0)
|
||||
tearoff_delay_us = payload->delay_us;
|
||||
reply_ng(CMD_SET_TEAROFF, PM3_SUCCESS, NULL, 0);
|
||||
break;
|
||||
}
|
||||
// always available
|
||||
case CMD_HF_DROPFIELD: {
|
||||
hf_field_off();
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
extern int g_rsamples; // = 0;
|
||||
extern uint8_t g_trigger;
|
||||
|
||||
int tearoff_hook(void);
|
||||
|
||||
// ADC Vref = 3300mV, and an (10M+1M):1M voltage divider on the HF input can measure voltages up to 36300 mV
|
||||
#define MAX_ADC_HF_VOLTAGE 36300
|
||||
// ADC Vref = 3300mV, (240k-10M):240k voltage divider, 140800 mV
|
||||
|
||||
@@ -2573,15 +2573,20 @@ void EM4xWriteWord(uint8_t addr, uint32_t data, uint32_t pwd, uint8_t usepwd) {
|
||||
|
||||
SendForward(len);
|
||||
|
||||
// Wait 20ms for write to complete?
|
||||
// No, when write is denied, err preamble comes much sooner
|
||||
//WaitUS(10820); // tPC+tWEE
|
||||
if (tearoff_hook() == PM3_ETEAROFF) { // tearoff occured
|
||||
StopTicks();
|
||||
reply_ng(CMD_LF_EM4X_WRITEWORD, PM3_ETEAROFF, NULL, 0);
|
||||
} else {
|
||||
// Wait 20ms for write to complete?
|
||||
// No, when write is denied, err preamble comes much sooner
|
||||
//WaitUS(10820); // tPC+tWEE
|
||||
|
||||
DoPartialAcquisition(0, false, 6000, 1000);
|
||||
DoPartialAcquisition(0, false, 6000, 1000);
|
||||
|
||||
StopTicks();
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
reply_ng(CMD_LF_EM4X_WRITEWORD, PM3_SUCCESS, NULL, 0);
|
||||
StopTicks();
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
reply_ng(CMD_LF_EM4X_WRITEWORD, PM3_SUCCESS, NULL, 0);
|
||||
}
|
||||
LEDsoff();
|
||||
}
|
||||
|
||||
@@ -2610,15 +2615,19 @@ void EM4xProtectWord(uint32_t data, uint32_t pwd, uint8_t usepwd) {
|
||||
|
||||
SendForward(len);
|
||||
|
||||
// Wait 20ms for write to complete?
|
||||
// No, when write is denied, err preamble comes much sooner
|
||||
//WaitUS(13640); // tPC+tPR
|
||||
if (tearoff_hook() == PM3_ETEAROFF) { // tearoff occured
|
||||
StopTicks();
|
||||
reply_ng(CMD_LF_EM4X_PROTECTWORD, PM3_ETEAROFF, NULL, 0);
|
||||
} else {
|
||||
// Wait 20ms for write to complete?
|
||||
// No, when write is denied, err preamble comes much sooner
|
||||
//WaitUS(13640); // tPC+tPR
|
||||
|
||||
DoPartialAcquisition(0, false, 6000, 1000);
|
||||
|
||||
StopTicks();
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
reply_ng(CMD_LF_EM4X_PROTECTWORD, PM3_SUCCESS, NULL, 0);
|
||||
DoPartialAcquisition(0, false, 6000, 1000);
|
||||
StopTicks();
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
reply_ng(CMD_LF_EM4X_PROTECTWORD, PM3_SUCCESS, NULL, 0);
|
||||
}
|
||||
LEDsoff();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user