X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/da198be4b5ae28a3d1c711b31081aba5af33ed6d..aaa1a9a2dcb8b9f2b6acd937f84464daa50ecad6:/armsrc/appmain.c diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 3dfa5267..2ba3d75c 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -22,7 +22,8 @@ #include #include "legicrf.h" -#include +#include "hitag2.h" +#include "hitagS.h" #include "lfsampling.h" #include "BigBuf.h" #include "mifareutil.h" @@ -79,16 +80,31 @@ void ToSendStuffBit(int b) { // Debug print functions, to go out over USB, to the usual PC-side client. //============================================================================= +void DbpStringEx(char *str, uint32_t cmd){ + byte_t len = strlen(str); + cmd_send(CMD_DEBUG_PRINT_STRING,len, cmd,0,(byte_t*)str,len); +} + void DbpString(char *str) { - byte_t len = strlen(str); - cmd_send(CMD_DEBUG_PRINT_STRING,len,0,0,(byte_t*)str,len); + DbpStringEx(str, 0); } #if 0 void DbpIntegers(int x1, int x2, int x3) { - cmd_send(CMD_DEBUG_PRINT_INTEGERS,x1,x2,x3,0,0); + cmd_send(CMD_DEBUG_PRINT_INTEGERS,x1,x2,x3,0,0); } #endif +void DbprintfEx(uint32_t cmd, const char *fmt, ...) { + // should probably limit size here; oh well, let's just use a big buffer + char output_string[128] = {0x00}; + va_list ap; + + va_start(ap, fmt); + kvsprintf(fmt, output_string, 10, ap); + va_end(ap); + + DbpStringEx(output_string, cmd); +} void Dbprintf(const char *fmt, ...) { // should probably limit size here; oh well, let's just use a big buffer @@ -228,23 +244,18 @@ void MeasureAntennaTuning(void) { void MeasureAntennaTuningHf(void) { int vHf = 0; // in mV - - DbpString("Measuring HF antenna, press button to exit"); - // Let the FPGA drive the high-frequency antenna around 13.56 MHz. FpgaDownloadAndGo(FPGA_BITSTREAM_HF); FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR); - for (;;) { + while ( !BUTTON_PRESS() ){ SpinDelay(20); vHf = (MAX_ADC_HF_VOLTAGE * AvgAdc(ADC_CHAN_HF)) >> 10; - - Dbprintf("%d mV",vHf); - if (BUTTON_PRESS()) break; + //Dbprintf("%d mV",vHf); + DbprintfEx(CMD_MEASURE_ANTENNA_TUNING_HF, "%d mV",vHf); } - - DbpString("cancelled"); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); + DbpString("cancelled"); } @@ -651,7 +662,7 @@ void SamyRun() SpinDelay(500); CmdHIDdemodFSK(1, &high[selected], &low[selected], 0); - Dbprintf("Recorded %x %x %x", selected, high[selected], low[selected]); + Dbprintf("Recorded %x %x %08x", selected, high[selected], low[selected]); LEDsoff(); LED(selected + 1, 0); @@ -667,7 +678,7 @@ void SamyRun() LED(LED_ORANGE, 0); // record - Dbprintf("Cloning %x %x %x", selected, high[selected], low[selected]); + Dbprintf("Cloning %x %x %08x", selected, high[selected], low[selected]); // wait for button to be released while(BUTTON_PRESS()) @@ -676,8 +687,8 @@ void SamyRun() /* need this delay to prevent catching some weird data */ SpinDelay(500); - CopyHIDtoT55x7(high[selected], low[selected], 0, 0); - Dbprintf("Cloned %x %x %x", selected, high[selected], low[selected]); + CopyHIDtoT55x7(0, high[selected], low[selected], 0); + Dbprintf("Cloned %x %x %08x", selected, high[selected], low[selected]); LEDsoff(); LED(selected + 1, 0); @@ -708,7 +719,7 @@ void SamyRun() while(BUTTON_PRESS()) WDT_HIT(); - Dbprintf("%x %x %x", selected, high[selected], low[selected]); + Dbprintf("%x %x %08x", selected, high[selected], low[selected]); CmdHIDsimTAG(high[selected], low[selected], 0); DbpString("Done playing"); @@ -996,6 +1007,18 @@ void UsbPacketReceived(uint8_t *packet, int len) case CMD_READER_HITAG: // Reader for Hitag tags, args = type and function ReaderHitag((hitag_function)c->arg[0],(hitag_data*)c->d.asBytes); break; + case CMD_SIMULATE_HITAG_S:// Simulate Hitag s tag, args = memory content + SimulateHitagSTag((bool)c->arg[0],(byte_t*)c->d.asBytes); + break; + case CMD_TEST_HITAGS_TRACES:// Tests every challenge within the given file + check_challenges((bool)c->arg[0],(byte_t*)c->d.asBytes); + break; + case CMD_READ_HITAG_S://Reader for only Hitag S tags, args = key or challenge + ReadHitagS((hitag_function)c->arg[0],(hitag_data*)c->d.asBytes); + break; + case CMD_WR_HITAG_S://writer for Hitag tags args=data to write,page and key or challenge + WritePageHitagS((hitag_function)c->arg[0],(hitag_data*)c->d.asBytes,c->arg[2]); + break; #endif #ifdef WITH_ISO15693 @@ -1251,8 +1274,7 @@ void UsbPacketReceived(uint8_t *packet, int len) LED_D_OFF(); // LED D indicates field ON or OFF break; - case CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K: - + case CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K: { LED_B_ON(); uint8_t *BigBuf = BigBuf_get_addr(); size_t len = 0; @@ -1264,13 +1286,26 @@ void UsbPacketReceived(uint8_t *packet, int len) cmd_send(CMD_ACK,1,0,BigBuf_get_traceLen(),getSamplingConfig(),sizeof(sample_config)); LED_B_OFF(); break; - + } case CMD_DOWNLOADED_SIM_SAMPLES_125K: { uint8_t *b = BigBuf_get_addr(); - memcpy(b+c->arg[0], c->d.asBytes, USB_CMD_DATA_SIZE); + memcpy( b + c->arg[0], c->d.asBytes, USB_CMD_DATA_SIZE); cmd_send(CMD_ACK,0,0,0,0,0); break; - } + } + case CMD_DOWNLOAD_EML_BIGBUF: { + LED_B_ON(); + uint8_t *cardmem = BigBuf_get_EM_addr(); + size_t len = 0; + for(size_t i=0; i < c->arg[1]; i += USB_CMD_DATA_SIZE) { + len = MIN((c->arg[1] - i), USB_CMD_DATA_SIZE); + cmd_send(CMD_DOWNLOADED_EML_BIGBUF, i, len, CARD_MEMORY_SIZE, cardmem + c->arg[0] + i, len); + } + // Trigger a finish downloading signal with an ACK frame + cmd_send(CMD_ACK, 1, 0, CARD_MEMORY_SIZE, 0, 0); + LED_B_OFF(); + break; + } case CMD_READ_MEM: ReadMem(c->arg[0]); break;