]> cvs.zerfleddert.de Git - proxmark3-svn/commitdiff
FIX: 'lf awid bruteforce' cleaning up all debug messages
authoriceman1001 <iceman@iuse.se>
Fri, 26 Aug 2016 14:35:30 +0000 (16:35 +0200)
committericeman1001 <iceman@iuse.se>
Fri, 26 Aug 2016 14:35:30 +0000 (16:35 +0200)
armsrc/appmain.c
armsrc/lfops.c
client/cmdlfawid.c

index 14ecf28f8d15643fb7c73b491762d8cd631c5c36..aa873e42263bba0da28815a9328e06c0abefe93a 100644 (file)
@@ -191,11 +191,12 @@ int AvgAdc(int ch) // was static - merlok
        return (a + 15) >> 5;
 }
 
+
 void MeasureAntennaTuning(void) {
-       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
 
+       uint8_t* LF_Results = BigBuf_malloc(256);
+       int i, adcval = 0, peak = 0, peakv = 0, peakf = 0;
+       int vLf125 = 0, vLf134 = 0, vHf = 0;    // in mV
        LED_B_ON();
 
 /*
@@ -210,7 +211,7 @@ void MeasureAntennaTuning(void) {
        FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
        FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
 
-       for (i=255; i>=19; i--) {
+       for  (i = 255; i >= 19; i--) {
                WDT_HIT();
                FpgaSendCommand(FPGA_CMD_SET_DIVISOR, i);
                SpinDelay(20);
@@ -223,11 +224,10 @@ void MeasureAntennaTuning(void) {
                        peakv = adcval;
                        peak = LF_Results[i];
                        peakf = 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();
        // Let the FPGA drive the high-frequency antenna around 13.56 MHz.
@@ -239,6 +239,7 @@ void MeasureAntennaTuning(void) {
        cmd_send(CMD_MEASURED_ANTENNA_TUNING, vLf125 | (vLf134<<16), vHf, peakf | (peakv<<16), LF_Results, 256);
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
 
+       BigBuf_free(); BigBuf_Clear_ext(false);
        LEDsoff();
 }
 
@@ -899,7 +900,7 @@ void UsbPacketReceived(uint8_t *packet, int len)
 {
        UsbCommand *c = (UsbCommand *)packet;
 
-  //Dbprintf("received %d bytes, with command: 0x%04x and args: %d %d %d",len,c->cmd,c->arg[0],c->arg[1],c->arg[2]);
+       //Dbprintf("received %d bytes, with command: 0x%04x and args: %d %d %d",len,c->cmd,c->arg[0],c->arg[1],c->arg[2]);
   
        switch(c->cmd) {
 #ifdef WITH_LF
@@ -952,7 +953,7 @@ void UsbPacketReceived(uint8_t *packet, int len)
                        WriteTItag(c->arg[0],c->arg[1],c->arg[2]);
                        break;
                case CMD_SIMULATE_TAG_125K:
-                       LED_A_ON();
+                       LED_A_ON();             
                        SimulateTagLowFrequency(c->arg[0], c->arg[1], 1);
                        LED_A_OFF();
                        break;
@@ -1055,15 +1056,15 @@ void UsbPacketReceived(uint8_t *packet, int len)
                        break;
 
                case CMD_WRITER_LEGIC_RF:
-                       LegicRfWriter(c->arg[1], c->arg[0]);
+                       LegicRfWriter( c->arg[0], c->arg[1], c->arg[2]);
                        break;
 
                case CMD_RAW_WRITER_LEGIC_RF:
-                       LegicRfRawWriter(c->arg[0], c->arg[1]);
+                       LegicRfRawWriter(c->arg[0], c->arg[1], c->arg[2]);
                        break;
 
                case CMD_READER_LEGIC_RF:
-                       LegicRfReader(c->arg[0], c->arg[1]);
+                       LegicRfReader(c->arg[0], c->arg[1], c->arg[2]);
                        break;
 #endif
 
@@ -1385,10 +1386,7 @@ void  __attribute__((noreturn)) AppMain(void)
        }
        common_area.flags.osimage_present = 1;
 
-       LED_D_OFF();
-       LED_C_OFF();
-       LED_B_OFF();
-       LED_A_OFF();
+       LEDsoff();
 
        // Init USB device
        usb_enable();
@@ -1398,8 +1396,7 @@ void  __attribute__((noreturn)) AppMain(void)
        AT91C_BASE_PIOA->PIO_PDR = GPIO_PCK0;
        AT91C_BASE_PMC->PMC_SCER = AT91C_PMC_PCK0;
        // PCK0 is PLL clock / 4 = 96Mhz / 4 = 24Mhz
-       AT91C_BASE_PMC->PMC_PCKR[0] = AT91C_PMC_CSS_PLL_CLK |
-               AT91C_PMC_PRES_CLK_4; //  4 for 24Mhz pck0, 2 for 48 MHZ pck0
+       AT91C_BASE_PMC->PMC_PCKR[0] = AT91C_PMC_CSS_PLL_CLK | AT91C_PMC_PRES_CLK_4; //  4 for 24Mhz pck0, 2 for 48 MHZ pck0
        AT91C_BASE_PIOA->PIO_OER = GPIO_PCK0;
 
        // Reset SPI
@@ -1421,10 +1418,11 @@ void  __attribute__((noreturn)) AppMain(void)
        size_t rx_len;
   
        for(;;) {
-               if (usb_poll()) {
-                       rx_len = usb_read(rx,sizeof(UsbCommand));
+               if ( usb_poll_validate_length() ) {
+                       rx_len = usb_read(rx, sizeof(UsbCommand));
+                       
                        if (rx_len)
-                               UsbPacketReceived(rx,rx_len);
+                               UsbPacketReceived(rx, rx_len);
                }
                WDT_HIT();
 
index 8b7e98fc2e31b7cd27b2d9c23f3f588abf7f899b..1f1e48ee614068f8e464198c148c3fabcd364852 100644 (file)
 #include "protocols.h"
 #include "usb_cdc.h" // for usb_poll_validate_length
 
+#ifndef SHORT_COIL
+# define SHORT_COIL()  LOW(GPIO_SSC_DOUT)
+#endif
+#ifndef OPEN_COIL
+# define OPEN_COIL()   HIGH(GPIO_SSC_DOUT)
+#endif
+
 /**
  * Function to do a modulation and then get samples.
  * @param delay_off
@@ -383,31 +390,30 @@ void WriteTItag(uint32_t idhi, uint32_t idlo, uint16_t crc)
 
 void SimulateTagLowFrequency(int period, int gap, int ledcontrol)
 {
-       int i;
+       int i = 0;
        uint8_t *tab = BigBuf_get_addr();
 
-       FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
-       FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT);
+       FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT | FPGA_LF_EDGE_DETECT_READER_FIELD);
 
        AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DOUT | GPIO_SSC_CLK;
        AT91C_BASE_PIOA->PIO_OER = GPIO_SSC_DOUT;
        AT91C_BASE_PIOA->PIO_ODR = GPIO_SSC_CLK;
 
- #define SHORT_COIL()  LOW(GPIO_SSC_DOUT)
- #define OPEN_COIL()   HIGH(GPIO_SSC_DOUT)
-
-       i = 0;
        for(;;) {
+               WDT_HIT();
+
+               if (ledcontrol) LED_D_ON();
+                               
                //wait until SSC_CLK goes HIGH
                while(!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)) {
-                       if(BUTTON_PRESS() || usb_poll_validate_length() ) {
-                               DbpString("Stopped");
-                               return;
-                       }
                        WDT_HIT();
+                       if ( usb_poll_validate_length() || BUTTON_PRESS() ) {
+                               FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
+                               LED_D_OFF();
+                               return;                         
+                       }
                }
-               if (ledcontrol) LED_D_ON();
-
+               
                if(tab[i])
                        OPEN_COIL();
                else
@@ -417,20 +423,21 @@ void SimulateTagLowFrequency(int period, int gap, int ledcontrol)
                
                //wait until SSC_CLK goes LOW
                while(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK) {
-                       if( BUTTON_PRESS() || usb_poll_validate_length() ) {
-                               DbpString("Stopped");
-                               return;
-                       }
                        WDT_HIT();
+                       if ( usb_poll_validate_length() || BUTTON_PRESS() ) {
+                               FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
+                               LED_D_OFF();
+                               return;                         
+                       }
                }
 
                i++;
                if(i == period) {
-
                        i = 0;
                        if (gap) {
+                               WDT_HIT();
                                SHORT_COIL();
-                               SpinDelayUs(gap);
+                               SpinDelayUs(gap);                               
                        }
                }
        }
@@ -524,7 +531,10 @@ static void fcAll(uint8_t fc, int *n, uint8_t clock, uint16_t *modCnt)
 // simulate a HID tag until the button is pressed
 void CmdHIDsimTAG(int hi, int lo, int ledcontrol)
 {
-       int n=0, i=0;
+       FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
+       set_tracing(FALSE);
+               
+       int n = 0, i = 0;
        /*
         HID tag bitstream format
         The tag contains a 44bit unique code. This is sent out MSB first in sets of 4 bits
@@ -535,7 +545,7 @@ void CmdHIDsimTAG(int hi, int lo, int ledcontrol)
         nor 1 bits, they are special patterns (a = set of 12 fc8 and b = set of 10 fc10)
        */
 
-       if (hi>0xFFF) {
+       if (hi > 0xFFF) {
                DbpString("Tags can only have 44 bits. - USE lf simfsk for larger tags");
                return;
        }
@@ -567,7 +577,8 @@ void CmdHIDsimTAG(int hi, int lo, int ledcontrol)
                        fc(8,  &n); fc(10, &n);         // high-low transition
                }
        }
-
+       WDT_HIT();
+       
        if (ledcontrol) LED_A_ON();
        SimulateTagLowFrequency(n, 0, ledcontrol);
        if (ledcontrol) LED_A_OFF();
@@ -578,8 +589,14 @@ void CmdHIDsimTAG(int hi, int lo, int ledcontrol)
 // arg1 contains fcHigh and fcLow, arg2 contains invert and clock
 void CmdFSKsimTAG(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream)
 {
-       int ledcontrol=1;
-       int n=0, i=0;
+       FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
+
+       // free eventually allocated BigBuf memory
+       BigBuf_free(); BigBuf_Clear_ext(false);
+       clear_trace();
+       set_tracing(FALSE);
+       
+       int ledcontrol = 1, n = 0, i = 0;
        uint8_t fcHigh = arg1 >> 8;
        uint8_t fcLow = arg1 & 0xFF;
        uint16_t modCnt = 0;
@@ -587,13 +604,15 @@ void CmdFSKsimTAG(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream)
        uint8_t invert = (arg2 >> 8) & 1;
 
        for (i=0; i<size; i++){
-               if (BitStream[i] == invert){
+               
+               if (BitStream[i] == invert)
                        fcAll(fcLow, &n, clk, &modCnt);
-               } else {
+               else
                        fcAll(fcHigh, &n, clk, &modCnt);
-               }
        }
-       Dbprintf("Simulating with fcHigh: %d, fcLow: %d, clk: %d, invert: %d, n: %d",fcHigh, fcLow, clk, invert, n);
+       WDT_HIT();
+       
+       Dbprintf("Simulating with fcHigh: %d, fcLow: %d, clk: %d, invert: %d, n: %d", fcHigh, fcLow, clk, invert, n);
 
        if (ledcontrol) LED_A_ON();
        SimulateTagLowFrequency(n, 0, ledcontrol);
@@ -644,19 +663,21 @@ static void stAskSimBit(int *n, uint8_t clock) {
 // args clock, ask/man or askraw, invert, transmission separator
 void CmdASKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream)
 {
-       int ledcontrol = 1;
-       int n=0, i=0;
+       FpgaDownloadAndGo(FPGA_BITSTREAM_LF);   
+       set_tracing(FALSE);
+       
+       int ledcontrol = 1, n = 0, i = 0;
        uint8_t clk = (arg1 >> 8) & 0xFF;
        uint8_t encoding = arg1 & 0xFF;
        uint8_t separator = arg2 & 1;
        uint8_t invert = (arg2 >> 8) & 1;
 
-       if (encoding==2){  //biphase
-               uint8_t phase=0;
+       if (encoding == 2){  //biphase
+               uint8_t phase = 0;
                for (i=0; i<size; i++){
                        biphaseSimBit(BitStream[i]^invert, &n, clk, &phase);
                }
-               if (phase==1) { //run a second set inverted to keep phase in check
+               if (phase == 1) { //run a second set inverted to keep phase in check
                        for (i=0; i<size; i++){
                                biphaseSimBit(BitStream[i]^invert, &n, clk, &phase);
                        }
@@ -676,6 +697,8 @@ void CmdASKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream)
        else if (separator==1)
                Dbprintf("sorry but separator option not yet available");
 
+       WDT_HIT();
+       
        Dbprintf("Simulating with clk: %d, invert: %d, encoding: %d, separator: %d, n: %d",clk, invert, encoding, separator, n);
 
        if (ledcontrol) LED_A_ON();
@@ -709,8 +732,10 @@ static void pskSimBit(uint8_t waveLen, int *n, uint8_t clk, uint8_t *curPhase, b
 // args clock, carrier, invert,
 void CmdPSKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream)
 {
-       int ledcontrol = 1;
-       int n=0, i=0;
+       FpgaDownloadAndGo(FPGA_BITSTREAM_LF);   
+       set_tracing(FALSE);
+       
+       int ledcontrol = 1, n = 0, i = 0;
        uint8_t clk = arg1 >> 8;
        uint8_t carrier = arg1 & 0xFF;
        uint8_t invert = arg2 & 0xFF;
@@ -722,6 +747,9 @@ void CmdPSKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream)
                        pskSimBit(carrier, &n, clk, &curPhase, TRUE);
                }
        }
+       
+       WDT_HIT();
+       
        Dbprintf("Simulating with Carrier: %d, clk: %d, invert: %d, n: %d",carrier, clk, invert, n);
                   
        if (ledcontrol) LED_A_ON();
index 2334e3e3321ffba7ded59066a8ae37d167f22650..bddd94af5a1bfb3347b53c7b935f33ccf820ee28 100644 (file)
@@ -84,6 +84,20 @@ int usage_lf_awid_brute(void){
        return 0;
 }
 
+static int sendPing(void){
+       UsbCommand ping = {CMD_PING, {1, 2, 3}};
+       SendCommand(&ping);
+       SendCommand(&ping);     
+       SendCommand(&ping);
+       
+       clearCommandBuffer();
+       UsbCommand resp;
+       if (WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {
+               return 0;
+       }
+       return 1;
+}
+
 static bool sendTry(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint32_t delay, uint8_t *bs, size_t bs_len){
 
        PrintAndLog("Trying FC: %u; CN: %u", fc, cn);           
@@ -98,22 +112,12 @@ static bool sendTry(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint32_t delay, ui
        memcpy(c.d.asBytes, bs, bs_len);
        clearCommandBuffer();
        SendCommand(&c);
+
        msleep(delay);
+       sendPing();
        return TRUE;
 }
-static int sendPing(){
-       UsbCommand resp;
-       UsbCommand ping = {CMD_PING};
-       clearCommandBuffer(); SendCommand(&ping);
-       clearCommandBuffer(); SendCommand(&ping);
-       clearCommandBuffer(); SendCommand(&ping);
-       if (WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {
-               PrintAndLog("aborted via keyboard!");
-               return 0;
-       }
-       PrintAndLog("Device didnt respond to ABORT");   
-       return 1;
-}
+
 
 int CmdAWIDDemodFSK(const char *Cmd) {
        int findone = 0;
@@ -367,6 +371,11 @@ int CmdAWIDBrute(const char *Cmd){
        
        for (;;){
        
+               if ( offline ) {
+                       printf("Device offline\n");
+                       return  2;
+               }
+               
                if (ukbhit()) return sendPing();
                
                // Do one up
Impressum, Datenschutz