mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 21:33:47 -07:00
Rework hf tune to make it synchronous (needed for rdv4)
This commit is contained in:
parent
995d782bb0
commit
7ed7a9de40
5 changed files with 74 additions and 34 deletions
|
@ -55,6 +55,7 @@ uint8_t ToSend[TOSEND_BUFFER_SIZE];
|
||||||
int ToSendMax = -1;
|
int ToSendMax = -1;
|
||||||
static int ToSendBit;
|
static int ToSendBit;
|
||||||
struct common_area common_area __attribute__((section(".commonarea")));
|
struct common_area common_area __attribute__((section(".commonarea")));
|
||||||
|
int button_status = BUTTON_NO_CLICK;
|
||||||
|
|
||||||
void ToSendReset(void) {
|
void ToSendReset(void) {
|
||||||
ToSendMax = -1;
|
ToSendMax = -1;
|
||||||
|
@ -300,28 +301,17 @@ void MeasureAntennaTuning(void) {
|
||||||
LEDsoff();
|
LEDsoff();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeasureAntennaTuningHf(void) {
|
uint16_t MeasureAntennaTuningHfData(void) {
|
||||||
uint16_t volt = 0; // in mV
|
uint16_t volt = 0; // in mV
|
||||||
// Let the FPGA drive the high-frequency antenna around 13.56 MHz.
|
|
||||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
|
|
||||||
SpinDelay(50);
|
|
||||||
volt = (MAX_ADC_HF_VOLTAGE * AvgAdc(ADC_CHAN_HF)) >> 10;
|
volt = (MAX_ADC_HF_VOLTAGE * AvgAdc(ADC_CHAN_HF)) >> 10;
|
||||||
bool use_high = (volt > MAX_ADC_HF_VOLTAGE - 300);
|
bool use_high = (volt > MAX_ADC_HF_VOLTAGE - 300);
|
||||||
|
|
||||||
while (!BUTTON_PRESS()) {
|
if (!use_high) {
|
||||||
SpinDelay(20);
|
volt = (MAX_ADC_HF_VOLTAGE * AvgAdc(ADC_CHAN_HF)) >> 10;
|
||||||
if (!use_high) {
|
} else {
|
||||||
volt = (MAX_ADC_HF_VOLTAGE * AvgAdc(ADC_CHAN_HF)) >> 10;
|
volt = (MAX_ADC_HF_VOLTAGE_RDV40 * AvgAdc(ADC_CHAN_HF_RDV40)) >> 10;
|
||||||
} else {
|
|
||||||
volt = (MAX_ADC_HF_VOLTAGE_RDV40 * AvgAdc(ADC_CHAN_HF_RDV40)) >> 10;
|
|
||||||
}
|
|
||||||
DbprintfEx(FLAG_INPLACE, "%u mV / %5u V", volt, (uint16_t)(volt / 1000));
|
|
||||||
}
|
}
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
return volt;
|
||||||
DbprintfEx(FLAG_NEWLINE, "");
|
|
||||||
Dbprintf("[+] cancelled", 1);
|
|
||||||
reply_ng(CMD_MEASURE_ANTENNA_TUNING_HF, PM3_EOPABORTED, NULL, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadMem(int addr) {
|
void ReadMem(int addr) {
|
||||||
|
@ -1239,8 +1229,23 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||||
MeasureAntennaTuning();
|
MeasureAntennaTuning();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_MEASURE_ANTENNA_TUNING_HF:
|
case CMD_MEASURE_ANTENNA_TUNING_HF_START:
|
||||||
MeasureAntennaTuningHf();
|
// Let the FPGA drive the high-frequency antenna around 13.56 MHz.
|
||||||
|
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||||
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
|
||||||
|
reply_ng(CMD_MEASURE_ANTENNA_TUNING_HF_START, PM3_SUCCESS, NULL, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CMD_MEASURE_ANTENNA_TUNING_HF_SAMPLE:
|
||||||
|
if (button_status == BUTTON_SINGLE_CLICK)
|
||||||
|
reply_ng(CMD_MEASURE_ANTENNA_TUNING_HF_SAMPLE, PM3_EOPABORTED, NULL, 0);
|
||||||
|
uint16_t volt = MeasureAntennaTuningHfData();
|
||||||
|
reply_ng(CMD_MEASURE_ANTENNA_TUNING_HF_SAMPLE, PM3_SUCCESS, (uint8_t *)&volt, sizeof(volt));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CMD_MEASURE_ANTENNA_TUNING_HF_STOP:
|
||||||
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
|
reply_ng(CMD_MEASURE_ANTENNA_TUNING_HF_STOP, PM3_SUCCESS, NULL, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_LISTEN_READER_FIELD:
|
case CMD_LISTEN_READER_FIELD:
|
||||||
|
@ -1646,8 +1651,8 @@ void __attribute__((noreturn)) AppMain(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Press button for one second to enter a possible standalone mode
|
// Press button for one second to enter a possible standalone mode
|
||||||
if (BUTTON_HELD(1000) > 0) {
|
button_status = BUTTON_HELD(1000);
|
||||||
|
if (button_status == BUTTON_HOLD) {
|
||||||
/*
|
/*
|
||||||
* So this is the trigger to execute a standalone mod. Generic entrypoint by following the standalone/standalone.h headerfile
|
* So this is the trigger to execute a standalone mod. Generic entrypoint by following the standalone/standalone.h headerfile
|
||||||
* All standalone mod "main loop" should be the RunMod() function.
|
* All standalone mod "main loop" should be the RunMod() function.
|
||||||
|
|
|
@ -20,6 +20,7 @@ static int usage_hf_search() {
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usage_hf_sniff() {
|
static int usage_hf_sniff() {
|
||||||
PrintAndLogEx(NORMAL, "The high frequence sniffer will assign all available memory on device for sniffed data");
|
PrintAndLogEx(NORMAL, "The high frequence sniffer will assign all available memory on device for sniffed data");
|
||||||
PrintAndLogEx(NORMAL, "Use " _YELLOW_("'data samples'")" command to download from device, and " _YELLOW_("'data plot'")" to look at it");
|
PrintAndLogEx(NORMAL, "Use " _YELLOW_("'data samples'")" command to download from device, and " _YELLOW_("'data plot'")" to look at it");
|
||||||
|
@ -36,6 +37,16 @@ static int usage_hf_sniff() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int usage_hf_tune() {
|
||||||
|
PrintAndLogEx(NORMAL, "Usage: hf tune [<iter>]");
|
||||||
|
PrintAndLogEx(NORMAL, "Continuously measure HF antenna tuning.");
|
||||||
|
PrintAndLogEx(NORMAL, "Press button to interrupt.");
|
||||||
|
PrintAndLogEx(NORMAL, "Options:");
|
||||||
|
PrintAndLogEx(NORMAL, " <iter> - number of iterations (default: infinite)");
|
||||||
|
PrintAndLogEx(NORMAL, "");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int CmdHFSearch(const char *Cmd) {
|
int CmdHFSearch(const char *Cmd) {
|
||||||
|
|
||||||
char cmdp = tolower(param_getchar(Cmd, 0));
|
char cmdp = tolower(param_getchar(Cmd, 0));
|
||||||
|
@ -82,17 +93,35 @@ int CmdHFSearch(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdHFTune(const char *Cmd) {
|
int CmdHFTune(const char *Cmd) {
|
||||||
(void)Cmd; // Cmd is not used so far
|
char cmdp = tolower(param_getchar(Cmd, 0));
|
||||||
PrintAndLogEx(SUCCESS, "Measuring HF antenna, press button to exit");
|
if (cmdp == 'h') return usage_hf_tune();
|
||||||
clearCommandBuffer();
|
int iter = param_get32ex(Cmd, 0, 0, 10);
|
||||||
SendCommandNG(CMD_MEASURE_ANTENNA_TUNING_HF, NULL, 0);
|
|
||||||
PacketResponseNG resp;
|
PacketResponseNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_MEASURE_ANTENNA_TUNING_HF, &resp, 1000)) {
|
PrintAndLogEx(SUCCESS, "Measuring HF antenna, click button to exit");
|
||||||
|
clearCommandBuffer();
|
||||||
|
SendCommandNG(CMD_MEASURE_ANTENNA_TUNING_HF_START, NULL, 0);
|
||||||
|
if (!WaitForResponseTimeout(CMD_MEASURE_ANTENNA_TUNING_HF_START, &resp, 1000)) {
|
||||||
PrintAndLogEx(WARNING, "Timeout while waiting for Proxmark HF measure, aborting");
|
PrintAndLogEx(WARNING, "Timeout while waiting for Proxmark HF measure, aborting");
|
||||||
return PM3_ETIMEOUT;
|
return PM3_ETIMEOUT;
|
||||||
}
|
}
|
||||||
if (resp.status != PM3_EOPABORTED)
|
for (uint8_t i=0; iter == 0 || i< iter; i++) { // loop forever (till button pressed) if iter = 0 (default)
|
||||||
return resp.status;
|
SendCommandNG(CMD_MEASURE_ANTENNA_TUNING_HF_SAMPLE, NULL, 0);
|
||||||
|
if (!WaitForResponseTimeout(CMD_MEASURE_ANTENNA_TUNING_HF_SAMPLE, &resp, 1000)) {
|
||||||
|
PrintAndLogEx(WARNING, "Timeout while waiting for Proxmark HF measure, aborting");
|
||||||
|
return PM3_ETIMEOUT;
|
||||||
|
}
|
||||||
|
if (resp.status == PM3_EOPABORTED)
|
||||||
|
break;
|
||||||
|
uint16_t volt = resp.data.asDwords[0];
|
||||||
|
PrintAndLogEx(INPLACE, "%u mV / %5u V", volt, (uint16_t)(volt / 1000));
|
||||||
|
}
|
||||||
|
SendCommandNG(CMD_MEASURE_ANTENNA_TUNING_HF_STOP, NULL, 0);
|
||||||
|
if (!WaitForResponseTimeout(CMD_MEASURE_ANTENNA_TUNING_HF_STOP, &resp, 1000)) {
|
||||||
|
PrintAndLogEx(WARNING, "Timeout while waiting for Proxmark HF measure, aborting");
|
||||||
|
return PM3_ETIMEOUT;
|
||||||
|
}
|
||||||
|
PrintAndLogEx(SUCCESS, "Done.");
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
client/ui.c
12
client/ui.c
|
@ -63,8 +63,6 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
|
||||||
char buffer2[MAX_PRINT_BUFFER + 20] = {0};
|
char buffer2[MAX_PRINT_BUFFER + 20] = {0};
|
||||||
char *token = NULL;
|
char *token = NULL;
|
||||||
char *tmp_ptr = NULL;
|
char *tmp_ptr = NULL;
|
||||||
// {NORMAL, SUCCESS, INFO, FAILED, WARNING, ERR, DEBUG}
|
|
||||||
static const char *prefixes[7] = { "", "[+] ", "[=] ", "[-] ", "[!] ", "[!!] ", "[#] "};
|
|
||||||
FILE *stream = stdout;
|
FILE *stream = stdout;
|
||||||
|
|
||||||
switch (level) {
|
switch (level) {
|
||||||
|
@ -88,7 +86,8 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
|
||||||
strncpy(prefix, _YELLOW_("[=]"), sizeof(prefix) - 1);
|
strncpy(prefix, _YELLOW_("[=]"), sizeof(prefix) - 1);
|
||||||
break;
|
break;
|
||||||
case NORMAL:
|
case NORMAL:
|
||||||
strncpy(prefix, prefixes[level], sizeof(prefix) - 1);
|
case INPLACE:
|
||||||
|
// no prefixes for normal & inplace
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,11 +96,16 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
|
||||||
vsnprintf(buffer, sizeof(buffer), fmt, args);
|
vsnprintf(buffer, sizeof(buffer), fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
// no prefixes for normal
|
// no prefixes for normal & inplace
|
||||||
if (level == NORMAL) {
|
if (level == NORMAL) {
|
||||||
fPrintAndLog(stream, "%s", buffer);
|
fPrintAndLog(stream, "%s", buffer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (level == INPLACE) {
|
||||||
|
printf("%s\r", buffer);
|
||||||
|
fflush(stdout);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (strchr(buffer, '\n')) {
|
if (strchr(buffer, '\n')) {
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ extern session_arg_t session;
|
||||||
#define M_PI 3.14159265358979323846264338327
|
#define M_PI 3.14159265358979323846264338327
|
||||||
#endif
|
#endif
|
||||||
#define MAX_PRINT_BUFFER 2048
|
#define MAX_PRINT_BUFFER 2048
|
||||||
typedef enum logLevel {NORMAL, SUCCESS, INFO, FAILED, WARNING, ERR, DEBUG} logLevel_t;
|
typedef enum logLevel {NORMAL, SUCCESS, INFO, FAILED, WARNING, ERR, DEBUG, INPLACE} logLevel_t;
|
||||||
|
|
||||||
void ShowGui(void);
|
void ShowGui(void);
|
||||||
void HideGraphWindow(void);
|
void HideGraphWindow(void);
|
||||||
|
|
|
@ -335,7 +335,9 @@ typedef struct {
|
||||||
|
|
||||||
// For measurements of the antenna tuning
|
// For measurements of the antenna tuning
|
||||||
#define CMD_MEASURE_ANTENNA_TUNING 0x0400
|
#define CMD_MEASURE_ANTENNA_TUNING 0x0400
|
||||||
#define CMD_MEASURE_ANTENNA_TUNING_HF 0x0401
|
#define CMD_MEASURE_ANTENNA_TUNING_HF_START 0x0401
|
||||||
|
#define CMD_MEASURE_ANTENNA_TUNING_HF_SAMPLE 0x0402
|
||||||
|
#define CMD_MEASURE_ANTENNA_TUNING_HF_STOP 0x0403
|
||||||
#define CMD_MEASURED_ANTENNA_TUNING 0x0410
|
#define CMD_MEASURED_ANTENNA_TUNING 0x0410
|
||||||
#define CMD_LISTEN_READER_FIELD 0x0420
|
#define CMD_LISTEN_READER_FIELD 0x0420
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue