X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/a9bc033bdd5bad5dcba73c55ee337bade1540d6a..72c4af087f2950bb445ae0c9c439724efe9a0d0e:/armsrc/appmain.c diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 8d6c1812..b517fa6c 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -6,7 +6,6 @@ //----------------------------------------------------------------------------- #include -#include #include "apps.h" #include "legicrf.h" #ifdef WITH_LCD @@ -20,13 +19,16 @@ #define va_end __builtin_va_end int kvsprintf(char const *fmt, void *arg, int radix, va_list ap); + +#define abs(x) ( ((x)<0) ? -(x) : (x) ) + //============================================================================= // A buffer where we can queue things up to be sent through the FPGA, for // any purpose (fake tag, as reader, whatever). We go MSB first, since that // is the order in which they go out on the wire. //============================================================================= -BYTE ToSend[256]; +BYTE ToSend[512]; int ToSendMax; static int ToSendBit; struct common_area common_area __attribute__((section(".commonarea"))); @@ -34,7 +36,7 @@ struct common_area common_area __attribute__((section(".commonarea"))); void BufferClear(void) { memset(BigBuf,0,sizeof(BigBuf)); - DbpString("Buffer cleared"); + Dbprintf("Buffer cleared (%i bytes)",sizeof(BigBuf)); } void ToSendReset(void) @@ -76,6 +78,9 @@ void DbpString(char *str) UsbCommand c; c.cmd = CMD_DEBUG_PRINT_STRING; c.arg[0] = strlen(str); + if(c.arg[0] > sizeof(c.d.asBytes)) { + c.arg[0] = sizeof(c.d.asBytes); + } memcpy(c.d.asBytes, str, c.arg[0]); UsbSendPacket((BYTE *)&c, sizeof(c)); @@ -83,6 +88,7 @@ void DbpString(char *str) SpinDelay(50); } +#if 0 void DbpIntegers(int x1, int x2, int x3) { /* this holds up stuff unless we're connected to usb */ @@ -99,6 +105,7 @@ void DbpIntegers(int x1, int x2, int x3) // XXX SpinDelay(50); } +#endif void Dbprintf(const char *fmt, ...) { // should probably limit size here; oh well, let's just use a big buffer @@ -200,6 +207,27 @@ void MeasureAntennaTuning(void) UsbSendPacket((BYTE *)&c, sizeof(c)); } +void MeasureAntennaTuningHf(void) +{ + int vHf = 0; // in mV + + DbpString("Measuring HF antenna, press button to exit"); + + for (;;) { + // Let the FPGA drive the high-frequency antenna around 13.56 MHz. + FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR); + SpinDelay(20); + // Vref = 3300mV, and an 10:1 voltage divider on the input + // can measure voltages up to 33000 mV + vHf = (33000 * AvgAdc(ADC_CHAN_HF)) >> 10; + + Dbprintf("%d mV",vHf); + if (BUTTON_PRESS()) break; + } + DbpString("cancelled"); +} + + void SimulateTagHfListen(void) { BYTE *dest = (BYTE *)BigBuf; @@ -248,13 +276,10 @@ void SimulateTagHfListen(void) void ReadMem(int addr) { - const DWORD *data = ((DWORD *)addr); - int i; + const BYTE *data = ((BYTE *)addr); - DbpString("Reading memory at address"); - DbpIntegers(0, 0, addr); - for (i = 0; i < 8; i+= 2) - DbpIntegers(0, data[i], data[i+1]); + Dbprintf("%x: %02x %02x %02x %02x %02x %02x %02x %02x", + addr, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]); } /* osimage version information is linked in */ @@ -340,8 +365,7 @@ void SamyRun() SpinDelay(500); CmdHIDdemodFSK(1, &high[selected], &low[selected], 0); - DbpString("Recorded"); - DbpIntegers(selected, high[selected], low[selected]); + Dbprintf("Recorded %x %x %x", selected, high[selected], low[selected]); LEDsoff(); LED(selected + 1, 0); @@ -371,7 +395,7 @@ void SamyRun() // wait for button to be released while(BUTTON_PRESS()) WDT_HIT(); - DbpIntegers(selected, high[selected], low[selected]); + Dbprintf("%x %x %x", selected, high[selected], low[selected]); CmdHIDsimTAG(high[selected], low[selected], 0); DbpString("Done playing"); if (BUTTON_HELD(1000) > 0) @@ -449,17 +473,15 @@ void ListenReaderField(int limit) lf_av=lf_max=ReadAdc(ADC_CHAN_LF); if(limit != HF_ONLY) { - DbpString("LF 125/134 Baseline:"); - DbpIntegers(lf_av,0,0); - lf_baseline= lf_av; + Dbprintf("LF 125/134 Baseline: %d", lf_av); + lf_baseline = lf_av; } hf_av=hf_max=ReadAdc(ADC_CHAN_HF); if (limit != LF_ONLY) { - DbpString("HF 13.56 Baseline:"); - DbpIntegers(hf_av,0,0); - hf_baseline= hf_av; + Dbprintf("HF 13.56 Baseline: %d", hf_av); + hf_baseline = hf_av; } for(;;) { @@ -490,9 +512,8 @@ void ListenReaderField(int limit) 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; + Dbprintf("LF 125/134 Field Change: %x %x %x", lf_av, lf_av_new, lf_count); + lf_av = lf_av_new; if (lf_av > lf_max) lf_max = lf_av; lf_count= 0; @@ -509,9 +530,8 @@ void ListenReaderField(int limit) 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; + Dbprintf("HF 13.56 Field Change: %x %x %x", hf_av, hf_av_new, hf_count); + hf_av = hf_av_new; if (hf_av > hf_max) hf_max = hf_av; hf_count= 0; @@ -550,11 +570,14 @@ void ListenReaderField(int limit) void UsbPacketReceived(BYTE *packet, int len) { UsbCommand *c = (UsbCommand *)packet; + UsbCommand ack; + ack.cmd = CMD_ACK; switch(c->cmd) { #ifdef WITH_LF case CMD_ACQUIRE_RAW_ADC_SAMPLES_125K: AcquireRawAdcSamples125k(c->arg[0]); + UsbSendPacket((BYTE*)&ack, sizeof(ack)); break; #endif @@ -581,8 +604,8 @@ void UsbPacketReceived(BYTE *packet, int len) #endif case CMD_READER_LEGIC_RF: - LegicRfReader(); - break; + LegicRfReader(c->arg[0], c->arg[1]); + break; #ifdef WITH_ISO15693 case CMD_SIMTAG_ISO_15693: @@ -649,6 +672,10 @@ void UsbPacketReceived(BYTE *packet, int len) MeasureAntennaTuning(); break; + case CMD_MEASURE_ANTENNA_TUNING_HF: + MeasureAntennaTuningHf(); + break; + case CMD_LISTEN_READER_FIELD: ListenReaderField(c->arg[0]); break; @@ -699,13 +726,15 @@ void UsbPacketReceived(BYTE *packet, int len) case CMD_DOWNLOADED_SIM_SAMPLES_125K: { BYTE *b = (BYTE *)BigBuf; memcpy(b+c->arg[0], c->d.asBytes, 48); + //Dbprintf("copied 48 bytes to %i",b+c->arg[0]); + UsbSendPacket((BYTE*)&ack, sizeof(ack)); break; } #ifdef WITH_LF case CMD_SIMULATE_TAG_125K: LED_A_ON(); - SimulateTagLowFrequency(c->arg[0], 1); + SimulateTagLowFrequency(c->arg[0], c->arg[1], 1); LED_A_OFF(); break; #endif @@ -775,7 +804,7 @@ void UsbPacketReceived(BYTE *packet, int len) } break; default: - DbpString("unknown command"); + Dbprintf("%s: 0x%04x","unknown command:",c->cmd); break; } }