mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-07-05 20:41:34 -07:00
fix bigbuf allocators (tracing + malloc) overwriting each other
* BigBuf.c: use s_ prefix for statics * BigBuf_Clear_ext already calls clear_trace, so remove extra calls * add some sanity checking of allocator args * dont compare PDC_RNCR to false
This commit is contained in:
parent
32f06db2e8
commit
aa286b4a16
10 changed files with 96 additions and 112 deletions
158
armsrc/BigBuf.c
158
armsrc/BigBuf.c
|
@ -45,7 +45,7 @@ static uint32_t s_bigbuf_size = 0;
|
||||||
static uint32_t s_bigbuf_hi = 0;
|
static uint32_t s_bigbuf_hi = 0;
|
||||||
|
|
||||||
// pointer to the emulator memory.
|
// pointer to the emulator memory.
|
||||||
static uint8_t *emulator_memory = NULL;
|
static uint8_t *s_emulator_memory = NULL;
|
||||||
|
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
// The ToSend buffer.
|
// The ToSend buffer.
|
||||||
|
@ -53,7 +53,7 @@ static uint8_t *emulator_memory = NULL;
|
||||||
// any purpose (fake tag, as reader, whatever). We go MSB first, since that
|
// any purpose (fake tag, as reader, whatever). We go MSB first, since that
|
||||||
// is the order in which they go out on the wire.
|
// is the order in which they go out on the wire.
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
static tosend_t toSend = {
|
static tosend_t s_toSend = {
|
||||||
.max = -1,
|
.max = -1,
|
||||||
.bit = 8,
|
.bit = 8,
|
||||||
.buf = NULL
|
.buf = NULL
|
||||||
|
@ -62,25 +62,25 @@ static tosend_t toSend = {
|
||||||
// The dmaBuf 16bit buffer.
|
// The dmaBuf 16bit buffer.
|
||||||
// A buffer where we receive IQ samples sent from the FPGA, for demodulating
|
// A buffer where we receive IQ samples sent from the FPGA, for demodulating
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
static dmabuf16_t dma_16 = {
|
static dmabuf16_t s_dma_16 = {
|
||||||
.size = DMA_BUFFER_SIZE,
|
.size = DMA_BUFFER_SIZE,
|
||||||
.buf = NULL
|
.buf = NULL
|
||||||
};
|
};
|
||||||
// dmaBuf 8bit buffer
|
// dmaBuf 8bit buffer
|
||||||
static dmabuf8_t dma_8 = {
|
static dmabuf8_t s_dma_8 = {
|
||||||
.size = DMA_BUFFER_SIZE,
|
.size = DMA_BUFFER_SIZE,
|
||||||
.buf = NULL
|
.buf = NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
// trace related variables
|
// trace related variables
|
||||||
static uint32_t trace_len = 0;
|
static uint32_t s_trace_len = 0;
|
||||||
static bool tracing = true;
|
static bool s_tracing = true;
|
||||||
|
|
||||||
// compute the available size for BigBuf
|
// compute the available size for BigBuf
|
||||||
void BigBuf_initialize(void) {
|
void BigBuf_initialize(void) {
|
||||||
s_bigbuf_size = (uint32_t)_stack_start - (uint32_t)__bss_end__;
|
s_bigbuf_size = (uint32_t)_stack_start - (uint32_t)__bss_end__;
|
||||||
s_bigbuf_hi = s_bigbuf_size;
|
s_bigbuf_hi = s_bigbuf_size;
|
||||||
trace_len = 0;
|
s_trace_len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the address of BigBuf
|
// get the address of BigBuf
|
||||||
|
@ -95,10 +95,10 @@ uint32_t BigBuf_get_size(void) {
|
||||||
// get the address of the emulator memory. Allocate part of Bigbuf for it, if not yet done
|
// get the address of the emulator memory. Allocate part of Bigbuf for it, if not yet done
|
||||||
uint8_t *BigBuf_get_EM_addr(void) {
|
uint8_t *BigBuf_get_EM_addr(void) {
|
||||||
// not yet allocated
|
// not yet allocated
|
||||||
if (emulator_memory == NULL) {
|
if (s_emulator_memory == NULL) {
|
||||||
emulator_memory = BigBuf_calloc(CARD_MEMORY_SIZE);
|
s_emulator_memory = BigBuf_calloc(CARD_MEMORY_SIZE);
|
||||||
}
|
}
|
||||||
return emulator_memory;
|
return s_emulator_memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t BigBuf_get_hi(void) {
|
uint32_t BigBuf_get_hi(void) {
|
||||||
|
@ -138,8 +138,9 @@ void BigBuf_Clear_keep_EM(void) {
|
||||||
uint8_t *BigBuf_malloc(uint16_t chunksize) {
|
uint8_t *BigBuf_malloc(uint16_t chunksize) {
|
||||||
chunksize = (chunksize + BIGBUF_ALIGN_BYTES - 1) & BIGBUF_ALIGN_MASK; // round up to next multiple of 4
|
chunksize = (chunksize + BIGBUF_ALIGN_BYTES - 1) & BIGBUF_ALIGN_MASK; // round up to next multiple of 4
|
||||||
|
|
||||||
if (s_bigbuf_hi < chunksize) {
|
if (s_bigbuf_hi - s_trace_len < chunksize || chunksize == 0) {
|
||||||
return NULL; // no memory left
|
// no memory left or chunksize too large
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
s_bigbuf_hi -= chunksize; // aligned to 4 Byte boundary
|
s_bigbuf_hi -= chunksize; // aligned to 4 Byte boundary
|
||||||
|
@ -159,23 +160,23 @@ uint8_t *BigBuf_calloc(uint16_t chunksize) {
|
||||||
// free ALL allocated chunks. The whole BigBuf is available for traces or samples again.
|
// free ALL allocated chunks. The whole BigBuf is available for traces or samples again.
|
||||||
void BigBuf_free(void) {
|
void BigBuf_free(void) {
|
||||||
s_bigbuf_hi = s_bigbuf_size;
|
s_bigbuf_hi = s_bigbuf_size;
|
||||||
emulator_memory = NULL;
|
s_emulator_memory = NULL;
|
||||||
// shouldn't this empty BigBuf also?
|
// shouldn't this empty BigBuf also?
|
||||||
toSend.buf = NULL;
|
s_toSend.buf = NULL;
|
||||||
dma_16.buf = NULL;
|
s_dma_16.buf = NULL;
|
||||||
dma_8.buf = NULL;
|
s_dma_8.buf = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// free allocated chunks EXCEPT the emulator memory
|
// free allocated chunks EXCEPT the emulator memory
|
||||||
void BigBuf_free_keep_EM(void) {
|
void BigBuf_free_keep_EM(void) {
|
||||||
if (emulator_memory != NULL)
|
if (s_emulator_memory != NULL)
|
||||||
s_bigbuf_hi = emulator_memory - (uint8_t *)BigBuf;
|
s_bigbuf_hi = s_emulator_memory - (uint8_t *)BigBuf;
|
||||||
else
|
else
|
||||||
s_bigbuf_hi = s_bigbuf_size;
|
s_bigbuf_hi = s_bigbuf_size;
|
||||||
|
|
||||||
toSend.buf = NULL;
|
s_toSend.buf = NULL;
|
||||||
dma_16.buf = NULL;
|
s_dma_16.buf = NULL;
|
||||||
dma_8.buf = NULL;
|
s_dma_8.buf = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BigBuf_print_status(void) {
|
void BigBuf_print_status(void) {
|
||||||
|
@ -183,23 +184,23 @@ void BigBuf_print_status(void) {
|
||||||
Dbprintf(" BigBuf_size............. %d", s_bigbuf_size);
|
Dbprintf(" BigBuf_size............. %d", s_bigbuf_size);
|
||||||
Dbprintf(" Available memory........ %d", s_bigbuf_hi);
|
Dbprintf(" Available memory........ %d", s_bigbuf_hi);
|
||||||
DbpString(_CYAN_("Tracing"));
|
DbpString(_CYAN_("Tracing"));
|
||||||
Dbprintf(" tracing ................ %d", tracing);
|
Dbprintf(" tracing ................ %d", s_tracing);
|
||||||
Dbprintf(" traceLen ............... %d", trace_len);
|
Dbprintf(" traceLen ............... %d", s_trace_len);
|
||||||
|
|
||||||
if (g_dbglevel >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
DbpString(_CYAN_("Sending buffers"));
|
DbpString(_CYAN_("Sending buffers"));
|
||||||
|
|
||||||
uint16_t d8 = 0;
|
uint16_t d8 = 0;
|
||||||
if (dma_8.buf)
|
if (s_dma_8.buf)
|
||||||
d8 = dma_8.buf - BigBuf_get_addr();
|
d8 = s_dma_8.buf - BigBuf_get_addr();
|
||||||
|
|
||||||
uint16_t d16 = 0;
|
uint16_t d16 = 0;
|
||||||
if (dma_16.buf)
|
if (s_dma_16.buf)
|
||||||
d16 = (uint8_t *)dma_16.buf - BigBuf_get_addr();
|
d16 = (uint8_t *)s_dma_16.buf - BigBuf_get_addr();
|
||||||
|
|
||||||
uint16_t ts = 0;
|
uint16_t ts = 0;
|
||||||
if (toSend.buf)
|
if (s_toSend.buf)
|
||||||
ts = toSend.buf - BigBuf_get_addr();
|
ts = s_toSend.buf - BigBuf_get_addr();
|
||||||
|
|
||||||
Dbprintf(" dma8 memory............. %u", d8);
|
Dbprintf(" dma8 memory............. %u", d8);
|
||||||
Dbprintf(" dma16 memory............ %u", d16);
|
Dbprintf(" dma16 memory............ %u", d16);
|
||||||
|
@ -213,19 +214,19 @@ uint16_t BigBuf_max_traceLen(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear_trace(void) {
|
void clear_trace(void) {
|
||||||
trace_len = 0;
|
s_trace_len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_tracelen(uint32_t value) {
|
void set_tracelen(uint32_t value) {
|
||||||
trace_len = value;
|
s_trace_len = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_tracing(bool enable) {
|
void set_tracing(bool enable) {
|
||||||
tracing = enable;
|
s_tracing = enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get_tracing(void) {
|
bool get_tracing(void) {
|
||||||
return tracing;
|
return s_tracing;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -233,7 +234,7 @@ bool get_tracing(void) {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
uint32_t BigBuf_get_traceLen(void) {
|
uint32_t BigBuf_get_traceLen(void) {
|
||||||
return trace_len;
|
return s_trace_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -243,18 +244,23 @@ uint32_t BigBuf_get_traceLen(void) {
|
||||||
annotation of commands/responses.
|
annotation of commands/responses.
|
||||||
**/
|
**/
|
||||||
bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_start, uint32_t timestamp_end, const uint8_t *parity, bool reader2tag) {
|
bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_start, uint32_t timestamp_end, const uint8_t *parity, bool reader2tag) {
|
||||||
if (tracing == false) {
|
if (btBytes == NULL || s_tracing == false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *trace = BigBuf_get_addr();
|
// Ignore too-small or too-large logs
|
||||||
tracelog_hdr_t *hdr = (tracelog_hdr_t *)(trace + trace_len);
|
if (iLen == 0 || iLen >= (1 << 15)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t num_paritybytes = (iLen - 1) / 8 + 1; // number of valid paritybytes in *parity
|
// number of valid paritybytes in *parity
|
||||||
|
const uint16_t num_paritybytes = (iLen - 1) / 8 + 1;
|
||||||
|
|
||||||
// Return when trace is full
|
// Disable tracing and return when trace is full
|
||||||
if (TRACELOG_HDR_LEN + iLen + num_paritybytes >= BigBuf_max_traceLen() - trace_len) {
|
const uint32_t max_trace_len = BigBuf_max_traceLen();
|
||||||
tracing = false;
|
const uint32_t trace_entry_len = TRACELOG_HDR_LEN + iLen + num_paritybytes;
|
||||||
|
if (s_trace_len >= max_trace_len || trace_entry_len >= max_trace_len - s_trace_len) {
|
||||||
|
s_tracing = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,27 +280,19 @@ bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_
|
||||||
duration = 0xFFFF;
|
duration = 0xFFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tracelog_hdr_t *hdr = (tracelog_hdr_t *)(BigBuf_get_addr() + s_trace_len);
|
||||||
hdr->timestamp = timestamp_start;
|
hdr->timestamp = timestamp_start;
|
||||||
hdr->duration = duration & 0xFFFF;
|
hdr->duration = duration & 0xFFFF;
|
||||||
hdr->data_len = iLen;
|
hdr->data_len = iLen;
|
||||||
hdr->isResponse = !reader2tag;
|
hdr->isResponse = !reader2tag;
|
||||||
trace_len += TRACELOG_HDR_LEN;
|
memcpy(hdr->frame, btBytes, iLen);
|
||||||
|
if (parity != NULL) {
|
||||||
// data bytes
|
memcpy(&hdr->frame[iLen], parity, num_paritybytes);
|
||||||
if (btBytes != NULL && iLen != 0) {
|
} else {
|
||||||
memcpy(hdr->frame, btBytes, iLen);
|
memset(&hdr->frame[iLen], 0x00, num_paritybytes);
|
||||||
trace_len += iLen;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// parity bytes
|
s_trace_len += trace_entry_len;
|
||||||
if (num_paritybytes != 0) {
|
|
||||||
if (parity != NULL) {
|
|
||||||
memcpy(trace + trace_len, parity, num_paritybytes);
|
|
||||||
} else {
|
|
||||||
memset(trace + trace_len, 0x00, num_paritybytes);
|
|
||||||
}
|
|
||||||
trace_len += num_paritybytes;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,6 +321,9 @@ bool RAMFUNC LogTraceBits(const uint8_t *btBytes, uint16_t bitLen, uint32_t time
|
||||||
// Emulator memory
|
// Emulator memory
|
||||||
int emlSet(const uint8_t *data, uint32_t offset, uint32_t length) {
|
int emlSet(const uint8_t *data, uint32_t offset, uint32_t length) {
|
||||||
uint8_t *mem = BigBuf_get_EM_addr();
|
uint8_t *mem = BigBuf_get_EM_addr();
|
||||||
|
if (!mem) {
|
||||||
|
return PM3_EMALLOC;
|
||||||
|
}
|
||||||
if (offset + length <= CARD_MEMORY_SIZE) {
|
if (offset + length <= CARD_MEMORY_SIZE) {
|
||||||
memcpy(mem + offset, data, length);
|
memcpy(mem + offset, data, length);
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
|
@ -334,6 +335,9 @@ int emlSet(const uint8_t *data, uint32_t offset, uint32_t length) {
|
||||||
|
|
||||||
int emlGet(uint8_t *out, uint32_t offset, uint32_t length) {
|
int emlGet(uint8_t *out, uint32_t offset, uint32_t length) {
|
||||||
uint8_t *mem = BigBuf_get_EM_addr();
|
uint8_t *mem = BigBuf_get_EM_addr();
|
||||||
|
if (!mem) {
|
||||||
|
return PM3_EMALLOC;
|
||||||
|
}
|
||||||
if (offset + length <= CARD_MEMORY_SIZE) {
|
if (offset + length <= CARD_MEMORY_SIZE) {
|
||||||
memcpy(out, mem + offset, length);
|
memcpy(out, mem + offset, length);
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
|
@ -347,51 +351,51 @@ int emlGet(uint8_t *out, uint32_t offset, uint32_t length) {
|
||||||
// get the address of the ToSend buffer. Allocate part of Bigbuf for it, if not yet done
|
// get the address of the ToSend buffer. Allocate part of Bigbuf for it, if not yet done
|
||||||
tosend_t *get_tosend(void) {
|
tosend_t *get_tosend(void) {
|
||||||
|
|
||||||
if (toSend.buf == NULL) {
|
if (s_toSend.buf == NULL) {
|
||||||
toSend.buf = BigBuf_malloc(TOSEND_BUFFER_SIZE);
|
s_toSend.buf = BigBuf_malloc(TOSEND_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
return &toSend;
|
return &s_toSend;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tosend_reset(void) {
|
void tosend_reset(void) {
|
||||||
toSend.max = -1;
|
s_toSend.max = -1;
|
||||||
toSend.bit = 8;
|
s_toSend.bit = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tosend_stuffbit(int b) {
|
void tosend_stuffbit(int b) {
|
||||||
|
|
||||||
if (toSend.max >= TOSEND_BUFFER_SIZE - 1) {
|
if (s_toSend.max >= TOSEND_BUFFER_SIZE - 1) {
|
||||||
Dbprintf(_RED_("toSend overflow"));
|
Dbprintf(_RED_("s_toSend overflow"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toSend.bit >= 8) {
|
if (s_toSend.bit >= 8) {
|
||||||
toSend.max++;
|
s_toSend.max++;
|
||||||
toSend.buf[toSend.max] = 0;
|
s_toSend.buf[s_toSend.max] = 0;
|
||||||
toSend.bit = 0;
|
s_toSend.bit = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b)
|
if (b)
|
||||||
toSend.buf[toSend.max] |= (1 << (7 - toSend.bit));
|
s_toSend.buf[s_toSend.max] |= (1 << (7 - s_toSend.bit));
|
||||||
|
|
||||||
toSend.bit++;
|
s_toSend.bit++;
|
||||||
|
|
||||||
if (toSend.max >= TOSEND_BUFFER_SIZE) {
|
if (s_toSend.max >= TOSEND_BUFFER_SIZE) {
|
||||||
toSend.bit = 0;
|
s_toSend.bit = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dmabuf16_t *get_dma16(void) {
|
dmabuf16_t *get_dma16(void) {
|
||||||
if (dma_16.buf == NULL) {
|
if (s_dma_16.buf == NULL) {
|
||||||
dma_16.buf = (uint16_t *)BigBuf_malloc(DMA_BUFFER_SIZE * sizeof(uint16_t));
|
s_dma_16.buf = (uint16_t *)BigBuf_malloc(DMA_BUFFER_SIZE * sizeof(uint16_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
return &dma_16;
|
return &s_dma_16;
|
||||||
}
|
}
|
||||||
|
|
||||||
dmabuf8_t *get_dma8(void) {
|
dmabuf8_t *get_dma8(void) {
|
||||||
if (dma_8.buf == NULL)
|
if (s_dma_8.buf == NULL)
|
||||||
dma_8.buf = BigBuf_malloc(DMA_BUFFER_SIZE);
|
s_dma_8.buf = BigBuf_malloc(DMA_BUFFER_SIZE);
|
||||||
|
|
||||||
return &dma_8;
|
return &s_dma_8;
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,6 @@ static void RAMFUNC SniffAndStore(uint8_t param) {
|
||||||
// free all previous allocations first
|
// free all previous allocations first
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
BigBuf_Clear_ext(false);
|
BigBuf_Clear_ext(false);
|
||||||
clear_trace();
|
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
|
||||||
// Array to store the authpwds
|
// Array to store the authpwds
|
||||||
|
@ -134,13 +133,13 @@ static void RAMFUNC SniffAndStore(uint8_t param) {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// primary buffer was stopped( <-- we lost data!
|
// primary buffer was stopped( <-- we lost data!
|
||||||
if (!AT91C_BASE_PDC_SSC->PDC_RCR) {
|
if (AT91C_BASE_PDC_SSC->PDC_RCR == 0) {
|
||||||
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t)dmaBuf;
|
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t)dmaBuf;
|
||||||
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
|
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
|
||||||
// Dbprintf("[-] RxEmpty ERROR | data length %d", dataLen); // temporary
|
// Dbprintf("[-] RxEmpty ERROR | data length %d", dataLen); // temporary
|
||||||
}
|
}
|
||||||
// secondary buffer sets as primary, secondary buffer was stopped
|
// secondary buffer sets as primary, secondary buffer was stopped
|
||||||
if (!AT91C_BASE_PDC_SSC->PDC_RNCR) {
|
if (AT91C_BASE_PDC_SSC->PDC_RNCR == 0) {
|
||||||
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t)dmaBuf;
|
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t)dmaBuf;
|
||||||
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
|
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1036,7 +1036,6 @@ void hitag_sniff(void) {
|
||||||
|
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
BigBuf_Clear_ext(false);
|
BigBuf_Clear_ext(false);
|
||||||
clear_trace();
|
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
|
||||||
// Set up eavesdropping mode, frequency divisor which will drive the FPGA
|
// Set up eavesdropping mode, frequency divisor which will drive the FPGA
|
||||||
|
@ -1061,7 +1060,6 @@ void SniffHitag2(bool ledcontrol) {
|
||||||
|
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
BigBuf_Clear_ext(false);
|
BigBuf_Clear_ext(false);
|
||||||
clear_trace();
|
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1418,7 +1416,6 @@ void SimulateHitag2(bool ledcontrol) {
|
||||||
|
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
BigBuf_Clear_ext(false);
|
BigBuf_Clear_ext(false);
|
||||||
clear_trace();
|
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
|
||||||
// empties bigbuff etc
|
// empties bigbuff etc
|
||||||
|
|
|
@ -708,9 +708,8 @@ void hts_simulate(bool tag_mem_supplied, const uint8_t *data, bool ledcontrol) {
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
BigBuf_Clear_ext(false);
|
BigBuf_Clear_ext(false);
|
||||||
|
|
||||||
// Clean up trace and prepare it for storing frames
|
// Enable tracing
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
clear_trace();
|
|
||||||
|
|
||||||
DbpString("Starting Hitag S simulation");
|
DbpString("Starting Hitag S simulation");
|
||||||
|
|
||||||
|
|
|
@ -728,7 +728,6 @@ void RAMFUNC SniffIso14443a(uint8_t param) {
|
||||||
// free all previous allocations first
|
// free all previous allocations first
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
BigBuf_Clear_ext(false);
|
BigBuf_Clear_ext(false);
|
||||||
clear_trace();
|
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
|
||||||
// The command (reader -> tag) that we're receiving.
|
// The command (reader -> tag) that we're receiving.
|
||||||
|
@ -798,13 +797,13 @@ void RAMFUNC SniffIso14443a(uint8_t param) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// primary buffer was stopped( <-- we lost data!
|
// primary buffer was stopped( <-- we lost data!
|
||||||
if (!AT91C_BASE_PDC_SSC->PDC_RCR) {
|
if (AT91C_BASE_PDC_SSC->PDC_RCR == 0) {
|
||||||
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) dma->buf;
|
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) dma->buf;
|
||||||
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
|
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
|
||||||
Dbprintf("[-] RxEmpty ERROR | data length %d", dataLen); // temporary
|
Dbprintf("[-] RxEmpty ERROR | data length %d", dataLen); // temporary
|
||||||
}
|
}
|
||||||
// secondary buffer sets as primary, secondary buffer was stopped
|
// secondary buffer sets as primary, secondary buffer was stopped
|
||||||
if (!AT91C_BASE_PDC_SSC->PDC_RNCR) {
|
if (AT91C_BASE_PDC_SSC->PDC_RNCR == 0) {
|
||||||
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dma->buf;
|
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dma->buf;
|
||||||
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
|
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
|
@ -3400,7 +3399,6 @@ void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype) {
|
||||||
|
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
BigBuf_Clear_ext(false);
|
BigBuf_Clear_ext(false);
|
||||||
clear_trace();
|
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
|
||||||
uint8_t mf_auth[4] = { keytype, block, 0x00, 0x00 };
|
uint8_t mf_auth[4] = { keytype, block, 0x00, 0x00 };
|
||||||
|
@ -3717,7 +3715,6 @@ void DetectNACKbug(void) {
|
||||||
|
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
BigBuf_Clear_ext(false);
|
BigBuf_Clear_ext(false);
|
||||||
clear_trace();
|
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_MOD);
|
iso14443a_setup(FPGA_HF_ISO14443A_READER_MOD);
|
||||||
|
|
||||||
|
|
|
@ -980,7 +980,6 @@ void Simulate_iso14443b_srx_tag(uint8_t *uid) {
|
||||||
// allocate command receive buffer
|
// allocate command receive buffer
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
BigBuf_Clear_ext(false);
|
BigBuf_Clear_ext(false);
|
||||||
clear_trace();
|
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
|
||||||
uint16_t len, cmdsReceived = 0;
|
uint16_t len, cmdsReceived = 0;
|
||||||
|
@ -1381,12 +1380,12 @@ static int Get14443bAnswerFromTag(uint8_t *response, uint16_t max_len, uint32_t
|
||||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_ENDRX)) {
|
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_ENDRX)) {
|
||||||
|
|
||||||
// primary buffer was stopped
|
// primary buffer was stopped
|
||||||
if (AT91C_BASE_PDC_SSC->PDC_RCR == false) {
|
if (AT91C_BASE_PDC_SSC->PDC_RCR == 0) {
|
||||||
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) dma->buf;
|
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) dma->buf;
|
||||||
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
|
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
// secondary buffer sets as primary, secondary buffer was stopped
|
// secondary buffer sets as primary, secondary buffer was stopped
|
||||||
if (AT91C_BASE_PDC_SSC->PDC_RNCR == false) {
|
if (AT91C_BASE_PDC_SSC->PDC_RNCR == 0) {
|
||||||
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dma->buf;
|
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dma->buf;
|
||||||
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
|
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
|
@ -2463,12 +2462,12 @@ void SniffIso14443b(void) {
|
||||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_ENDRX)) {
|
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_ENDRX)) {
|
||||||
|
|
||||||
// primary buffer was stopped
|
// primary buffer was stopped
|
||||||
if (AT91C_BASE_PDC_SSC->PDC_RCR == false) {
|
if (AT91C_BASE_PDC_SSC->PDC_RCR == 0) {
|
||||||
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) dma->buf;
|
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) dma->buf;
|
||||||
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
|
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
// secondary buffer sets as primary, secondary buffer was stopped
|
// secondary buffer sets as primary, secondary buffer was stopped
|
||||||
if (AT91C_BASE_PDC_SSC->PDC_RNCR == false) {
|
if (AT91C_BASE_PDC_SSC->PDC_RNCR == 0) {
|
||||||
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dma->buf;
|
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dma->buf;
|
||||||
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
|
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
|
@ -2578,7 +2577,6 @@ void SendRawCommand14443B(iso14b_raw_cmd_t *p) {
|
||||||
|
|
||||||
if ((p->flags & ISO14B_CLEARTRACE) == ISO14B_CLEARTRACE) {
|
if ((p->flags & ISO14B_CLEARTRACE) == ISO14B_CLEARTRACE) {
|
||||||
clear_trace();
|
clear_trace();
|
||||||
BigBuf_Clear_ext(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
|
|
@ -1032,12 +1032,12 @@ int GetIso15693AnswerFromTag(uint8_t *response, uint16_t max_len, uint16_t timeo
|
||||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_ENDRX)) {
|
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_ENDRX)) {
|
||||||
|
|
||||||
// primary buffer was stopped
|
// primary buffer was stopped
|
||||||
if (AT91C_BASE_PDC_SSC->PDC_RCR == false) {
|
if (AT91C_BASE_PDC_SSC->PDC_RCR == 0) {
|
||||||
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) dma->buf;
|
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) dma->buf;
|
||||||
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
|
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
// secondary buffer sets as primary, secondary buffer was stopped
|
// secondary buffer sets as primary, secondary buffer was stopped
|
||||||
if (AT91C_BASE_PDC_SSC->PDC_RNCR == false) {
|
if (AT91C_BASE_PDC_SSC->PDC_RNCR == 0) {
|
||||||
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dma->buf;
|
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dma->buf;
|
||||||
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
|
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
|
@ -1708,12 +1708,12 @@ void SniffIso15693(uint8_t jam_search_len, uint8_t *jam_search_string, bool icla
|
||||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_ENDRX)) {
|
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_ENDRX)) {
|
||||||
|
|
||||||
// primary buffer was stopped
|
// primary buffer was stopped
|
||||||
if (AT91C_BASE_PDC_SSC->PDC_RCR == false) {
|
if (AT91C_BASE_PDC_SSC->PDC_RCR == 0) {
|
||||||
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) dma->buf;
|
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) dma->buf;
|
||||||
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
|
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
// secondary buffer sets as primary, secondary buffer was stopped
|
// secondary buffer sets as primary, secondary buffer was stopped
|
||||||
if (AT91C_BASE_PDC_SSC->PDC_RNCR == false) {
|
if (AT91C_BASE_PDC_SSC->PDC_RNCR == 0) {
|
||||||
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dma->buf;
|
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dma->buf;
|
||||||
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
|
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1006,7 +1006,6 @@ void CmdFSKsimTAGEx(uint8_t fchigh, uint8_t fclow, uint8_t separator, uint8_t cl
|
||||||
// free eventually allocated BigBuf memory
|
// free eventually allocated BigBuf memory
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
BigBuf_Clear_ext(false);
|
BigBuf_Clear_ext(false);
|
||||||
clear_trace();
|
|
||||||
set_tracing(false);
|
set_tracing(false);
|
||||||
|
|
||||||
int n = 0, i = 0;
|
int n = 0, i = 0;
|
||||||
|
|
|
@ -385,7 +385,6 @@ void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain)
|
||||||
// free eventually allocated BigBuf memory
|
// free eventually allocated BigBuf memory
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
BigBuf_Clear_ext(false);
|
BigBuf_Clear_ext(false);
|
||||||
clear_trace();
|
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
|
||||||
// params
|
// params
|
||||||
|
@ -804,7 +803,6 @@ void MifareAcquireNonces(uint32_t arg0, uint32_t flags) {
|
||||||
|
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
BigBuf_Clear_ext(false);
|
BigBuf_Clear_ext(false);
|
||||||
clear_trace();
|
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
|
||||||
if (initialize)
|
if (initialize)
|
||||||
|
@ -918,7 +916,6 @@ void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags,
|
||||||
|
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
BigBuf_Clear_ext(false);
|
BigBuf_Clear_ext(false);
|
||||||
clear_trace();
|
|
||||||
set_tracing(false);
|
set_tracing(false);
|
||||||
|
|
||||||
if (initialize)
|
if (initialize)
|
||||||
|
@ -1069,7 +1066,6 @@ int MifareAcquireStaticEncryptedNonces(uint32_t flags, const uint8_t *key, bool
|
||||||
|
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
BigBuf_Clear_ext(false);
|
BigBuf_Clear_ext(false);
|
||||||
clear_trace();
|
|
||||||
set_tracing(false);
|
set_tracing(false);
|
||||||
|
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
||||||
|
@ -1353,9 +1349,6 @@ void MifareNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo, uint8
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
BigBuf_Clear_ext(false);
|
BigBuf_Clear_ext(false);
|
||||||
|
|
||||||
if (calibrate)
|
|
||||||
clear_trace();
|
|
||||||
|
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
|
||||||
// statistics on nonce distance
|
// statistics on nonce distance
|
||||||
|
@ -1595,7 +1588,6 @@ void MifareStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo,
|
||||||
// free eventually allocated BigBuf memory
|
// free eventually allocated BigBuf memory
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
BigBuf_Clear_ext(false);
|
BigBuf_Clear_ext(false);
|
||||||
clear_trace();
|
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
|
||||||
int16_t isOK = PM3_ESOFT;
|
int16_t isOK = PM3_ESOFT;
|
||||||
|
|
|
@ -50,7 +50,6 @@ void RAMFUNC SniffMifare(uint8_t param) {
|
||||||
// free all previous allocations first
|
// free all previous allocations first
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
BigBuf_Clear_ext(false);
|
BigBuf_Clear_ext(false);
|
||||||
clear_trace();
|
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
|
||||||
// The command (reader -> tag) that we're receiving.
|
// The command (reader -> tag) that we're receiving.
|
||||||
|
@ -137,13 +136,13 @@ void RAMFUNC SniffMifare(uint8_t param) {
|
||||||
if (dataLen < 1) continue;
|
if (dataLen < 1) continue;
|
||||||
|
|
||||||
// primary buffer was stopped ( <-- we lost data!
|
// primary buffer was stopped ( <-- we lost data!
|
||||||
if (!AT91C_BASE_PDC_SSC->PDC_RCR) {
|
if (AT91C_BASE_PDC_SSC->PDC_RCR == 0) {
|
||||||
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t)dmaBuf;
|
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t)dmaBuf;
|
||||||
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
|
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
|
||||||
Dbprintf("[-] RxEmpty ERROR | data length %d", dataLen); // temporary
|
Dbprintf("[-] RxEmpty ERROR | data length %d", dataLen); // temporary
|
||||||
}
|
}
|
||||||
// secondary buffer sets as primary, secondary buffer was stopped
|
// secondary buffer sets as primary, secondary buffer was stopped
|
||||||
if (!AT91C_BASE_PDC_SSC->PDC_RNCR) {
|
if (AT91C_BASE_PDC_SSC->PDC_RNCR == 0) {
|
||||||
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t)dmaBuf;
|
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t)dmaBuf;
|
||||||
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
|
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue