From: iceman1001 Date: Fri, 26 Aug 2016 14:35:30 +0000 (+0200) Subject: FIX: 'lf awid bruteforce' cleaning up all debug messages X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/f121b478a11894a42f0fdab127974e1e7d521cc3?ds=inline FIX: 'lf awid bruteforce' cleaning up all debug messages --- diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 14ecf28f..aa873e42 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -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(); diff --git a/armsrc/lfops.c b/armsrc/lfops.c index 8b7e98fc..1f1e48ee 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -19,6 +19,13 @@ #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> 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> 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(); diff --git a/client/cmdlfawid.c b/client/cmdlfawid.c index 2334e3e3..bddd94af 100644 --- a/client/cmdlfawid.c +++ b/client/cmdlfawid.c @@ -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