X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/850427c8a939d79ff4df01982687a7ab1d8fd2d5..72c4af087f2950bb445ae0c9c439724efe9a0d0e:/armsrc/appmain.c diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 6273317e..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)); @@ -202,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; @@ -250,9 +276,9 @@ void SimulateTagHfListen(void) void ReadMem(int addr) { - const DWORD *data = ((DWORD *)addr); + const BYTE *data = ((BYTE *)addr); - Dbprintf("Reading memory at address %x: %02x %02x %02x %02x %02x %02x %02x %02x", + 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]); } @@ -544,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 @@ -575,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: @@ -643,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; @@ -693,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 @@ -769,7 +804,7 @@ void UsbPacketReceived(BYTE *packet, int len) } break; default: - DbpString("unknown command"); + Dbprintf("%s: 0x%04x","unknown command:",c->cmd); break; } }