mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-07-10 23:42:40 -07:00
add l/h option to hw tune and optimize order of tuning
This commit is contained in:
parent
6fcb5dda51
commit
fdcfbdcc21
8 changed files with 69 additions and 22 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -21,6 +21,7 @@ flasher
|
||||||
version.c
|
version.c
|
||||||
lua
|
lua
|
||||||
luac
|
luac
|
||||||
|
fpga_compress
|
||||||
|
|
||||||
fpga/*
|
fpga/*
|
||||||
!fpga/tests
|
!fpga/tests
|
||||||
|
|
|
@ -33,6 +33,7 @@ of stream transmissions (marshmellow)
|
||||||
- Added 'hf snoop'. This command take digitalized signal from FPGA and put in BigBuffer. (pwpiwi + enio)
|
- Added 'hf snoop'. This command take digitalized signal from FPGA and put in BigBuffer. (pwpiwi + enio)
|
||||||
- Added Topaz (NFC type 1) protocol support ('hf topaz reader', 'hf list topaz', 'hf 14a raw -T', 'hf topaz snoop'). (piwi)
|
- Added Topaz (NFC type 1) protocol support ('hf topaz reader', 'hf list topaz', 'hf 14a raw -T', 'hf topaz snoop'). (piwi)
|
||||||
- Added option c to 'hf list' (mark CRC bytes) (piwi)
|
- Added option c to 'hf list' (mark CRC bytes) (piwi)
|
||||||
|
- Added option `l` or `h` to `hw tune` to save time and unnecessary fpga writes if you are only interested in lf or hf.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Added `[l] <length>` option to data printdemodbuffer
|
- Added `[l] <length>` option to data printdemodbuffer
|
||||||
|
|
|
@ -182,13 +182,9 @@ int AvgAdc(int ch) // was static - merlok
|
||||||
return (a + 15) >> 5;
|
return (a + 15) >> 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeasureAntennaTuning(void)
|
void MeasureAntennaTuningLfOnly(int *vLf125, int *vLf134, int *peakf, int *peakv, uint8_t LF_Results[])
|
||||||
{
|
{
|
||||||
uint8_t LF_Results[256];
|
int i, adcval = 0, peak = 0;
|
||||||
int i, adcval = 0, peak = 0, peakv = 0, peakf = 0; //ptr = 0
|
|
||||||
int vLf125 = 0, vLf134 = 0, vHf = 0; // in mV
|
|
||||||
|
|
||||||
LED_B_ON();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sweeps the useful LF range of the proxmark from
|
* Sweeps the useful LF range of the proxmark from
|
||||||
|
@ -206,30 +202,59 @@ void MeasureAntennaTuning(void)
|
||||||
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, i);
|
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, i);
|
||||||
SpinDelay(20);
|
SpinDelay(20);
|
||||||
adcval = ((MAX_ADC_LF_VOLTAGE * AvgAdc(ADC_CHAN_LF)) >> 10);
|
adcval = ((MAX_ADC_LF_VOLTAGE * AvgAdc(ADC_CHAN_LF)) >> 10);
|
||||||
if (i==95) vLf125 = adcval; // voltage at 125Khz
|
if (i==95) *vLf125 = adcval; // voltage at 125Khz
|
||||||
if (i==89) vLf134 = adcval; // voltage at 134Khz
|
if (i==89) *vLf134 = adcval; // voltage at 134Khz
|
||||||
|
|
||||||
LF_Results[i] = adcval>>8; // scale int to fit in byte for graphing purposes
|
LF_Results[i] = adcval>>8; // scale int to fit in byte for graphing purposes
|
||||||
if(LF_Results[i] > peak) {
|
if(LF_Results[i] > peak) {
|
||||||
peakv = adcval;
|
*peakv = adcval;
|
||||||
peak = LF_Results[i];
|
peak = LF_Results[i];
|
||||||
peakf = i;
|
*peakf = i;
|
||||||
//ptr = i;
|
//ptr = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=18; i >= 0; i--) LF_Results[i] = 0;
|
for (i=18; i >= 0; i--) LF_Results[i] = 0;
|
||||||
|
|
||||||
LED_A_ON();
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MeasureAntennaTuningHfOnly(int *vHf)
|
||||||
|
{
|
||||||
// Let the FPGA drive the high-frequency antenna around 13.56 MHz.
|
// Let the FPGA drive the high-frequency antenna around 13.56 MHz.
|
||||||
|
LED_A_ON();
|
||||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
|
||||||
SpinDelay(20);
|
SpinDelay(20);
|
||||||
vHf = (MAX_ADC_HF_VOLTAGE * AvgAdc(ADC_CHAN_HF)) >> 10;
|
*vHf = (MAX_ADC_HF_VOLTAGE * AvgAdc(ADC_CHAN_HF)) >> 10;
|
||||||
|
LED_A_OFF();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MeasureAntennaTuning(int mode)
|
||||||
|
{
|
||||||
|
uint8_t LF_Results[256] = {0};
|
||||||
|
int peakv = 0, peakf = 0;
|
||||||
|
int vLf125 = 0, vLf134 = 0, vHf = 0; // in mV
|
||||||
|
|
||||||
|
LED_B_ON();
|
||||||
|
|
||||||
|
if (((mode & FLAG_TUNE_ALL) == FLAG_TUNE_ALL) && (FpgaGetCurrent() == FPGA_BITSTREAM_HF)) {
|
||||||
|
// Reverse "standard" order if HF already loaded, to avoid unnecessary swap.
|
||||||
|
MeasureAntennaTuningHfOnly(&vHf);
|
||||||
|
MeasureAntennaTuningLfOnly(&vLf125, &vLf134, &peakf, &peakv, LF_Results);
|
||||||
|
} else {
|
||||||
|
if (mode & FLAG_TUNE_LF) {
|
||||||
|
MeasureAntennaTuningLfOnly(&vLf125, &vLf134, &peakf, &peakv, LF_Results);
|
||||||
|
}
|
||||||
|
if (mode & FLAG_TUNE_HF) {
|
||||||
|
MeasureAntennaTuningHfOnly(&vHf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cmd_send(CMD_MEASURED_ANTENNA_TUNING, vLf125 | (vLf134<<16), vHf, peakf | (peakv<<16), LF_Results, 256);
|
cmd_send(CMD_MEASURED_ANTENNA_TUNING, vLf125 | (vLf134<<16), vHf, peakf | (peakv<<16), LF_Results, 256);
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
LED_A_OFF();
|
|
||||||
LED_B_OFF();
|
LED_B_OFF();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1231,7 +1256,7 @@ void UsbPacketReceived(uint8_t *packet, int len)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_MEASURE_ANTENNA_TUNING:
|
case CMD_MEASURE_ANTENNA_TUNING:
|
||||||
MeasureAntennaTuning();
|
MeasureAntennaTuning(c->arg[0]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_MEASURE_ANTENNA_TUNING_HF:
|
case CMD_MEASURE_ANTENNA_TUNING_HF:
|
||||||
|
|
|
@ -566,3 +566,7 @@ void Fpga_print_status(void)
|
||||||
else if(downloaded_bitstream == FPGA_BITSTREAM_LF) Dbprintf(" mode.............LF");
|
else if(downloaded_bitstream == FPGA_BITSTREAM_LF) Dbprintf(" mode.............LF");
|
||||||
else Dbprintf(" mode.............%d", downloaded_bitstream);
|
else Dbprintf(" mode.............%d", downloaded_bitstream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int FpgaGetCurrent() {
|
||||||
|
return downloaded_bitstream;
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ void FpgaSetupSsc(void);
|
||||||
void SetupSpi(int mode);
|
void SetupSpi(int mode);
|
||||||
bool FpgaSetupSscDma(uint8_t *buf, int len);
|
bool FpgaSetupSscDma(uint8_t *buf, int len);
|
||||||
void Fpga_print_status();
|
void Fpga_print_status();
|
||||||
|
int FpgaGetCurrent();
|
||||||
#define FpgaDisableSscDma(void) AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS;
|
#define FpgaDisableSscDma(void) AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS;
|
||||||
#define FpgaEnableSscDma(void) AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN;
|
#define FpgaEnableSscDma(void) AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN;
|
||||||
void SetAdcMuxFor(uint32_t whichGpio);
|
void SetAdcMuxFor(uint32_t whichGpio);
|
||||||
|
|
|
@ -2048,10 +2048,20 @@ int CmdSamples(const char *Cmd)
|
||||||
|
|
||||||
int CmdTuneSamples(const char *Cmd)
|
int CmdTuneSamples(const char *Cmd)
|
||||||
{
|
{
|
||||||
int timeout = 0;
|
int timeout = 0, arg = FLAG_TUNE_ALL;
|
||||||
|
|
||||||
|
if(*Cmd == 'l') {
|
||||||
|
arg = FLAG_TUNE_LF;
|
||||||
|
} else if (*Cmd == 'h') {
|
||||||
|
arg = FLAG_TUNE_HF;
|
||||||
|
} else if (*Cmd != '\0') {
|
||||||
|
PrintAndLog("use 'tune' or 'tune l' or 'tune h'");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
printf("\nMeasuring antenna characteristics, please wait...");
|
printf("\nMeasuring antenna characteristics, please wait...");
|
||||||
|
|
||||||
UsbCommand c = {CMD_MEASURE_ANTENNA_TUNING};
|
UsbCommand c = {CMD_MEASURE_ANTENNA_TUNING, {arg, 0, 0}};
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbCommand resp;
|
||||||
|
|
|
@ -467,7 +467,7 @@ static command_t CommandTable[] =
|
||||||
{"reset", CmdReset, 0, "Reset the Proxmark3"},
|
{"reset", CmdReset, 0, "Reset the Proxmark3"},
|
||||||
{"setlfdivisor", CmdSetDivisor, 0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},
|
{"setlfdivisor", CmdSetDivisor, 0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},
|
||||||
{"setmux", CmdSetMux, 0, "<loraw|hiraw|lopkd|hipkd> -- Set the ADC mux to a specific value"},
|
{"setmux", CmdSetMux, 0, "<loraw|hiraw|lopkd|hipkd> -- Set the ADC mux to a specific value"},
|
||||||
{"tune", CmdTune, 0, "Measure antenna tuning"},
|
{"tune", CmdTune, 0, "['l'|'h'] -- Measure antenna tuning (option 'l' or 'h' to limit to LF or HF)"},
|
||||||
{"version", CmdVersion, 0, "Show version information about the connected Proxmark"},
|
{"version", CmdVersion, 0, "Show version information about the connected Proxmark"},
|
||||||
{"status", CmdStatus, 0, "Show runtime status information about the connected Proxmark"},
|
{"status", CmdStatus, 0, "Show runtime status information about the connected Proxmark"},
|
||||||
{"ping", CmdPing, 0, "Test if the pm3 is responsive"},
|
{"ping", CmdPing, 0, "Test if the pm3 is responsive"},
|
||||||
|
|
|
@ -228,6 +228,11 @@ typedef struct{
|
||||||
#define FLAG_ICLASS_READER_CEDITKEY 0x40
|
#define FLAG_ICLASS_READER_CEDITKEY 0x40
|
||||||
|
|
||||||
|
|
||||||
|
//hw tune args
|
||||||
|
#define FLAG_TUNE_LF 1
|
||||||
|
#define FLAG_TUNE_HF 2
|
||||||
|
#define FLAG_TUNE_ALL 3
|
||||||
|
|
||||||
|
|
||||||
// CMD_DEVICE_INFO response packet has flags in arg[0], flag definitions:
|
// CMD_DEVICE_INFO response packet has flags in arg[0], flag definitions:
|
||||||
/* Whether a bootloader that understands the common_area is present */
|
/* Whether a bootloader that understands the common_area is present */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue