--- /dev/null
+//-----------------------------------------------------------------------------
+// Jonathan Westhues, Aug 2005
+// Gerhard de Koning Gans, April 2008, May 2011
+//
+// This code is licensed to you under the terms of the GNU GPL, version 2 or,
+// at your option, any later version. See the LICENSE.txt file for the text of
+// the license.
+//-----------------------------------------------------------------------------
+// BigBuf and functions to allocate/free parts of it.
+//-----------------------------------------------------------------------------
+
+#include <stdint.h>
+#include "proxmark3.h"
+#include "apps.h"
+#include "string.h"
+
+// The large multi-purpose buffer, typically used to hold A/D samples or traces,
+// may be processed in some way. Also used to hold various smaller buffers.
+static uint8_t BigBuf[BIGBUF_SIZE];
+
+// High memory mark
+static uint16_t BigBuf_hi = BIGBUF_SIZE;
+
+// trace related global variables. Change to function calls?
+//uint8_t *trace = BigBuf;
+uint16_t traceLen;
+
+
+// get the address of BigBuf
+uint8_t *BigBuf_get_addr(void)
+{
+ return BigBuf;
+}
+
+
+// clear ALL of BigBuf
+void BigBuf_Clear(void)
+{
+ memset(BigBuf,0,BIGBUF_SIZE);
+ Dbprintf("Buffer cleared (%i bytes)",BIGBUF_SIZE);
+}
+
+
+// allocate a chunk of memory from BigBuf. We allocate high memory first. Low memory
+// is always for traces/samples
+uint8_t *BigBuf_malloc(uint16_t chunksize)
+{
+ if (BigBuf_hi - chunksize < 0) {
+ return NULL; // no memory left
+ } else {
+ BigBuf_hi -= chunksize; // aligned to 4 Byte boundary
+ return BigBuf + BigBuf_hi;
+ }
+}
+
+
+// free ALL allocated chunks. The whole BigBuf is available for traces again.
+void BigBuf_free(void)
+{
+ BigBuf_hi = BIGBUF_SIZE;
+}
+
+
+// return the maximum trace length (i.e. the unallocated size of BigBuf)
+uint16_t BigBuf_max_trace_len(void)
+{
+ return BigBuf_hi;
+}
\ No newline at end of file
--- /dev/null
+//-----------------------------------------------------------------------------
+// Jonathan Westhues, Aug 2005
+// Gerhard de Koning Gans, April 2008, May 2011
+//
+// This code is licensed to you under the terms of the GNU GPL, version 2 or,
+// at your option, any later version. See the LICENSE.txt file for the text of
+// the license.
+//-----------------------------------------------------------------------------
+// BigBuf and functions to allocate/free parts of it.
+//-----------------------------------------------------------------------------
+
+#ifndef __BIGBUF_H
+#define __BIGBUF_H
+
+
+#define BIGBUF_SIZE 40000
+#define TRACE_OFFSET 0
+#define TRACE_SIZE 3000
+#define RECV_CMD_OFFSET (TRACE_OFFSET + TRACE_SIZE)
+#define MAX_FRAME_SIZE 256
+#define MAX_PARITY_SIZE ((MAX_FRAME_SIZE + 1)/ 8)
+#define RECV_CMD_PAR_OFFSET (RECV_CMD_OFFSET + MAX_FRAME_SIZE)
+#define RECV_RESP_OFFSET (RECV_CMD_PAR_OFFSET + MAX_PARITY_SIZE)
+#define RECV_RESP_PAR_OFFSET (RECV_RESP_OFFSET + MAX_FRAME_SIZE)
+#define CARD_MEMORY_OFFSET (RECV_RESP_PAR_OFFSET + MAX_PARITY_SIZE)
+#define CARD_MEMORY_SIZE 4096
+#define DMA_BUFFER_OFFSET CARD_MEMORY_OFFSET
+#define DMA_BUFFER_SIZE CARD_MEMORY_SIZE
+#define FREE_BUFFER_OFFSET (CARD_MEMORY_OFFSET + CARD_MEMORY_SIZE)
+#define FREE_BUFFER_SIZE (BIGBUF_SIZE - FREE_BUFFER_OFFSET - 1)
+
+extern uint8_t *BigBuf_get_addr(void);
+extern uint16_t BigBuf_max_trace_len(void);
+void BigBuf_Clear(void);
+extern uint8_t *BigBuf_malloc(uint16_t);
+extern void BigBuf_free(void);
+
+extern uint16_t traceLen;
+
+#endif /* __BIGBUF_H */
$(SRC_CRAPTO1) \
$(SRC_CRC) \
legic_prng.c \
- iclass.c
-
+ iclass.c \
+ BigBuf.c \
# stdint.h provided locally until GCC 4.5 becomes C99 compliant
APP_CFLAGS += -I.
static int ToSendBit;
struct common_area common_area __attribute__((section(".commonarea")));
-void BufferClear(void)
-{
- memset(BigBuf,0,sizeof(BigBuf));
- Dbprintf("Buffer cleared (%i bytes)",sizeof(BigBuf));
-}
-
void ToSendReset(void)
{
ToSendMax = -1;
void SimulateTagHfListen(void)
{
- uint8_t *dest = (uint8_t *)BigBuf+FREE_BUFFER_OFFSET;
+ uint8_t *dest = BigBuf_get_addr() + FREE_BUFFER_OFFSET;
uint8_t v = 0;
int i;
int p = 0;
MifareUC_Auth2(c->arg[0],c->d.asBytes);
break;
case CMD_MIFAREU_READCARD:
- MifareUReadCard(c->arg[0],c->arg[1],c->d.asBytes);
- break;
+ MifareUReadCard(c->arg[0], c->arg[1], c->d.asBytes);
+ break;
case CMD_MIFAREUC_READCARD:
- MifareUReadCard(c->arg[0],c->arg[1],c->d.asBytes);
- break;
+ MifareUReadCard(c->arg[0], c->arg[1], c->d.asBytes);
+ break;
case CMD_MIFARE_READSC:
MifareReadSector(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
break;
break;
case CMD_BUFF_CLEAR:
- BufferClear();
+ BigBuf_Clear();
break;
case CMD_MEASURE_ANTENNA_TUNING:
case CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K:
LED_B_ON();
+ uint8_t *BigBuf = BigBuf_get_addr();
for(size_t i=0; i<c->arg[1]; i += USB_CMD_DATA_SIZE) {
size_t len = MIN((c->arg[1] - i),USB_CMD_DATA_SIZE);
- cmd_send(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K,i,len,0,((byte_t*)BigBuf)+c->arg[0]+i,len);
+ cmd_send(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K,i,len,0,BigBuf+c->arg[0]+i,len);
}
// Trigger a finish downloading signal with an ACK frame
cmd_send(CMD_ACK,0,0,0,0,0);
break;
case CMD_DOWNLOADED_SIM_SAMPLES_125K: {
- uint8_t *b = (uint8_t *)BigBuf;
+ uint8_t *b = BigBuf_get_addr();
memcpy(b+c->arg[0], c->d.asBytes, USB_CMD_DATA_SIZE);
cmd_send(CMD_ACK,0,0,0,0,0);
break;
#include "common.h"
#include "hitag2.h"
#include "mifare.h"
-
#include "../common/crc32.h"
-
-// The large multi-purpose buffer, typically used to hold A/D samples,
-// maybe processed in some way.
-#define BIGBUF_SIZE 40000
-uint32_t BigBuf[BIGBUF_SIZE / sizeof(uint32_t)];
-#define TRACE_OFFSET 0
-#define TRACE_SIZE 3000
-#define RECV_CMD_OFFSET (TRACE_OFFSET + TRACE_SIZE)
-#define MAX_FRAME_SIZE 256
-#define MAX_PARITY_SIZE ((MAX_FRAME_SIZE + 1)/ 8)
-#define RECV_CMD_PAR_OFFSET (RECV_CMD_OFFSET + MAX_FRAME_SIZE)
-#define RECV_RESP_OFFSET (RECV_CMD_PAR_OFFSET + MAX_PARITY_SIZE)
-#define RECV_RESP_PAR_OFFSET (RECV_RESP_OFFSET + MAX_FRAME_SIZE)
-#define CARD_MEMORY_OFFSET (RECV_RESP_PAR_OFFSET + MAX_PARITY_SIZE)
-#define CARD_MEMORY_SIZE 4096
-#define DMA_BUFFER_OFFSET CARD_MEMORY_OFFSET
-#define DMA_BUFFER_SIZE CARD_MEMORY_SIZE
-#define FREE_BUFFER_OFFSET (CARD_MEMORY_OFFSET + CARD_MEMORY_SIZE)
-#define FREE_BUFFER_SIZE (BIGBUF_SIZE - FREE_BUFFER_OFFSET - 1)
-
-/*
-The statements above translates into this :
-BIGBUF_SIZE = 40000
-TRACE_OFFSET = 0
-TRACE_SIZE = 3000
-RECV_CMD_OFFSET = 3000
-MAX_FRAME_SIZE = 256
-MAX_PARITY_SIZE = 32
-RECV_CMD_PAR_OFFSET = 3256
-RECV_RESP_OFFSET = 3288
-RECV_RESP_PAR_OFFSET= 3544
-CARD_MEMORY_OFFSET = 3576
-CARD_MEMORY_SIZE = 4096
-DMA_BUFFER_OFFSET = 3576
-DMA_BUFFER_SIZE = 4096
-FREE_BUFFER_OFFSET = 7672
-FREE_BUFFER_SIZE = 32327
- */
+#include "BigBuf.h"
extern const uint8_t OddByteParity[256];
-extern uint8_t *trace; // = (uint8_t *) BigBuf;
-extern int traceLen; // = 0;
extern int rsamples; // = 0;
extern int tracing; // = TRUE;
extern uint8_t trigger;
void DoAcquisition125k(int trigger_threshold);
extern int ToSendMax;
extern uint8_t ToSend[];
-extern uint32_t BigBuf[];
/// fpga.h
void FpgaSendCommand(uint16_t cmd, uint16_t v);
bool bPwd;
bool bSuccessful;
+
int LogTraceHitag(const uint8_t * btBytes, int iBits, int iSamples, uint32_t dwParity, int bReader)
{
+ static uint16_t traceLen = 0;
+ uint8_t *trace = BigBuf_get_addr();
+
// Return when trace is full
if (traceLen >= TRACE_SIZE) return FALSE;
#define AUTH_TABLE_OFFSET FREE_BUFFER_OFFSET
#define AUTH_TABLE_LENGTH FREE_BUFFER_SIZE
-byte_t* auth_table = (byte_t *)BigBuf+AUTH_TABLE_OFFSET;
size_t auth_table_pos = 0;
size_t auth_table_len = AUTH_TABLE_LENGTH;
void hitag2_handle_reader_command(byte_t* rx, const size_t rxlen, byte_t* tx, size_t* txlen)
{
+ byte_t* auth_table;
+ auth_table = (byte_t *)BigBuf_get_addr() + AUTH_TABLE_OFFSET;
byte_t rx_air[HITAG_FRAME_LEN];
// Copy the (original) received frame how it is send over the air
}
bool hitag2_test_auth_attempts(byte_t* rx, const size_t rxlen, byte_t* tx, size_t* txlen) {
+
+ byte_t* auth_table;
+ auth_table = (byte_t *)BigBuf_get_addr() + AUTH_TABLE_OFFSET;
+
// Reset the transmission frame length
*txlen = 0;
auth_table_len = 0;
auth_table_pos = 0;
+ byte_t* auth_table;
+ auth_table = (byte_t *)BigBuf_get_addr() + AUTH_TABLE_OFFSET;
memset(auth_table, 0x00, AUTH_TABLE_LENGTH);
DbpString("Starting Hitag2 snoop");
bQuiet = false;
// Clean up trace and prepare it for storing frames
- iso14a_set_tracing(TRUE);
- iso14a_clear_trace();
+ iso14a_set_tracing(TRUE);
+ iso14a_clear_trace();
auth_table_len = 0;
auth_table_pos = 0;
+ byte_t* auth_table;
+ auth_table = (byte_t *)BigBuf_get_addr() + AUTH_TABLE_OFFSET;
memset(auth_table, 0x00, AUTH_TABLE_LENGTH);
DbpString("Starting Hitag2 simulation");
bSuccessful = false;
// Clean up trace and prepare it for storing frames
- iso14a_set_tracing(TRUE);
- iso14a_clear_trace();
+ iso14a_set_tracing(TRUE);
+ iso14a_clear_trace();
+ byte_t* auth_table;
+ auth_table = (byte_t *)BigBuf_get_addr() + AUTH_TABLE_OFFSET;
+
DbpString("Starting Hitag reader family");
// Check configuration
// The command (reader -> tag) that we're receiving.
// The length of a received command will in most cases be no more than 18 bytes.
// So 32 should be enough!
- uint8_t *readerToTagCmd = (((uint8_t *)BigBuf) + RECV_CMD_OFFSET);
+ uint8_t *readerToTagCmd = BigBuf_get_addr() + RECV_CMD_OFFSET;
// The response (tag -> reader) that we're receiving.
- uint8_t *tagToReaderResponse = (((uint8_t *)BigBuf) + RECV_RESP_OFFSET);
+ uint8_t *tagToReaderResponse = BigBuf_get_addr() + RECV_RESP_OFFSET;
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
iso14a_set_trigger(FALSE);
// The DMA buffer, used to stream samples from the FPGA
- int8_t *dmaBuf = ((int8_t *)BigBuf) + DMA_BUFFER_OFFSET;
+ uint8_t *dmaBuf = BigBuf_get_addr() + DMA_BUFFER_OFFSET;
int lastRxCounter;
- int8_t *upTo;
+ uint8_t *upTo;
int smpl;
int maxBehindBy = 0;
//uint8_t sof = 0x0f;
// Respond SOF -- takes 1 bytes
- uint8_t *resp1 = (((uint8_t *)BigBuf) + FREE_BUFFER_OFFSET);
+ uint8_t *resp1 = (BigBuf_get_addr() + FREE_BUFFER_OFFSET);
int resp1Len;
// Anticollision CSN (rotated CSN)
// 22: Takes 2 bytes for SOF/EOF and 10 * 2 = 20 bytes (2 bytes/byte)
- uint8_t *resp2 = (((uint8_t *)BigBuf) + FREE_BUFFER_OFFSET + 2);
+ uint8_t *resp2 = (BigBuf_get_addr() + FREE_BUFFER_OFFSET + 2);
int resp2Len;
// CSN
// 22: Takes 2 bytes for SOF/EOF and 10 * 2 = 20 bytes (2 bytes/byte)
- uint8_t *resp3 = (((uint8_t *)BigBuf) + FREE_BUFFER_OFFSET + 30);
+ uint8_t *resp3 = (BigBuf_get_addr() + FREE_BUFFER_OFFSET + 30);
int resp3Len;
// e-Purse
// 18: Takes 2 bytes for SOF/EOF and 8 * 2 = 16 bytes (2 bytes/byte)
- uint8_t *resp4 = (((uint8_t *)BigBuf) + FREE_BUFFER_OFFSET + 60);
+ uint8_t *resp4 = (BigBuf_get_addr() + FREE_BUFFER_OFFSET + 60);
int resp4Len;
// + 1720..
- uint8_t *receivedCmd = (((uint8_t *)BigBuf) + RECV_CMD_OFFSET);
+ uint8_t *receivedCmd = BigBuf_get_addr() + RECV_CMD_OFFSET;
memset(receivedCmd, 0x44, MAX_FRAME_SIZE);
int len;
static uint8_t identify[] = { 0x0c };
static uint8_t select[] = { 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static uint8_t readcheck_cc[]= { 0x88, 0x02 };
- uint8_t *resp = (((uint8_t *)BigBuf) + RECV_RESP_OFFSET);
+ uint8_t *resp = BigBuf_get_addr() + RECV_RESP_OFFSET;
uint8_t read_status = 0;
int keyaccess;
} memory;
- uint8_t* resp = (((uint8_t *)BigBuf) + RECV_RESP_OFFSET);
+ uint8_t* resp = BigBuf_get_addr() + RECV_RESP_OFFSET;
setupIclassReader();
uint8_t *resp;
int respLen;
- uint8_t *resp1 = (((uint8_t *)BigBuf) + 800);
+ uint8_t *resp1 = BigBuf_get_addr() + 800;
int resp1Len;
- uint8_t *receivedCmd = (uint8_t *)BigBuf;
+ uint8_t *receivedCmd = BigBuf_get_addr();
int len;
int i;
int gotFrame = FALSE;
//# define DMA_BUFFER_SIZE 8
- int8_t *dmaBuf;
+ uint8_t *dmaBuf;
int lastRxCounter;
- int8_t *upTo;
+ uint8_t *upTo;
int ci, cq;
int samples = 0;
// Clear out the state of the "UART" that receives from the tag.
+ uint8_t *BigBuf = BigBuf_get_addr();
memset(BigBuf, 0x00, 400);
- Demod.output = (uint8_t *)BigBuf;
+ Demod.output = BigBuf;
Demod.len = 0;
Demod.state = DEMOD_UNSYNCD;
// And the UART that receives from the reader
- Uart.output = (((uint8_t *)BigBuf) + 1024);
+ Uart.output = BigBuf + 1024;
Uart.byteCntMax = 100;
Uart.state = STATE_UNSYNCD;
// Setup for the DMA.
- dmaBuf = (int8_t *)(BigBuf + 32);
+ dmaBuf = BigBuf + 32;
upTo = dmaBuf;
lastRxCounter = DEMOD_DMA_BUFFER_SIZE;
- FpgaSetupSscDma((uint8_t *)dmaBuf, DEMOD_DMA_BUFFER_SIZE);
+ FpgaSetupSscDma(dmaBuf, DEMOD_DMA_BUFFER_SIZE);
// Signal field is ON with the appropriate LED:
if (weTx) LED_D_ON(); else LED_D_OFF();
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
// The command (reader -> tag) that we're working on receiving.
- uint8_t *receivedCmd = (uint8_t *)(BigBuf) + DEMOD_TRACE_SIZE;
+ uint8_t *receivedCmd = BigBuf_get_addr() + DEMOD_TRACE_SIZE;
// The response (tag -> reader) that we're working on receiving.
- uint8_t *receivedResponse = (uint8_t *)(BigBuf) + DEMOD_TRACE_SIZE + READER_TAG_BUFFER_SIZE;
+ uint8_t *receivedResponse = BigBuf_get_addr() + DEMOD_TRACE_SIZE + READER_TAG_BUFFER_SIZE;
// As we receive stuff, we copy it from receivedCmd or receivedResponse
// into trace, along with its length and other annotations.
- uint8_t *trace = (uint8_t *)BigBuf;
+ uint8_t *trace = BigBuf_get_addr();
int traceLen = 0;
// The DMA buffer, used to stream samples from the FPGA.
- int8_t *dmaBuf = (int8_t *)(BigBuf) + DEMOD_TRACE_SIZE + READER_TAG_BUFFER_SIZE + TAG_READER_BUFFER_SIZE;
+ uint8_t *dmaBuf = BigBuf_get_addr() + DEMOD_TRACE_SIZE + READER_TAG_BUFFER_SIZE + TAG_READER_BUFFER_SIZE;
int lastRxCounter;
- int8_t *upTo;
+ uint8_t *upTo;
int ci, cq;
int maxBehindBy = 0;
#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
}
void iso14a_clear_trace() {
+ uint8_t *trace = BigBuf_get_addr();
memset(trace, 0x44, TRACE_SIZE);
traceLen = 0;
}
{
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;
// The command (reader -> tag) that we're receiving.
// The length of a received command will in most cases be no more than 18 bytes.
// So 32 should be enough!
- uint8_t *receivedCmd = ((uint8_t *)BigBuf) + RECV_CMD_OFFSET;
- uint8_t *receivedCmdPar = ((uint8_t *)BigBuf) + RECV_CMD_PAR_OFFSET;
+ uint8_t *receivedCmd = BigBuf_get_addr() + RECV_CMD_OFFSET;
+ uint8_t *receivedCmdPar = BigBuf_get_addr() + RECV_CMD_PAR_OFFSET;
// The response (tag -> reader) that we're receiving.
- uint8_t *receivedResponse = ((uint8_t *)BigBuf) + RECV_RESP_OFFSET;
- uint8_t *receivedResponsePar = ((uint8_t *)BigBuf) + RECV_RESP_PAR_OFFSET;
+ uint8_t *receivedResponse = BigBuf_get_addr() + RECV_RESP_OFFSET;
+ uint8_t *receivedResponsePar = BigBuf_get_addr() + RECV_RESP_PAR_OFFSET;
// As we receive stuff, we copy it from receivedCmd or receivedResponse
// into trace, along with its length and other annotations.
//uint8_t *trace = (uint8_t *)BigBuf;
// The DMA buffer, used to stream samples from the FPGA
- uint8_t *dmaBuf = ((uint8_t *)BigBuf) + DMA_BUFFER_OFFSET;
+ uint8_t *dmaBuf = BigBuf_get_addr() + DMA_BUFFER_OFFSET;
uint8_t *data = dmaBuf;
uint8_t previous_data = 0;
int maxDataLen = 0;
bool EmLogTrace(uint8_t *reader_data, uint16_t reader_len, uint32_t reader_StartTime, uint32_t reader_EndTime, uint8_t *reader_Parity,
uint8_t *tag_data, uint16_t tag_len, uint32_t tag_StartTime, uint32_t tag_EndTime, uint8_t *tag_Parity);
-static uint8_t* free_buffer_pointer = (((uint8_t *)BigBuf) + FREE_BUFFER_OFFSET);
+static uint8_t* free_buffer_pointer;
typedef struct {
uint8_t* response;
} tag_response_info_t;
void reset_free_buffer() {
- free_buffer_pointer = (((uint8_t *)BigBuf) + FREE_BUFFER_OFFSET);
+ free_buffer_pointer = BigBuf_get_addr() + FREE_BUFFER_OFFSET;
}
bool prepare_tag_modulation(tag_response_info_t* response_info, size_t max_buffer_size) {
response_info->modulation = free_buffer_pointer;
// Determine the maximum size we can use from our buffer
- size_t max_buffer_size = (((uint8_t *)BigBuf) + FREE_BUFFER_OFFSET + FREE_BUFFER_SIZE) - free_buffer_pointer;
+ size_t max_buffer_size = BigBuf_get_addr() + FREE_BUFFER_OFFSET + FREE_BUFFER_SIZE - free_buffer_pointer;
// Forward the prepare tag modulation function to the inner function
if (prepare_tag_modulation(response_info,max_buffer_size)) {
iso14443a_setup(FPGA_HF_ISO14443A_TAGSIM_LISTEN);
// buffers used on software Uart:
- uint8_t *receivedCmd = ((uint8_t *)BigBuf) + RECV_CMD_OFFSET;
- uint8_t *receivedCmdPar = ((uint8_t *)BigBuf) + RECV_CMD_PAR_OFFSET;
+ uint8_t *receivedCmd = BigBuf_get_addr() + RECV_CMD_OFFSET;
+ uint8_t *receivedCmdPar = BigBuf_get_addr() + RECV_CMD_PAR_OFFSET;
cmdsRecvd = 0;
tag_response_info_t* p_response;
uint8_t sel_all[] = { 0x93,0x20 };
uint8_t sel_uid[] = { 0x93,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
uint8_t rats[] = { 0xE0,0x80,0x00,0x00 }; // FSD=256, FSDI=8, CID=0
- uint8_t *resp = ((uint8_t *)BigBuf) + RECV_RESP_OFFSET;
- uint8_t *resp_par = ((uint8_t *)BigBuf) + RECV_RESP_PAR_OFFSET;
+ uint8_t *resp = BigBuf_get_addr() + RECV_RESP_OFFSET;
+ uint8_t *resp_par = BigBuf_get_addr() + RECV_RESP_PAR_OFFSET;
byte_t uid_resp[4];
size_t uid_resp_len;
uint8_t mf_nr_ar[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
static uint8_t mf_nr_ar3;
- uint8_t* receivedAnswer = (((uint8_t *)BigBuf) + RECV_RESP_OFFSET);
- uint8_t* receivedAnswerPar = (((uint8_t *)BigBuf) + RECV_RESP_PAR_OFFSET);
+ uint8_t* receivedAnswer = BigBuf_get_addr() + RECV_RESP_OFFSET;
+ uint8_t* receivedAnswerPar = BigBuf_get_addr() + RECV_RESP_PAR_OFFSET;
iso14a_clear_trace();
iso14a_set_tracing(TRUE);
// The command (reader -> tag) that we're receiving.
// The length of a received command will in most cases be no more than 18 bytes.
// So 32 should be enough!
- uint8_t *receivedCmd = (((uint8_t *)BigBuf) + RECV_CMD_OFFSET);
- uint8_t *receivedCmdPar = ((uint8_t *)BigBuf) + RECV_CMD_PAR_OFFSET;
+ uint8_t *receivedCmd = BigBuf_get_addr() + RECV_CMD_OFFSET;
+ uint8_t *receivedCmdPar = BigBuf_get_addr() + RECV_CMD_PAR_OFFSET;
// The response (tag -> reader) that we're receiving.
- uint8_t *receivedResponse = (((uint8_t *)BigBuf) + RECV_RESP_OFFSET);
- uint8_t *receivedResponsePar = ((uint8_t *)BigBuf) + RECV_RESP_PAR_OFFSET;
+ uint8_t *receivedResponse = BigBuf_get_addr() + RECV_RESP_OFFSET;
+ uint8_t *receivedResponsePar = BigBuf_get_addr() + RECV_RESP_PAR_OFFSET;
// As we receive stuff, we copy it from receivedCmd or receivedResponse
// into trace, along with its length and other annotations.
//uint8_t *trace = (uint8_t *)BigBuf;
// The DMA buffer, used to stream samples from the FPGA
- uint8_t *dmaBuf = ((uint8_t *)BigBuf) + DMA_BUFFER_OFFSET;
+ uint8_t *dmaBuf = BigBuf_get_addr() + DMA_BUFFER_OFFSET;
uint8_t *data = dmaBuf;
uint8_t previous_data = 0;
int maxDataLen = 0;
static int GetIso15693AnswerFromTag(uint8_t *receivedResponse, int maxLen, int *samples, int *elapsed)
{
int c = 0;
- uint8_t *dest = (uint8_t *)BigBuf;
+ uint8_t *dest = BigBuf_get_addr();
int getNext = 0;
int8_t prev = 0;
static int GetIso15693AnswerFromSniff(uint8_t *receivedResponse, int maxLen, int *samples, int *elapsed)
{
int c = 0;
- uint8_t *dest = (uint8_t *)BigBuf;
+ uint8_t *dest = BigBuf_get_addr();
int getNext = 0;
int8_t prev = 0;
//-----------------------------------------------------------------------------
void AcquireRawAdcSamplesIso15693(void)
{
- uint8_t *dest = (uint8_t *)BigBuf;
+ uint8_t *dest = BigBuf_get_addr();
int c = 0;
int getNext = 0;
void RecordRawAdcSamplesIso15693(void)
{
- uint8_t *dest = (uint8_t *)BigBuf;
+ uint8_t *dest = BigBuf_get_addr();
int c = 0;
int getNext = 0;
LED_D_OFF();
int answerLen=0;
- uint8_t *answer = (((uint8_t *)BigBuf) + 3660);
- if (recv!=NULL) memset(BigBuf + 3660, 0, 100);
+ uint8_t *answer = BigBuf_get_addr() + 3660;
+ if (recv != NULL) memset(answer, 0, 100);
if (init) Iso15693InitReader();
LED_C_OFF();
LED_D_OFF();
- uint8_t *answer1 = (((uint8_t *)BigBuf) + 3660); //
- uint8_t *answer2 = (((uint8_t *)BigBuf) + 3760);
- uint8_t *answer3 = (((uint8_t *)BigBuf) + 3860);
+ uint8_t *answer1 = BigBuf_get_addr() + 3660;
+ uint8_t *answer2 = BigBuf_get_addr() + 3760;
+ uint8_t *answer3 = BigBuf_get_addr() + 3860;
int answerLen1 = 0;
int answerLen2 = 0;
// Blank arrays
- memset(BigBuf + 3660, 0x00, 300);
+ memset(answer1, 0x00, 300);
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
LED_C_OFF();
LED_D_OFF();
- uint8_t *buf = (((uint8_t *)BigBuf) + 3660); //
+ uint8_t *buf = BigBuf_get_addr() + 3660;
int answerLen1 = 0;
int samples = 0;
void DirectTag15693Command(uint32_t datalen,uint32_t speed, uint32_t recv, uint8_t data[]) {
int recvlen=0;
- uint8_t *recvbuf=(uint8_t *)BigBuf;
+ uint8_t *recvbuf = BigBuf_get_addr();
// UsbCommand n;
if (DEBUG) {
}
/* Write Time Data into LOG */
+ uint8_t *BigBuf = BigBuf_get_addr();
if(count == 6) { i = -1; } else { i = legic_read_count; }
- ((uint8_t*)BigBuf)[OFFSET_LOG+128+i] = legic_prng_count();
- ((uint8_t*)BigBuf)[OFFSET_LOG+256+i*4] = (legic_prng_bc >> 0) & 0xff;
- ((uint8_t*)BigBuf)[OFFSET_LOG+256+i*4+1] = (legic_prng_bc >> 8) & 0xff;
- ((uint8_t*)BigBuf)[OFFSET_LOG+256+i*4+2] = (legic_prng_bc >>16) & 0xff;
- ((uint8_t*)BigBuf)[OFFSET_LOG+256+i*4+3] = (legic_prng_bc >>24) & 0xff;
- ((uint8_t*)BigBuf)[OFFSET_LOG+384+i] = count;
+ BigBuf[OFFSET_LOG+128+i] = legic_prng_count();
+ BigBuf[OFFSET_LOG+256+i*4] = (legic_prng_bc >> 0) & 0xff;
+ BigBuf[OFFSET_LOG+256+i*4+1] = (legic_prng_bc >> 8) & 0xff;
+ BigBuf[OFFSET_LOG+256+i*4+2] = (legic_prng_bc >>16) & 0xff;
+ BigBuf[OFFSET_LOG+256+i*4+3] = (legic_prng_bc >>24) & 0xff;
+ BigBuf[OFFSET_LOG+384+i] = count;
/* Generate KeyStream */
for(i=0; i<count; i++) {
LegicCommonInit();
+ uint8_t *BigBuf = BigBuf_get_addr();
memset(BigBuf, 0, 1024);
DbpString("setting up legic card");
LED_C_OFF();
return -1;
}
- ((uint8_t*)BigBuf)[byte_index] = r;
+ BigBuf[byte_index] = r;
WDT_HIT();
byte_index++;
if(byte_index & 0x10) LED_C_ON(); else LED_C_OFF();
void LegicRfWriter(int bytes, int offset) {
int byte_index=0, addr_sz=0;
-
+ uint8_t *BigBuf = BigBuf_get_addr();
+
LegicCommonInit();
DbpString("setting up legic card");
perform_setup_phase_rwd(SESSION_IV);
legic_prng_forward(2);
while(byte_index < bytes) {
- int r = legic_write_byte(((uint8_t*)BigBuf)[byte_index+offset], byte_index+offset, addr_sz);
+ int r = legic_write_byte(BigBuf[byte_index+offset], byte_index+offset, addr_sz);
if((r != 0) || BUTTON_PRESS()) {
Dbprintf("operation aborted @ 0x%03.3x", byte_index);
switch_off_tag_rwd();
/* Handle (whether to respond) a frame in tag mode */
static void frame_handle_tag(struct legic_frame const * const f)
{
+ uint8_t *BigBuf = BigBuf_get_addr();
+
/* First Part of Handshake (IV) */
if(f->bits == 7) {
if(f->data == SESSION_IV) {
if(legic_state == STATE_CON) {
int key = get_key_stream(-1, 11); //legic_phase_drift, 11);
int addr = f->data ^ key; addr = addr >> 1;
- int data = ((uint8_t*)BigBuf)[addr];
+ int data = BigBuf[addr];
int hash = LegicCRC(addr, data, 11) << 8;
- ((uint8_t*)BigBuf)[OFFSET_LOG+legic_read_count] = (uint8_t)addr;
+ BigBuf[OFFSET_LOG+legic_read_count] = (uint8_t)addr;
legic_read_count++;
//Dbprintf("Data:%03.3x, key:%03.3x, addr: %03.3x, read_c:%u", f->data, key, addr, read_c);
int i;
Dbprintf("IV: %03.3x", legic_prng_iv);
for(i = 0; i<legic_read_count; i++) {
- Dbprintf("Read Nb: %u, Addr: %u", i, ((uint8_t*)BigBuf)[OFFSET_LOG+i]);
+ Dbprintf("Read Nb: %u, Addr: %u", i, BigBuf[OFFSET_LOG+i]);
}
for(i = -1; i<legic_read_count; i++) {
uint32_t t;
- t = ((uint8_t*)BigBuf)[OFFSET_LOG+256+i*4];
- t |= ((uint8_t*)BigBuf)[OFFSET_LOG+256+i*4+1] << 8;
- t |= ((uint8_t*)BigBuf)[OFFSET_LOG+256+i*4+2] <<16;
- t |= ((uint8_t*)BigBuf)[OFFSET_LOG+256+i*4+3] <<24;
+ t = BigBuf[OFFSET_LOG+256+i*4];
+ t |= BigBuf[OFFSET_LOG+256+i*4+1] << 8;
+ t |= BigBuf[OFFSET_LOG+256+i*4+2] <<16;
+ t |= BigBuf[OFFSET_LOG+256+i*4+3] <<24;
Dbprintf("Cycles: %u, Frame Length: %u, Time: %u",
- ((uint8_t*)BigBuf)[OFFSET_LOG+128+i],
- ((uint8_t*)BigBuf)[OFFSET_LOG+384+i],
+ BigBuf[OFFSET_LOG+128+i],
+ BigBuf[OFFSET_LOG+384+i],
t);
}
}
*/
void DoAcquisition125k_internal(int trigger_threshold,bool silent)
{
- uint8_t *dest = (uint8_t *)BigBuf;
- int n = sizeof(BigBuf);
+ uint8_t *dest = BigBuf_get_addr();
+ int n = BigBuf_max_trace_len();
int i;
memset(dest, 0, n);
#define FREQLO 123200
#define FREQHI 134200
- signed char *dest = (signed char *)BigBuf;
- int n = sizeof(BigBuf);
+ signed char *dest = (signed char *)BigBuf_get_addr();
+ uint16_t n = BigBuf_max_trace_len();
// 128 bit shift register [shift3:shift2:shift1:shift0]
uint32_t shift3 = 0, shift2 = 0, shift1 = 0, shift0 = 0;
#define TIBUFLEN 1250
// clear buffer
- memset(BigBuf,0,sizeof(BigBuf));
+ uint32_t *BigBuf = (uint32_t *)BigBuf_get_addr();
+ memset(BigBuf,0,BigBuf_max_trace_len()/sizeof(uint32_t));
// Set up the synchronous serial port
AT91C_BASE_PIOA->PIO_PDR = GPIO_SSC_DIN;
AT91C_BASE_PIOA->PIO_PDR = GPIO_SSC_DOUT;
AT91C_BASE_PIOA->PIO_ASR = GPIO_SSC_DIN | GPIO_SSC_DOUT;
- char *dest = (char *)BigBuf;
+ char *dest = (char *)BigBuf_get_addr();
n = TIBUFLEN*32;
// unpack buffer
for (i=TIBUFLEN-1; i>=0; i--) {
void SimulateTagLowFrequency(int period, int gap, int ledcontrol)
{
int i;
- uint8_t *tab = (uint8_t *)BigBuf;
+ uint8_t *tab = BigBuf_get_addr();
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT);
// compose fc/8 fc/10 waveform
static void fc(int c, int *n) {
- uint8_t *dest = (uint8_t *)BigBuf;
+ uint8_t *dest = BigBuf_get_addr();
int idx;
// for when we want an fc8 pattern every 4 logical bits
// loop to get raw HID waveform then FSK demodulate the TAG ID from it
void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol)
{
- uint8_t *dest = (uint8_t *)BigBuf;
+ uint8_t *dest = BigBuf_get_addr();
size_t size=sizeof(BigBuf);
uint32_t hi2=0, hi=0, lo=0;
DoAcquisition125k_internal(-1,true);
// FSK demodulator
+ idx = HIDdemodFSK(dest, BigBuf_max_trace_len(), &hi2, &hi, &lo);
WDT_HIT();
size = sizeof(BigBuf);
void CmdEM410xdemod(int findone, int *high, int *low, int ledcontrol)
{
- uint8_t *dest = (uint8_t *)BigBuf;
+ uint8_t *dest = BigBuf_get_addr();
size_t size=0, idx=0;
int clk=0, invert=0, errCnt=0;
if (ledcontrol) LED_A_ON();
DoAcquisition125k_internal(-1,true);
- size = sizeof(BigBuf);
+ size = BigBuf_max_trace_len();
//Dbprintf("DEBUG: Buffer got");
//askdemod and manchester decode
errCnt = askmandemod(dest, &size, &clk, &invert);
void CmdIOdemodFSK(int findone, int *high, int *low, int ledcontrol)
{
- uint8_t *dest = (uint8_t *)BigBuf;
+ uint8_t *dest = BigBuf_get_addr();
int idx=0;
uint32_t code=0, code2=0;
uint8_t version=0;
DoAcquisition125k_internal(-1,true);
//fskdemod and get start index
WDT_HIT();
- idx = IOdemodFSK(dest,sizeof(BigBuf));
+ idx = IOdemodFSK(dest, BigBuf_max_trace_len());
if (idx>0){
//valid tag found
// Read one card block in page 0
void T55xxReadBlock(uint32_t Block, uint32_t Pwd, uint8_t PwdMode)
{
- uint8_t *dest = (uint8_t *)BigBuf;
+ uint8_t *dest = BigBuf_get_addr();
//int m=0, i=0; //enio adjustment 12/10/14
uint32_t m=0, i=0;
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
- m = sizeof(BigBuf);
+ m = BigBuf_max_trace_len();
// Clear destination buffer before sending the command
memset(dest, 128, m);
// Connect the A/D to the peak-detected low-frequency path.
// Read card traceability data (page 1)
void T55xxReadTrace(void){
- uint8_t *dest = (uint8_t *)BigBuf;
+ uint8_t *dest = BigBuf_get_addr();
int m=0, i=0;
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
- m = sizeof(BigBuf);
+ m = BigBuf_max_trace_len();
// Clear destination buffer before sending the command
memset(dest, 128, m);
// Connect the A/D to the peak-detected low-frequency path.
int DemodPCF7931(uint8_t **outBlocks) {
uint8_t BitStream[256];
uint8_t Blocks[8][16];
- uint8_t *GraphBuffer = (uint8_t *)BigBuf;
- int GraphTraceLen = sizeof(BigBuf);
+ uint8_t *GraphBuffer = BigBuf_get_addr();
+ int GraphTraceLen = BigBuf_max_trace_len();
int i, j, lastval, bitidx, half_switch;
int clock = 64;
int tolerance = clock / 8;
void EM4xReadWord(uint8_t Address, uint32_t Pwd, uint8_t PwdMode) {
uint8_t fwd_bit_count;
- uint8_t *dest = (uint8_t *)BigBuf;
+ uint8_t *dest = BigBuf_get_addr();
int m=0, i=0;
//If password mode do login
fwd_bit_count = Prepare_Cmd( FWD_CMD_READ );
fwd_bit_count += Prepare_Addr( Address );
- m = sizeof(BigBuf);
+ m = BigBuf_max_trace_len();
// Clear destination buffer before sending the command
memset(dest, 128, m);
// Connect the A/D to the peak-detected low-frequency path.
int pckSize = 0;\r
int pckLen = traceLen;\r
int pckNum = 0;\r
-\r
+ uint8_t *trace = BigBuf_get_addr();\r
+ \r
FpgaDisableSscDma();\r
while (pckLen > 0) {\r
pckSize = MIN(USB_CMD_DATA_SIZE, pckLen);\r
\r
// memory management\r
uint8_t* get_bigbufptr_recvrespbuf(void) {\r
- return (((uint8_t *)BigBuf) + RECV_RESP_OFFSET); \r
+ return BigBuf_get_addr() + RECV_RESP_OFFSET; \r
}\r
uint8_t* get_bigbufptr_recvcmdbuf(void) {\r
- return (((uint8_t *)BigBuf) + RECV_CMD_OFFSET); \r
+ return BigBuf_get_addr() + RECV_CMD_OFFSET; \r
}\r
uint8_t* get_bigbufptr_emlcardmem(void) {\r
- return (((uint8_t *)BigBuf) + CARD_MEMORY_OFFSET);\r
+ return BigBuf_get_addr() + CARD_MEMORY_OFFSET;\r
}\r
\r
// crypto1 helpers\r
return 0;\r
}\r
return 1;\r
-}
\ No newline at end of file
+}