X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/850427c8a939d79ff4df01982687a7ab1d8fd2d5..040a7baad0fa7c2901e44e5f5f63f0918d29ae97:/armsrc/appmain.c diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 6273317e..e5cd16b7 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -26,7 +26,7 @@ int kvsprintf(char const *fmt, void *arg, int radix, va_list ap); // 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 +34,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 +76,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 +205,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 +274,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 +568,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 @@ -643,6 +670,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 +724,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 +802,7 @@ void UsbPacketReceived(BYTE *packet, int len) } break; default: - DbpString("unknown command"); + Dbprintf("%s: 0x%04x","unknown command:",c->cmd); break; } }