mirror of
https://github.com/Proxmark/proxmark3.git
synced 2024-09-21 23:36:51 +08:00
Merge pull request #181 from raburton/tune
add l/h option to hw tune and optimize order of tuning
This commit is contained in:
commit
83f11ccf72
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -21,6 +21,7 @@ flasher
|
|||
version.c
|
||||
lua
|
||||
luac
|
||||
fpga_compress
|
||||
|
||||
fpga/*
|
||||
!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 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 `l` or `h` to `hw tune` to save time and unnecessary fpga writes if you are only interested in lf or hf.
|
||||
|
||||
### Changed
|
||||
- Added `[l] <length>` option to data printdemodbuffer
|
||||
|
|
|
@ -182,13 +182,9 @@ int AvgAdc(int ch) // was static - merlok
|
|||
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, peakv = 0, peakf = 0; //ptr = 0
|
||||
int vLf125 = 0, vLf134 = 0, vHf = 0; // in mV
|
||||
|
||||
LED_B_ON();
|
||||
int i, adcval = 0, peak = 0;
|
||||
|
||||
/*
|
||||
* Sweeps the useful LF range of the proxmark from
|
||||
|
@ -198,38 +194,67 @@ void MeasureAntennaTuning(void)
|
|||
* the resonating frequency of your LF antenna
|
||||
* ( hopefully around 95 if it is tuned to 125kHz!)
|
||||
*/
|
||||
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
||||
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
|
||||
for (i=255; i>=19; i--) {
|
||||
WDT_HIT();
|
||||
WDT_HIT();
|
||||
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, i);
|
||||
SpinDelay(20);
|
||||
adcval = ((MAX_ADC_LF_VOLTAGE * AvgAdc(ADC_CHAN_LF)) >> 10);
|
||||
if (i==95) vLf125 = adcval; // voltage at 125Khz
|
||||
if (i==89) vLf134 = adcval; // voltage at 134Khz
|
||||
if (i==95) *vLf125 = adcval; // voltage at 125Khz
|
||||
if (i==89) *vLf134 = adcval; // voltage at 134Khz
|
||||
|
||||
LF_Results[i] = adcval>>8; // scale int to fit in byte for graphing purposes
|
||||
if(LF_Results[i] > peak) {
|
||||
peakv = adcval;
|
||||
*peakv = adcval;
|
||||
peak = LF_Results[i];
|
||||
peakf = i;
|
||||
*peakf = i;
|
||||
//ptr = i;
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
LED_A_ON();
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
|
||||
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);
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
LED_A_OFF();
|
||||
LED_B_OFF();
|
||||
return;
|
||||
}
|
||||
|
@ -1231,7 +1256,7 @@ void UsbPacketReceived(uint8_t *packet, int len)
|
|||
break;
|
||||
|
||||
case CMD_MEASURE_ANTENNA_TUNING:
|
||||
MeasureAntennaTuning();
|
||||
MeasureAntennaTuning(c->arg[0]);
|
||||
break;
|
||||
|
||||
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 Dbprintf(" mode.............%d", downloaded_bitstream);
|
||||
}
|
||||
|
||||
int FpgaGetCurrent() {
|
||||
return downloaded_bitstream;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ void FpgaSetupSsc(void);
|
|||
void SetupSpi(int mode);
|
||||
bool FpgaSetupSscDma(uint8_t *buf, int len);
|
||||
void Fpga_print_status();
|
||||
int FpgaGetCurrent();
|
||||
#define FpgaDisableSscDma(void) AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS;
|
||||
#define FpgaEnableSscDma(void) AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN;
|
||||
void SetAdcMuxFor(uint32_t whichGpio);
|
||||
|
|
|
@ -2048,10 +2048,20 @@ int CmdSamples(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...");
|
||||
|
||||
UsbCommand c = {CMD_MEASURE_ANTENNA_TUNING};
|
||||
UsbCommand c = {CMD_MEASURE_ANTENNA_TUNING, {arg, 0, 0}};
|
||||
SendCommand(&c);
|
||||
|
||||
UsbCommand resp;
|
||||
|
|
|
@ -467,7 +467,7 @@ static command_t CommandTable[] =
|
|||
{"reset", CmdReset, 0, "Reset the Proxmark3"},
|
||||
{"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"},
|
||||
{"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"},
|
||||
{"status", CmdStatus, 0, "Show runtime status information about the connected Proxmark"},
|
||||
{"ping", CmdPing, 0, "Test if the pm3 is responsive"},
|
||||
|
|
|
@ -228,6 +228,11 @@ typedef struct{
|
|||
#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:
|
||||
/* Whether a bootloader that understands the common_area is present */
|
||||
|
|
Loading…
Reference in a new issue