]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/appmain.c
more extended help
[proxmark3-svn] / armsrc / appmain.c
index 01e3efc98274b5a73e80e68f97d84af0395bca60..77bbbbc4daec6a54b0c46ed95b1276e5db998223 100644 (file)
@@ -7,6 +7,7 @@
 
 
 #include <proxmark3.h>
+#include <stdlib.h>
 #include "apps.h"
 #ifdef WITH_LCD
 #include "fonts.h"
@@ -143,7 +144,7 @@ void ModThenAcquireRawAdcSamples125k(int delay_off,int period_0,int period_1,BYT
        BOOL at134khz;
 
        // see if 'h' was specified
-       if(command[strlen(command) - 1] == 'h')
+       if(command[strlen((char *) command) - 1] == 'h')
                at134khz= TRUE;
        else
                at134khz= FALSE;
@@ -240,7 +241,9 @@ static int AvgAdc(int ch)
 void SweepLFrange()
 {
        BYTE *dest = (BYTE *)BigBuf;
-       int i;
+       char dummy[12];
+       int i, peak= 0, ptr= 0;
+       double freq;
 
        // clear buffer
        memset(BigBuf,0,sizeof(BigBuf));
@@ -249,8 +252,29 @@ void SweepLFrange()
        for (i=255; i>19; i--) {
                FpgaSendCommand(FPGA_CMD_SET_DIVISOR, i);
                SpinDelay(20);
-               dest[i] = (137500 * AvgAdc(4)) >> 18;
+               dest[i] = (137500 * AvgAdc(ADC_CHAN_LF)) >> 18;
+               if(dest[i] > peak) {
+                       peak= dest[i];
+                       ptr= i;
+                       }
        }
+       dummy[11]= '\0';
+       dummy[10]= 'z';
+       dummy[9]= 'H';
+       dummy[8]= 'k';
+       dummy[7]= ' ';
+       freq= 12000000/(ptr + 1);
+       for(i= 6; i > 3 ; --i) {
+               dummy[i]= '0' + ((int) freq) % 10;
+               freq /= 10;
+               }
+       dummy[3]= '.';
+       for(i= 2; i >= 0 ; --i) {
+               dummy[i]= '0' + ((int) freq) % 10;
+               freq /= 10;
+               }
+       DbpString("Antenna resonates at:");
+       DbpString(dummy);
 }
 
 void MeasureAntennaTuning(void)
@@ -267,7 +291,7 @@ void MeasureAntennaTuning(void)
        FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
        FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_READER | FPGA_LF_READER_USE_125_KHZ);
        SpinDelay(20);
-       vLf125 = AvgAdc(4);
+       vLf125 = AvgAdc(ADC_CHAN_LF);
        // Vref = 3.3V, and a 10000:240 voltage divider on the input
        // can measure voltages up to 137500 mV
        vLf125 = (137500 * vLf125) >> 10;
@@ -276,7 +300,7 @@ void MeasureAntennaTuning(void)
        FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 88); //134.8Khz
        FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_READER | FPGA_LF_READER_USE_134_KHZ);
        SpinDelay(20);
-       vLf134 = AvgAdc(4);
+       vLf134 = AvgAdc(ADC_CHAN_LF);
        // Vref = 3.3V, and a 10000:240 voltage divider on the input
        // can measure voltages up to 137500 mV
        vLf134 = (137500 * vLf134) >> 10;
@@ -284,7 +308,7 @@ void MeasureAntennaTuning(void)
        // Let the FPGA drive the high-frequency antenna around 13.56 MHz.
        FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
        SpinDelay(20);
-       vHf = AvgAdc(5);
+       vHf = AvgAdc(ADC_CHAN_HF);
        // Vref = 3300mV, and an 10:1 voltage divider on the input
        // can measure voltages up to 33000 mV
        vHf = (33000 * vHf) >> 10;
@@ -315,6 +339,7 @@ void SimulateTagLowFrequency(int period)
        for(;;) {
                while(!(PIO_PIN_DATA_STATUS & (1<<GPIO_SSC_CLK))) {
                        if(BUTTON_PRESS()) {
+                               DbpString("Stopped");
                                return;
                        }
                        WDT_HIT();
@@ -330,6 +355,7 @@ void SimulateTagLowFrequency(int period)
 
                while(PIO_PIN_DATA_STATUS & (1<<GPIO_SSC_CLK)) {
                        if(BUTTON_PRESS()) {
+                               DbpString("Stopped");
                                return;
                        }
                        WDT_HIT();
@@ -463,6 +489,7 @@ static void CmdHIDdemodFSK(void)
                WDT_HIT();
                LED_A_ON();
                if(BUTTON_PRESS()) {
+                       DbpString("Stopped");
                        LED_A_OFF();
                        return;
                }
@@ -727,6 +754,10 @@ void UsbPacketReceived(BYTE *packet, int len)
                        MeasureAntennaTuning();
                        break;
 
+               case CMD_LISTEN_READER_FIELD:
+                       ListenReaderField(c->ext1);
+                       break;
+
                case CMD_HID_DEMOD_FSK:
                        CmdHIDdemodFSK();                               // Demodulate HID tag
                        break;
@@ -904,3 +935,86 @@ void SpinDelay(int ms)
                WDT_HIT();
        }
 }
+
+// listen for external reader 
+void ListenReaderField(int limit)
+{
+       int lf_av, lf_av_new, lf_baseline= 0, lf_count= 0;
+       int hf_av, hf_av_new,  hf_baseline= 0, hf_count= 0;
+
+#define LF_ONLY                1
+#define HF_ONLY                2
+
+       LED_A_OFF();
+       LED_B_OFF();
+       LED_C_OFF();
+       LED_D_OFF();
+
+       lf_av= ReadAdc(ADC_CHAN_LF);
+
+       if(limit != HF_ONLY) 
+               {
+               DbpString("LF 125/134 Baseline:");
+               DbpIntegers(lf_av,0,0);
+               lf_baseline= lf_av;
+               }
+
+       hf_av= ReadAdc(ADC_CHAN_HF);
+
+
+       if (limit != LF_ONLY) 
+               {
+               DbpString("HF 13.56 Baseline:");
+               DbpIntegers(hf_av,0,0);
+               hf_baseline= hf_av;
+               }
+
+       for(;;) 
+               {
+               if(BUTTON_PRESS()) 
+                       {
+                       DbpString("Stopped");
+                       LED_B_OFF();
+                       LED_D_OFF();
+                       return;
+                       }
+               WDT_HIT();
+
+
+               if (limit != HF_ONLY) 
+                       {
+                       if (abs(lf_av - lf_baseline) > 10)
+                               LED_D_ON();
+                       else
+                               LED_D_OFF();
+                       ++lf_count;
+                       lf_av_new= ReadAdc(ADC_CHAN_LF);
+                       // see if there's a significant change
+                       if(abs(lf_av - lf_av_new) > 10) 
+                               {
+                               DbpString("LF 125/134 Field Change:");
+                               DbpIntegers(lf_av,lf_av_new,lf_count);
+                               lf_av= lf_av_new;
+                               lf_count= 0;
+                               }
+                       }
+
+               if (limit != LF_ONLY) 
+                       {
+                       if (abs(hf_av - hf_baseline) > 10)
+                               LED_B_ON();
+                       else
+                               LED_B_OFF();
+                       ++hf_count;
+                       hf_av_new= ReadAdc(ADC_CHAN_HF);
+                       // see if there's a significant change
+                       if(abs(hf_av - hf_av_new) > 10) 
+                               {
+                               DbpString("HF 13.56 Field Change:");
+                               DbpIntegers(hf_av,hf_av_new,hf_count);
+                               hf_av= hf_av_new;
+                               hf_count= 0;
+                               }
+                       }
+               }
+}
Impressum, Datenschutz