From: Martin Holst Swende Date: Wed, 21 Jan 2015 22:53:40 +0000 (+0100) Subject: Generic tracing pt.3 : reworking how iso14443b-traces are stored in ARM-memory X-Git-Tag: v2.0.0-rc1~23^2~12 X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/9e8255d4e99eb2917df13be92402e75a73417696?ds=inline Generic tracing pt.3 : reworking how iso14443b-traces are stored in ARM-memory --- diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 530dc39c..bca31533 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -986,7 +986,7 @@ void UsbPacketReceived(uint8_t *packet, int len) void __attribute__((noreturn)) AppMain(void) { SpinDelay(100); - + clear_trace(); if(common_area.magic != COMMON_AREA_MAGIC || common_area.version != 1) { /* Initialize common area */ memset(&common_area, 0, sizeof(common_area)); diff --git a/armsrc/iso14443.c b/armsrc/iso14443.c index 4d7d4fa8..3c8e1fdd 100644 --- a/armsrc/iso14443.c +++ b/armsrc/iso14443.c @@ -628,30 +628,26 @@ static void GetSamplesFor14443Demod(int weTx, int n, int quiet) int max = 0; int gotFrame = FALSE; -//# define DMA_BUFFER_SIZE 8 - int8_t *dmaBuf; - int lastRxCounter; - int8_t *upTo; int ci, cq; int samples = 0; // Clear out the state of the "UART" that receives from the tag. - memset(BigBuf, 0x00, 400); - Demod.output = (uint8_t *)BigBuf; + memset(Demod.output, 0x00, MAX_FRAME_SIZE); + Demod.output = ((uint8_t *)BigBuf) + RECV_RESP_OFFSET; Demod.len = 0; Demod.state = DEMOD_UNSYNCD; // And the UART that receives from the reader - Uart.output = (((uint8_t *)BigBuf) + 1024); - Uart.byteCntMax = 100; + Uart.output = ((uint8_t *)BigBuf) + RECV_CMD_OFFSET; + Uart.byteCntMax = MAX_FRAME_SIZE; Uart.state = STATE_UNSYNCD; - // Setup for the DMA. - dmaBuf = (int8_t *)(BigBuf + 32); - upTo = dmaBuf; + // The DMA buffer, used to stream samples from the FPGA + int8_t *dmaBuf = ((int8_t *)BigBuf) + DMA_BUFFER_OFFSET; + int8_t *upTo= dmaBuf; lastRxCounter = DEMOD_DMA_BUFFER_SIZE; FpgaSetupSscDma((uint8_t *)dmaBuf, DEMOD_DMA_BUFFER_SIZE); diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index d91b24d7..54c1db40 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -22,10 +22,7 @@ #include "mifareutil.h" static uint32_t iso14a_timeout; -uint8_t *trace = (uint8_t *) BigBuf+TRACE_OFFSET; int rsamples = 0; -int traceLen = 0; -int tracing = TRUE; uint8_t trigger = 0; // the block number for the ISO14443-4 PCB static uint8_t iso14_pcb_blocknum = 0; diff --git a/armsrc/util.c b/armsrc/util.c index a4f55879..38f41750 100644 --- a/armsrc/util.c +++ b/armsrc/util.c @@ -13,6 +13,9 @@ #include "string.h" #include "apps.h" +uint8_t *trace = (uint8_t *) BigBuf+TRACE_OFFSET; +int traceLen = 0; +int tracing = TRUE; void print_result(char *name, uint8_t *buf, size_t len) { @@ -463,7 +466,6 @@ bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_ tracing = FALSE; // don't trace any more return FALSE; } - // Traceformat: // 32 bits timestamp (little endian) // 16 bits duration (little endian) @@ -502,6 +504,11 @@ bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_ } traceLen += num_paritybytes; + if(traceLen +4 < TRACE_SIZE) + { //If it hadn't been cleared, for whatever reason.. + memset(trace+traceLen,0x44, 4); + } + return TRUE; } diff --git a/client/cmdhf.c b/client/cmdhf.c index 9acc9825..37366802 100644 --- a/client/cmdhf.c +++ b/client/cmdhf.c @@ -413,15 +413,18 @@ uint16_t printTraceLine(uint16_t tracepos, uint8_t* trace, uint8_t protocol, boo if (tracepos + data_len + parity_len >= TRACE_SIZE) { return TRACE_SIZE; } - uint8_t *frame = trace + tracepos; tracepos += data_len; uint8_t *parityBytes = trace + tracepos; tracepos += parity_len; + //--- Draw the data column + //char line[16][110]; char line[16][110]; - for (int j = 0; j < data_len; j++) { + + for (int j = 0; j < data_len && j/16 < 16; j++) { + int oddparity = 0x01; int k; @@ -430,11 +433,17 @@ uint16_t printTraceLine(uint16_t tracepos, uint8_t* trace, uint8_t protocol, boo } uint8_t parityBits = parityBytes[j>>3]; - if (isResponse && (oddparity != ((parityBits >> (7-(j&0x0007))) & 0x01))) { - sprintf(line[j/16]+((j%16)*4), "%02x! ", frame[j]); + snprintf(line[j/16]+(( j % 16) * 4),110, "%02x! ", frame[j]); + } else { - sprintf(line[j/16]+((j%16)*4), "%02x ", frame[j]); + snprintf(line[j/16]+(( j % 16) * 4),110, "%02x! ", frame[j]); + } + } + if(data_len == 0) + { + if(data_len == 0){ + sprintf(line[0],""); } } //--- Draw the CRC column @@ -479,8 +488,8 @@ uint16_t printTraceLine(uint16_t tracepos, uint8_t* trace, uint8_t protocol, boo annotateIso14443b(explanation,sizeof(explanation),frame,data_len); } - int num_lines = (data_len - 1)/16 + 1; - for (int j = 0; j < num_lines; j++) { + int num_lines = MIN((data_len - 1)/16 + 1, 16); + for (int j = 0; j < num_lines ; j++) { if (j == 0) { PrintAndLog(" %9d | %9d | %s | %-64s| %s| %s", (timestamp - first_timestamp), @@ -573,7 +582,6 @@ int CmdHFList(const char *Cmd) uint16_t tracepos = 0; GetFromBigBuf(trace, TRACE_SIZE, 0); WaitForResponse(CMD_ACK, NULL); - PrintAndLog("Recorded Activity"); PrintAndLog(""); PrintAndLog("Start = Start of Start Bit, End = End of last modulation. Src = Source of Transfer");