]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/util.c
Merge branch 'master' into GenericTracing
[proxmark3-svn] / armsrc / util.c
index cce9bed80a471e403c7eef1ee78096f5abcf024d..4948fce8f8a19146436d220f8aa5475335736f6c 100644 (file)
@@ -12,7 +12,9 @@
 #include "util.h"
 #include "string.h"
 #include "apps.h"
+#include "BigBuf.h"
 
+int tracing = TRUE;
 
 
 void print_result(char *name, uint8_t *buf, size_t len) {
@@ -427,6 +429,24 @@ uint32_t RAMFUNC GetCountSspClk(){
                return tmp_count;
        }
 }
+void iso14a_clear_trace() {
+       clear_trace();
+}
+
+void iso14a_set_tracing(bool enable) {
+       set_tracing(enable);
+}
+
+void clear_trace() {
+       uint8_t *trace = BigBuf_get_addr();
+       uint16_t max_traceLen = BigBuf_max_traceLen();
+       memset(trace, 0x44, max_traceLen);
+       traceLen = 0;
+}
+
+void set_tracing(bool enable) {
+       tracing = enable;
+}
 
 /**
   This is a function to store traces. All protocols can use this generic tracer-function.
@@ -439,15 +459,18 @@ bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_
 {
        if (!tracing) return FALSE;
 
+       uint8_t *trace = BigBuf_get_addr();
+
        uint16_t num_paritybytes = (iLen-1)/8 + 1;      // number of valid paritybytes in *parity
        uint16_t duration = timestamp_end - timestamp_start;
 
        // Return when trace is full
-       if (traceLen + sizeof(iLen) + sizeof(timestamp_start) + sizeof(duration) + num_paritybytes + iLen >= TRACE_SIZE) {
+       uint16_t max_traceLen = BigBuf_max_traceLen();
+
+       if (traceLen + sizeof(iLen) + sizeof(timestamp_start) + sizeof(duration) + num_paritybytes + iLen >= max_traceLen) {
                tracing = FALSE;        // don't trace any more
                return FALSE;
        }
-
        // Traceformat:
        // 32 bits timestamp (little endian)
        // 16 bits duration (little endian)
@@ -486,6 +509,11 @@ bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_
        }
        traceLen += num_paritybytes;
 
+       if(traceLen +4 < max_traceLen)
+       {       //If it hadn't been cleared, for whatever reason..
+               memset(trace+traceLen,0x44, 4);
+       }
+
        return TRUE;
 }
 
Impressum, Datenschutz