]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
Merge pull request #185 from marshmellow42/master
authorIceman <iceman@iuse.se>
Fri, 12 Aug 2016 11:55:09 +0000 (13:55 +0200)
committerGitHub <noreply@github.com>
Fri, 12 Aug 2016 11:55:09 +0000 (13:55 +0200)
some lf fixes and hf mf sim attack mode add-ons

.gitignore
CHANGELOG.md
armsrc/appmain.c
armsrc/fpgaloader.c
armsrc/fpgaloader.h
client/cmddata.c
client/cmdhw.c
include/usb_cmd.h

index fa74326ed6f9297683b6124cb138becaa61bc94f..4af73fb12625d454c10459ea96660e5c689cc811 100644 (file)
@@ -21,6 +21,7 @@ flasher
 version.c
 lua
 luac
+fpga_compress
 
 fpga/*
 !fpga/tests
index b50083abb7be3f53f18a90d40cde207461f514ac..4b09e461cac3358d1f2e474099f10ff15f274f62 100644 (file)
@@ -34,6 +34,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac
 - 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
 - Fixed bug in lf biphase sim - `lf simask b` (and any tagtype that relies on it - gproxii...) (marshmellow)
index ffe6b7f22f745e47ccdd5c3ed0890682e63081ab..aaa41f4acd3b6371092f5a86bb151236d7730bc5 100644 (file)
@@ -180,13 +180,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
@@ -196,38 +192,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;
 }
@@ -1229,7 +1254,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:
index 308dda8c09e6ebf8fd0a691df91ccb0c0c3189d2..e211c12fbd5a7e5119b86d6196da954e1b0198ef 100644 (file)
@@ -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;
+}
index 38724cdba3dc996d71b58ccbd671b49b8bbf13ac..7dfc5c1265e539e8e8e419bb9ad68da857e6a061 100644 (file)
@@ -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);
index ba161dd832fbbdd371f52b1395acb3b83923e640..86dac4233507089c67abdf43be8fc45e7fd97933 100644 (file)
@@ -2038,10 +2038,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;
index 33dc78aeb523c5731ec297e9432159336d774580..74e476eb55067a3c72eb4c666cb82f32dd1f4086 100644 (file)
@@ -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"},
index 03a573d5d58c299e56a917371ecf57457ba5d6f0..66e6cf91cea3529422532a746d8ac2185eee993d 100644 (file)
@@ -229,6 +229,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 */
Impressum, Datenschutz