proxmark3/armsrc/hfsnoop.c

80 lines
2.3 KiB
C
Raw Normal View History

#include "proxmark3.h"
#include "apps.h"
#include "BigBuf.h"
#include "util.h"
2019-03-10 03:34:41 +08:00
#include "usb_cdc.h" // for usb_poll_validate_length
2019-03-12 20:15:39 +08:00
static void RAMFUNC optimizedSniff(void);
2019-03-12 20:15:39 +08:00
static void RAMFUNC optimizedSniff(void) {
2019-03-10 03:34:41 +08:00
int n = BigBuf_max_traceLen() / sizeof(uint16_t); // take all memory
2019-03-10 03:34:41 +08:00
uint16_t *dest = (uint16_t *)BigBuf_get_addr();
2019-03-10 07:00:59 +08:00
uint16_t *destend = dest + n - 1;
2019-03-10 03:34:41 +08:00
// Reading data loop
2019-03-10 07:00:59 +08:00
while (dest <= destend) {
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
2019-03-10 03:34:41 +08:00
*dest = (uint16_t)(AT91C_BASE_SSC->SSC_RHR);
dest++;
}
}
2019-03-09 18:51:46 +08:00
//setting tracelen - important! it was set by buffer overflow before
2019-03-10 07:00:59 +08:00
set_tracelen(BigBuf_max_traceLen());
}
2019-03-12 20:15:39 +08:00
void HfSniff(int samplesToSkip, int triggersToSkip) {
2019-03-10 07:00:59 +08:00
BigBuf_free();
BigBuf_Clear();
2019-03-10 03:34:41 +08:00
Dbprintf("Skipping first %d sample pairs, Skipping %d triggers.\n", samplesToSkip, triggersToSkip);
int trigger_cnt = 0;
2019-03-10 03:34:41 +08:00
LED_D_ON();
2019-03-10 03:34:41 +08:00
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
2019-03-10 03:34:41 +08:00
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
2019-03-10 03:34:41 +08:00
// Set up the synchronous serial port
FpgaSetupSsc();
2019-03-10 03:34:41 +08:00
// Setting Frame Mode For better performance on high speed data transfer.
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(16);
2019-03-10 03:34:41 +08:00
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SNOOP);
SpinDelay(100);
2019-03-10 03:34:41 +08:00
uint16_t r = 0;
2019-03-10 07:00:59 +08:00
while (!BUTTON_PRESS() && !usb_poll_validate_length()) {
2019-03-10 03:34:41 +08:00
WDT_HIT();
2019-03-10 03:34:41 +08:00
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
r = (uint16_t)AT91C_BASE_SSC->SSC_RHR;
r = MAX(r & 0xff, r >> 8);
if (r >= 180) { // 0xB4 ??
if (++trigger_cnt > triggersToSkip)
2019-03-10 07:00:59 +08:00
break;
2019-03-10 03:34:41 +08:00
}
}
}
if (!BUTTON_PRESS()) {
int waitcount = samplesToSkip; // lets wait 40000 ticks of pck0
2019-03-10 07:00:59 +08:00
while (waitcount != 0) {
2019-03-10 03:34:41 +08:00
2019-03-10 07:00:59 +08:00
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY))
2019-03-10 03:34:41 +08:00
waitcount--;
}
2019-03-12 20:15:39 +08:00
optimizedSniff();
2019-03-10 03:34:41 +08:00
Dbprintf("Trigger kicked! Value: %d, Dumping Samples Hispeed now.", r);
}
//Resetting Frame mode (First set in fpgaloader.c)
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(8) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0);
2019-03-12 20:15:39 +08:00
DbpString("HF Sniffing end");
2019-03-10 03:34:41 +08:00
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
LED_D_OFF();
}