Better hw detectreader

Fix regression in 5f831ee776
Add support for switching modes by keyboard
This commit is contained in:
wh201906 2024-02-16 21:52:27 +08:00
parent 0079493a36
commit 710c8ede8e
No known key found for this signature in database
3 changed files with 44 additions and 18 deletions

View file

@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
## [unreleased][unreleased]
- Changed `hw detectreader` - Detect both LF and HF at the same time (@wh201906)
- Changed `hf mfu info` - should not try pwd against a UL-AES (@iceman1001)
- Fixed `hf mfu info` - tag type identification now properly handles 64bits (@iceman1001)
- Changed `hf st info` - reworked the output (@iceman1001)

View file

@ -612,6 +612,7 @@ at the same place! :-)
#define LIGHT_LEVELS 20
void ListenReaderField(uint8_t limit) {
#define LF_HF_BOTH 0
#define LF_ONLY 1
#define HF_ONLY 2
#define REPORT_CHANGE 1000 // report new values only if they have changed at least by REPORT_CHANGE mV
@ -627,13 +628,13 @@ void ListenReaderField(uint8_t limit) {
LEDsoff();
if (limit == LF_ONLY) {
if (limit == LF_ONLY || limit == LF_HF_BOTH) {
lf_av = lf_max = (MAX_ADC_LF_VOLTAGE * SumAdc(ADC_CHAN_LF, 32)) >> 15;
Dbprintf("LF 125/134kHz Baseline: %dmV", lf_av);
lf_baseline = lf_av;
}
if (limit == HF_ONLY) {
if (limit == HF_ONLY || limit == LF_HF_BOTH) {
// iceman, useless, since we are measuring readerfield, not our field. My tests shows a max of 20v from a reader.
hf_av = hf_max = (MAX_ADC_HF_VOLTAGE * SumAdc(ADC_CHAN_HF, 32)) >> 15;
@ -643,8 +644,15 @@ void ListenReaderField(uint8_t limit) {
for (;;) {
// Switch modes with button
if (BUTTON_PRESS()) {
// Switch modes with button or Enter key
bool modeSwitched = BUTTON_PRESS();
if (modeSwitched == false && data_available()) {
// flush the buffer
PacketCommandNG rx;
receive_ng(&rx);
modeSwitched = true;
}
if (modeSwitched) {
SpinDelay(500);
switch (mode) {
case 1:
@ -661,7 +669,7 @@ void ListenReaderField(uint8_t limit) {
}
WDT_HIT();
if (limit == LF_ONLY) {
if (limit == LF_ONLY || limit == LF_HF_BOTH) {
if (mode == 1) {
if (ABS(lf_av - lf_baseline) > REPORT_CHANGE)
LED_D_ON();
@ -679,7 +687,7 @@ void ListenReaderField(uint8_t limit) {
}
}
if (limit == HF_ONLY) {
if (limit == HF_ONLY || limit == LF_HF_BOTH) {
if (mode == 1) {
if (ABS(hf_av - hf_baseline) > REPORT_CHANGE)
LED_B_ON();
@ -2312,6 +2320,7 @@ static void PacketReceived(PacketCommandNG *packet) {
if (packet->length != sizeof(uint8_t))
break;
ListenReaderField(packet->data.asBytes[0]);
reply_ng(CMD_LISTEN_READER_FIELD, PM3_EOPABORTED, NULL, 0);
break;
}
case CMD_FPGA_MAJOR_MODE_OFF: { // ## FPGA Control

View file

@ -529,13 +529,14 @@ static int CmdDetectReader(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hw detectreader",
"Start to detect presences of reader field",
"hw detectreader\n"
"hw detectreader -L\n"
);
void *argtable[] = {
arg_param_begin,
arg_lit0("L", "LF", "detect low frequency 125/134 kHz"),
arg_lit0("H", "HF", "detect high frequency 13.56 MHZ"),
arg_lit0("L", "LF", "only detect low frequency 125/134 kHz"),
arg_lit0("H", "HF", "only detect high frequency 13.56 MHZ"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
@ -543,20 +544,35 @@ static int CmdDetectReader(const char *Cmd) {
bool hf = arg_get_lit(ctx, 2);
CLIParserFree(ctx);
if ((lf + hf) > 1) {
PrintAndLogEx(INFO, "Can only set one frequency");
return PM3_EINVARG;
// 0: Detect both frequency in mode 1
// 1: LF_ONLY
// 2: HF_ONLY
uint8_t arg = 0;
if (lf == true && hf == false) {
arg = 1;
} else if (hf == true && lf == false) {
arg = 2;
}
uint8_t arg = 0;
if (lf)
arg = 1;
else if (hf)
arg = 2;
PrintAndLogEx(INFO, "Press " _GREEN_("pm3 button") " to change modes and exit");
clearCommandBuffer();
SendCommandNG(CMD_LISTEN_READER_FIELD, (uint8_t *)&arg, sizeof(arg));
PrintAndLogEx(INFO, "Press " _GREEN_("pm3 button") " or " _GREEN_("<Enter>") " to change modes and exit");
for (;;) {
if (kbd_enter_pressed()) {
SendCommandNG(CMD_BREAK_LOOP, NULL, 0);
PrintAndLogEx(DEBUG, _GREEN_("<Enter>") " pressed");
}
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_LISTEN_READER_FIELD, &resp, 1000)) {
if (resp.status != PM3_EOPABORTED) {
PrintAndLogEx(ERR, "Unexpected response: %d", resp.status);
}
break;
}
}
PrintAndLogEx(INFO, "Done!");
return PM3_SUCCESS;
}