mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-19 12:59:44 -07:00
- fix: ensure that FpgaDownloadAndGo() is always called before requesting
any memory from BigBuf[]. This is required because FpgaDownloadAndGo() might allocate, use, and free most of BigBuf[] when decompressing FPGA configs. - cleanup: remove rests of deprecated "end of trace markers" (0x44)
This commit is contained in:
parent
a88c28271c
commit
09ffd16ee2
7 changed files with 105 additions and 111 deletions
|
@ -96,9 +96,6 @@ uint16_t BigBuf_max_traceLen(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear_trace() {
|
void clear_trace() {
|
||||||
uint8_t *trace = BigBuf_get_addr();
|
|
||||||
uint16_t max_traceLen = BigBuf_max_traceLen();
|
|
||||||
memset(trace, 0x44, max_traceLen);
|
|
||||||
traceLen = 0;
|
traceLen = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,13 +173,10 @@ bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_
|
||||||
}
|
}
|
||||||
traceLen += num_paritybytes;
|
traceLen += num_paritybytes;
|
||||||
|
|
||||||
if(traceLen +4 < max_traceLen)
|
|
||||||
{ //If it hadn't been cleared, for whatever reason..
|
|
||||||
memset(trace+traceLen,0x44, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LogTraceHitag(const uint8_t * btBytes, int iBits, int iSamples, uint32_t dwParity, int readerToTag)
|
int LogTraceHitag(const uint8_t * btBytes, int iBits, int iSamples, uint32_t dwParity, int readerToTag)
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -710,22 +710,24 @@ void SnoopHitag(uint32_t type) {
|
||||||
byte_t rx[HITAG_FRAME_LEN];
|
byte_t rx[HITAG_FRAME_LEN];
|
||||||
size_t rxlen=0;
|
size_t rxlen=0;
|
||||||
|
|
||||||
auth_table_len = 0;
|
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
||||||
auth_table_pos = 0;
|
|
||||||
BigBuf_free();
|
|
||||||
auth_table = (byte_t *)BigBuf_malloc(AUTH_TABLE_LENGTH);
|
|
||||||
memset(auth_table, 0x00, AUTH_TABLE_LENGTH);
|
|
||||||
|
|
||||||
// Clean up trace and prepare it for storing frames
|
// Clean up trace and prepare it for storing frames
|
||||||
set_tracing(TRUE);
|
set_tracing(TRUE);
|
||||||
clear_trace();
|
clear_trace();
|
||||||
|
|
||||||
|
auth_table_len = 0;
|
||||||
|
auth_table_pos = 0;
|
||||||
|
|
||||||
|
BigBuf_free();
|
||||||
|
auth_table = (byte_t *)BigBuf_malloc(AUTH_TABLE_LENGTH);
|
||||||
|
memset(auth_table, 0x00, AUTH_TABLE_LENGTH);
|
||||||
|
|
||||||
DbpString("Starting Hitag2 snoop");
|
DbpString("Starting Hitag2 snoop");
|
||||||
LED_D_ON();
|
LED_D_ON();
|
||||||
|
|
||||||
// Set up eavesdropping mode, frequency divisor which will drive the FPGA
|
// Set up eavesdropping mode, frequency divisor which will drive the FPGA
|
||||||
// and analog mux selection.
|
// and analog mux selection.
|
||||||
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT | FPGA_LF_EDGE_DETECT_TOGGLE_MODE);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT | FPGA_LF_EDGE_DETECT_TOGGLE_MODE);
|
||||||
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
|
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
|
||||||
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
|
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
|
||||||
|
@ -922,6 +924,12 @@ void SimulateHitagTag(bool tag_mem_supplied, byte_t* data) {
|
||||||
bool bQuitTraceFull = false;
|
bool bQuitTraceFull = false;
|
||||||
bQuiet = false;
|
bQuiet = false;
|
||||||
|
|
||||||
|
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
||||||
|
|
||||||
|
// Clean up trace and prepare it for storing frames
|
||||||
|
set_tracing(TRUE);
|
||||||
|
clear_trace();
|
||||||
|
|
||||||
auth_table_len = 0;
|
auth_table_len = 0;
|
||||||
auth_table_pos = 0;
|
auth_table_pos = 0;
|
||||||
byte_t* auth_table;
|
byte_t* auth_table;
|
||||||
|
@ -929,10 +937,6 @@ void SimulateHitagTag(bool tag_mem_supplied, byte_t* data) {
|
||||||
auth_table = (byte_t *)BigBuf_malloc(AUTH_TABLE_LENGTH);
|
auth_table = (byte_t *)BigBuf_malloc(AUTH_TABLE_LENGTH);
|
||||||
memset(auth_table, 0x00, AUTH_TABLE_LENGTH);
|
memset(auth_table, 0x00, AUTH_TABLE_LENGTH);
|
||||||
|
|
||||||
// Clean up trace and prepare it for storing frames
|
|
||||||
set_tracing(TRUE);
|
|
||||||
clear_trace();
|
|
||||||
|
|
||||||
DbpString("Starting Hitag2 simulation");
|
DbpString("Starting Hitag2 simulation");
|
||||||
LED_D_ON();
|
LED_D_ON();
|
||||||
hitag2_init();
|
hitag2_init();
|
||||||
|
@ -953,7 +957,6 @@ void SimulateHitagTag(bool tag_mem_supplied, byte_t* data) {
|
||||||
|
|
||||||
// Set up simulator mode, frequency divisor which will drive the FPGA
|
// Set up simulator mode, frequency divisor which will drive the FPGA
|
||||||
// and analog mux selection.
|
// and analog mux selection.
|
||||||
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT | FPGA_LF_EDGE_DETECT_READER_FIELD);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT | FPGA_LF_EDGE_DETECT_READER_FIELD);
|
||||||
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
|
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
|
||||||
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
|
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
|
||||||
|
|
|
@ -1125,7 +1125,6 @@ int doIClassSimulation( int simulationMode, uint8_t *reader_mac_buf)
|
||||||
int resp_cc_len;
|
int resp_cc_len;
|
||||||
|
|
||||||
uint8_t *receivedCmd = BigBuf_malloc(MAX_FRAME_SIZE);
|
uint8_t *receivedCmd = BigBuf_malloc(MAX_FRAME_SIZE);
|
||||||
memset(receivedCmd, 0x44, MAX_FRAME_SIZE);
|
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
// Prepare card messages
|
// Prepare card messages
|
||||||
|
@ -1336,7 +1335,6 @@ int doIClassSimulation( int simulationMode, uint8_t *reader_mac_buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
memset(receivedCmd, 0x44, MAX_FRAME_SIZE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Dbprintf("%x", cmdsRecvd);
|
//Dbprintf("%x", cmdsRecvd);
|
||||||
|
|
|
@ -551,12 +551,8 @@ void RAMFUNC SnoopIso14443a(uint8_t param) {
|
||||||
|
|
||||||
LEDsoff();
|
LEDsoff();
|
||||||
|
|
||||||
// We won't start recording the frames that we acquire until we trigger;
|
iso14443a_setup(FPGA_HF_ISO14443A_SNIFFER);
|
||||||
// a good trigger condition to get started is probably when we see a
|
|
||||||
// response from the tag.
|
|
||||||
// triggered == FALSE -- to wait first for card
|
|
||||||
bool triggered = !(param & 0x03);
|
|
||||||
|
|
||||||
// Allocate memory from BigBuf for some buffers
|
// Allocate memory from BigBuf for some buffers
|
||||||
// free all previous allocations first
|
// free all previous allocations first
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
|
@ -583,8 +579,6 @@ void RAMFUNC SnoopIso14443a(uint8_t param) {
|
||||||
bool TagIsActive = FALSE;
|
bool TagIsActive = FALSE;
|
||||||
bool ReaderIsActive = FALSE;
|
bool ReaderIsActive = FALSE;
|
||||||
|
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_SNIFFER);
|
|
||||||
|
|
||||||
// Set up the demodulator for tag -> reader responses.
|
// Set up the demodulator for tag -> reader responses.
|
||||||
DemodInit(receivedResponse, receivedResponsePar);
|
DemodInit(receivedResponse, receivedResponsePar);
|
||||||
|
|
||||||
|
@ -594,6 +588,12 @@ void RAMFUNC SnoopIso14443a(uint8_t param) {
|
||||||
// Setup and start DMA.
|
// Setup and start DMA.
|
||||||
FpgaSetupSscDma((uint8_t *)dmaBuf, DMA_BUFFER_SIZE);
|
FpgaSetupSscDma((uint8_t *)dmaBuf, DMA_BUFFER_SIZE);
|
||||||
|
|
||||||
|
// We won't start recording the frames that we acquire until we trigger;
|
||||||
|
// a good trigger condition to get started is probably when we see a
|
||||||
|
// response from the tag.
|
||||||
|
// triggered == FALSE -- to wait first for card
|
||||||
|
bool triggered = !(param & 0x03);
|
||||||
|
|
||||||
// And now we loop, receiving samples.
|
// And now we loop, receiving samples.
|
||||||
for(uint32_t rsamples = 0; TRUE; ) {
|
for(uint32_t rsamples = 0; TRUE; ) {
|
||||||
|
|
||||||
|
@ -1026,6 +1026,9 @@ void SimulateIso14443aTag(int tagType, int uid_1st, int uid_2nd, byte_t* data)
|
||||||
.modulation_n = 0
|
.modulation_n = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// We need to listen to the high-frequency, peak-detected path.
|
||||||
|
iso14443a_setup(FPGA_HF_ISO14443A_TAGSIM_LISTEN);
|
||||||
|
|
||||||
BigBuf_free_keep_EM();
|
BigBuf_free_keep_EM();
|
||||||
|
|
||||||
// allocate buffers:
|
// allocate buffers:
|
||||||
|
@ -1054,9 +1057,6 @@ void SimulateIso14443aTag(int tagType, int uid_1st, int uid_2nd, byte_t* data)
|
||||||
int happened2 = 0;
|
int happened2 = 0;
|
||||||
int cmdsRecvd = 0;
|
int cmdsRecvd = 0;
|
||||||
|
|
||||||
// We need to listen to the high-frequency, peak-detected path.
|
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_TAGSIM_LISTEN);
|
|
||||||
|
|
||||||
cmdsRecvd = 0;
|
cmdsRecvd = 0;
|
||||||
tag_response_info_t* p_response;
|
tag_response_info_t* p_response;
|
||||||
|
|
||||||
|
@ -1994,6 +1994,10 @@ void ReaderMifare(bool first_try)
|
||||||
uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE];
|
uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE];
|
||||||
uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE];
|
uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE];
|
||||||
|
|
||||||
|
if (first_try) {
|
||||||
|
iso14443a_setup(FPGA_HF_ISO14443A_READER_MOD);
|
||||||
|
}
|
||||||
|
|
||||||
// free eventually allocated BigBuf memory. We want all for tracing.
|
// free eventually allocated BigBuf memory. We want all for tracing.
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
|
|
||||||
|
@ -2022,7 +2026,6 @@ void ReaderMifare(bool first_try)
|
||||||
|
|
||||||
if (first_try) {
|
if (first_try) {
|
||||||
mf_nr_ar3 = 0;
|
mf_nr_ar3 = 0;
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_MOD);
|
|
||||||
sync_time = GetCountSspClk() & 0xfffffff8;
|
sync_time = GetCountSspClk() & 0xfffffff8;
|
||||||
sync_cycles = 65536; // theory: Mifare Classic's random generator repeats every 2^16 cycles (and so do the nonces).
|
sync_cycles = 65536; // theory: Mifare Classic's random generator repeats every 2^16 cycles (and so do the nonces).
|
||||||
nt_attacked = 0;
|
nt_attacked = 0;
|
||||||
|
@ -2239,13 +2242,6 @@ void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t *
|
||||||
uint32_t ar_nr_responses[] = {0,0,0,0,0,0,0,0};
|
uint32_t ar_nr_responses[] = {0,0,0,0,0,0,0,0};
|
||||||
uint8_t ar_nr_collected = 0;
|
uint8_t ar_nr_collected = 0;
|
||||||
|
|
||||||
// free eventually allocated BigBuf memory but keep Emulator Memory
|
|
||||||
BigBuf_free_keep_EM();
|
|
||||||
|
|
||||||
// clear trace
|
|
||||||
clear_trace();
|
|
||||||
set_tracing(TRUE);
|
|
||||||
|
|
||||||
// Authenticate response - nonce
|
// Authenticate response - nonce
|
||||||
uint32_t nonce = bytes_to_num(rAUTH_NT, 4);
|
uint32_t nonce = bytes_to_num(rAUTH_NT, 4);
|
||||||
|
|
||||||
|
@ -2287,10 +2283,6 @@ void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t *
|
||||||
rUIDBCC2[4] = rUIDBCC2[0] ^ rUIDBCC2[1] ^ rUIDBCC2[2] ^ rUIDBCC2[3];
|
rUIDBCC2[4] = rUIDBCC2[0] ^ rUIDBCC2[1] ^ rUIDBCC2[2] ^ rUIDBCC2[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need to listen to the high-frequency, peak-detected path.
|
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_TAGSIM_LISTEN);
|
|
||||||
|
|
||||||
|
|
||||||
if (MF_DBGLEVEL >= 1) {
|
if (MF_DBGLEVEL >= 1) {
|
||||||
if (!_7BUID) {
|
if (!_7BUID) {
|
||||||
Dbprintf("4B UID: %02x%02x%02x%02x",
|
Dbprintf("4B UID: %02x%02x%02x%02x",
|
||||||
|
@ -2302,6 +2294,17 @@ void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We need to listen to the high-frequency, peak-detected path.
|
||||||
|
iso14443a_setup(FPGA_HF_ISO14443A_TAGSIM_LISTEN);
|
||||||
|
|
||||||
|
// free eventually allocated BigBuf memory but keep Emulator Memory
|
||||||
|
BigBuf_free_keep_EM();
|
||||||
|
|
||||||
|
// clear trace
|
||||||
|
clear_trace();
|
||||||
|
set_tracing(TRUE);
|
||||||
|
|
||||||
|
|
||||||
bool finished = FALSE;
|
bool finished = FALSE;
|
||||||
while (!BUTTON_PRESS() && !finished) {
|
while (!BUTTON_PRESS() && !finished) {
|
||||||
WDT_HIT();
|
WDT_HIT();
|
||||||
|
@ -2720,10 +2723,8 @@ void RAMFUNC SniffMifare(uint8_t param) {
|
||||||
uint8_t receivedResponse[MAX_MIFARE_FRAME_SIZE];
|
uint8_t receivedResponse[MAX_MIFARE_FRAME_SIZE];
|
||||||
uint8_t receivedResponsePar[MAX_MIFARE_PARITY_SIZE];
|
uint8_t receivedResponsePar[MAX_MIFARE_PARITY_SIZE];
|
||||||
|
|
||||||
// As we receive stuff, we copy it from receivedCmd or receivedResponse
|
iso14443a_setup(FPGA_HF_ISO14443A_SNIFFER);
|
||||||
// into trace, along with its length and other annotations.
|
|
||||||
//uint8_t *trace = (uint8_t *)BigBuf;
|
|
||||||
|
|
||||||
// free eventually allocated BigBuf memory
|
// free eventually allocated BigBuf memory
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
// allocate the DMA buffer, used to stream samples from the FPGA
|
// allocate the DMA buffer, used to stream samples from the FPGA
|
||||||
|
@ -2735,8 +2736,6 @@ void RAMFUNC SniffMifare(uint8_t param) {
|
||||||
bool ReaderIsActive = FALSE;
|
bool ReaderIsActive = FALSE;
|
||||||
bool TagIsActive = FALSE;
|
bool TagIsActive = FALSE;
|
||||||
|
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_SNIFFER);
|
|
||||||
|
|
||||||
// Set up the demodulator for tag -> reader responses.
|
// Set up the demodulator for tag -> reader responses.
|
||||||
DemodInit(receivedResponse, receivedResponsePar);
|
DemodInit(receivedResponse, receivedResponsePar);
|
||||||
|
|
||||||
|
|
|
@ -334,6 +334,8 @@ void SimulateIso14443bTag(void)
|
||||||
0x00, 0x21, 0x85, 0x5e, 0xd7
|
0x00, 0x21, 0x85, 0x5e, 0xd7
|
||||||
};
|
};
|
||||||
|
|
||||||
|
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||||
|
|
||||||
clear_trace();
|
clear_trace();
|
||||||
set_tracing(TRUE);
|
set_tracing(TRUE);
|
||||||
|
|
||||||
|
@ -348,8 +350,6 @@ void SimulateIso14443bTag(void)
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
uint16_t cmdsRecvd = 0;
|
uint16_t cmdsRecvd = 0;
|
||||||
|
|
||||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
|
||||||
|
|
||||||
// prepare the (only one) tag answer:
|
// prepare the (only one) tag answer:
|
||||||
CodeIso14443bAsTag(response1, sizeof(response1));
|
CodeIso14443bAsTag(response1, sizeof(response1));
|
||||||
uint8_t *resp1Code = BigBuf_malloc(ToSendMax);
|
uint8_t *resp1Code = BigBuf_malloc(ToSendMax);
|
||||||
|
@ -908,9 +908,6 @@ static void CodeAndTransmit14443bAsReader(const uint8_t *cmd, int len)
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void ReadSTMemoryIso14443b(uint32_t dwLast)
|
void ReadSTMemoryIso14443b(uint32_t dwLast)
|
||||||
{
|
{
|
||||||
clear_trace();
|
|
||||||
set_tracing(TRUE);
|
|
||||||
|
|
||||||
uint8_t i = 0x00;
|
uint8_t i = 0x00;
|
||||||
|
|
||||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||||
|
@ -929,6 +926,9 @@ void ReadSTMemoryIso14443b(uint32_t dwLast)
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR | FPGA_HF_READER_RX_XCORR_848_KHZ);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR | FPGA_HF_READER_RX_XCORR_848_KHZ);
|
||||||
SpinDelay(200);
|
SpinDelay(200);
|
||||||
|
|
||||||
|
clear_trace();
|
||||||
|
set_tracing(TRUE);
|
||||||
|
|
||||||
// First command: wake up the tag using the INITIATE command
|
// First command: wake up the tag using the INITIATE command
|
||||||
uint8_t cmd1[] = {0x06, 0x00, 0x97, 0x5b};
|
uint8_t cmd1[] = {0x06, 0x00, 0x97, 0x5b};
|
||||||
CodeAndTransmit14443bAsReader(cmd1, sizeof(cmd1));
|
CodeAndTransmit14443bAsReader(cmd1, sizeof(cmd1));
|
||||||
|
|
|
@ -877,12 +877,12 @@ int SendDataTag(uint8_t *send, int sendlen, int init, int speed, uint8_t **recv)
|
||||||
LED_C_OFF();
|
LED_C_OFF();
|
||||||
LED_D_OFF();
|
LED_D_OFF();
|
||||||
|
|
||||||
|
if (init) Iso15693InitReader();
|
||||||
|
|
||||||
int answerLen=0;
|
int answerLen=0;
|
||||||
uint8_t *answer = BigBuf_get_addr() + 3660;
|
uint8_t *answer = BigBuf_get_addr() + 3660;
|
||||||
if (recv != NULL) memset(answer, 0, 100);
|
if (recv != NULL) memset(answer, 0, 100);
|
||||||
|
|
||||||
if (init) Iso15693InitReader();
|
|
||||||
|
|
||||||
if (!speed) {
|
if (!speed) {
|
||||||
// low speed (1 out of 256)
|
// low speed (1 out of 256)
|
||||||
CodeIso15693AsReader256(send, sendlen);
|
CodeIso15693AsReader256(send, sendlen);
|
||||||
|
@ -999,10 +999,6 @@ void ReaderIso15693(uint32_t parameter)
|
||||||
LED_C_OFF();
|
LED_C_OFF();
|
||||||
LED_D_OFF();
|
LED_D_OFF();
|
||||||
|
|
||||||
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 answerLen1 = 0;
|
||||||
int answerLen2 = 0;
|
int answerLen2 = 0;
|
||||||
int answerLen3 = 0;
|
int answerLen3 = 0;
|
||||||
|
@ -1013,19 +1009,21 @@ void ReaderIso15693(uint32_t parameter)
|
||||||
int elapsed = 0;
|
int elapsed = 0;
|
||||||
uint8_t TagUID[8] = {0x00};
|
uint8_t TagUID[8] = {0x00};
|
||||||
|
|
||||||
|
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||||
|
|
||||||
|
uint8_t *answer1 = BigBuf_get_addr() + 3660;
|
||||||
|
uint8_t *answer2 = BigBuf_get_addr() + 3760;
|
||||||
|
uint8_t *answer3 = BigBuf_get_addr() + 3860;
|
||||||
// Blank arrays
|
// Blank arrays
|
||||||
memset(answer1, 0x00, 300);
|
memset(answer1, 0x00, 300);
|
||||||
|
|
||||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
|
||||||
|
|
||||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||||
// Setup SSC
|
// Setup SSC
|
||||||
FpgaSetupSsc();
|
FpgaSetupSsc();
|
||||||
|
|
||||||
// Start from off (no field generated)
|
// Start from off (no field generated)
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
SpinDelay(200);
|
SpinDelay(200);
|
||||||
|
|
||||||
// Give the tags time to energize
|
// Give the tags time to energize
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
|
||||||
|
@ -1111,24 +1109,22 @@ void SimTagIso15693(uint32_t parameter, uint8_t *uid)
|
||||||
LED_C_OFF();
|
LED_C_OFF();
|
||||||
LED_D_OFF();
|
LED_D_OFF();
|
||||||
|
|
||||||
uint8_t *buf = BigBuf_get_addr() + 3660;
|
|
||||||
|
|
||||||
int answerLen1 = 0;
|
int answerLen1 = 0;
|
||||||
int samples = 0;
|
int samples = 0;
|
||||||
int tsamples = 0;
|
int tsamples = 0;
|
||||||
int wait = 0;
|
int wait = 0;
|
||||||
int elapsed = 0;
|
int elapsed = 0;
|
||||||
|
|
||||||
memset(buf, 0x00, 100);
|
|
||||||
|
|
||||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||||
|
|
||||||
|
uint8_t *buf = BigBuf_get_addr() + 3660;
|
||||||
|
memset(buf, 0x00, 100);
|
||||||
|
|
||||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||||
|
|
||||||
FpgaSetupSsc();
|
FpgaSetupSsc();
|
||||||
|
|
||||||
// Start from off (no field generated)
|
// Start from off (no field generated)
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
SpinDelay(200);
|
SpinDelay(200);
|
||||||
|
|
||||||
LED_A_OFF();
|
LED_A_OFF();
|
||||||
|
|
|
@ -44,10 +44,10 @@ void MifareReadBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
|
||||||
struct Crypto1State *pcs;
|
struct Crypto1State *pcs;
|
||||||
pcs = &mpcs;
|
pcs = &mpcs;
|
||||||
|
|
||||||
// clear trace
|
|
||||||
clear_trace();
|
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
||||||
|
|
||||||
|
clear_trace();
|
||||||
|
|
||||||
LED_A_ON();
|
LED_A_ON();
|
||||||
LED_B_OFF();
|
LED_B_OFF();
|
||||||
LED_C_OFF();
|
LED_C_OFF();
|
||||||
|
@ -95,9 +95,11 @@ void MifareUC_Auth(uint8_t arg0, uint8_t *keybytes){
|
||||||
bool turnOffField = (arg0 == 1);
|
bool turnOffField = (arg0 == 1);
|
||||||
|
|
||||||
LED_A_ON(); LED_B_OFF(); LED_C_OFF();
|
LED_A_ON(); LED_B_OFF(); LED_C_OFF();
|
||||||
clear_trace();
|
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
||||||
|
|
||||||
|
clear_trace();
|
||||||
|
|
||||||
if(!iso14443a_select_card(NULL, NULL, NULL)) {
|
if(!iso14443a_select_card(NULL, NULL, NULL)) {
|
||||||
if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Can't select card");
|
if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Can't select card");
|
||||||
OnError(0);
|
OnError(0);
|
||||||
|
@ -129,9 +131,10 @@ void MifareUReadBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain)
|
||||||
|
|
||||||
LEDsoff();
|
LEDsoff();
|
||||||
LED_A_ON();
|
LED_A_ON();
|
||||||
clear_trace();
|
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
||||||
|
|
||||||
|
clear_trace();
|
||||||
|
|
||||||
int len = iso14443a_select_card(NULL, NULL, NULL);
|
int len = iso14443a_select_card(NULL, NULL, NULL);
|
||||||
if(!len) {
|
if(!len) {
|
||||||
if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Can't select card (RC:%02X)",len);
|
if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Can't select card (RC:%02X)",len);
|
||||||
|
@ -199,11 +202,10 @@ void MifareReadSector(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
|
||||||
struct Crypto1State *pcs;
|
struct Crypto1State *pcs;
|
||||||
pcs = &mpcs;
|
pcs = &mpcs;
|
||||||
|
|
||||||
// clear trace
|
|
||||||
clear_trace();
|
|
||||||
|
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
||||||
|
|
||||||
|
clear_trace();
|
||||||
|
|
||||||
LED_A_ON();
|
LED_A_ON();
|
||||||
LED_B_OFF();
|
LED_B_OFF();
|
||||||
LED_C_OFF();
|
LED_C_OFF();
|
||||||
|
@ -252,6 +254,10 @@ void MifareReadSector(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
|
||||||
// datain = KEY bytes
|
// datain = KEY bytes
|
||||||
void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain)
|
void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain)
|
||||||
{
|
{
|
||||||
|
LEDsoff();
|
||||||
|
LED_A_ON();
|
||||||
|
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
||||||
|
|
||||||
// free eventually allocated BigBuf memory
|
// free eventually allocated BigBuf memory
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
clear_trace();
|
clear_trace();
|
||||||
|
@ -269,10 +275,6 @@ void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LEDsoff();
|
|
||||||
LED_A_ON();
|
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
|
||||||
|
|
||||||
int len = iso14443a_select_card(NULL, NULL, NULL);
|
int len = iso14443a_select_card(NULL, NULL, NULL);
|
||||||
if (!len) {
|
if (!len) {
|
||||||
if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Can't select card (RC:%d)",len);
|
if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Can't select card (RC:%d)",len);
|
||||||
|
@ -366,11 +368,10 @@ void MifareWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
|
||||||
struct Crypto1State *pcs;
|
struct Crypto1State *pcs;
|
||||||
pcs = &mpcs;
|
pcs = &mpcs;
|
||||||
|
|
||||||
// clear trace
|
|
||||||
clear_trace();
|
|
||||||
|
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
||||||
|
|
||||||
|
clear_trace();
|
||||||
|
|
||||||
LED_A_ON();
|
LED_A_ON();
|
||||||
LED_B_OFF();
|
LED_B_OFF();
|
||||||
LED_C_OFF();
|
LED_C_OFF();
|
||||||
|
@ -472,9 +473,10 @@ void MifareUWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain)
|
||||||
|
|
||||||
LEDsoff();
|
LEDsoff();
|
||||||
LED_A_ON();
|
LED_A_ON();
|
||||||
clear_trace();
|
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
||||||
|
|
||||||
|
clear_trace();
|
||||||
|
|
||||||
if(!iso14443a_select_card(NULL, NULL, NULL)) {
|
if(!iso14443a_select_card(NULL, NULL, NULL)) {
|
||||||
if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card");
|
if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card");
|
||||||
OnError(0);
|
OnError(0);
|
||||||
|
@ -530,9 +532,10 @@ void MifareUSetPwd(uint8_t arg0, uint8_t *datain){
|
||||||
memcpy(pwd, datain, 16);
|
memcpy(pwd, datain, 16);
|
||||||
|
|
||||||
LED_A_ON(); LED_B_OFF(); LED_C_OFF();
|
LED_A_ON(); LED_B_OFF(); LED_C_OFF();
|
||||||
clear_trace();
|
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
||||||
|
|
||||||
|
clear_trace();
|
||||||
|
|
||||||
if(!iso14443a_select_card(NULL, NULL, NULL)) {
|
if(!iso14443a_select_card(NULL, NULL, NULL)) {
|
||||||
if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card");
|
if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card");
|
||||||
OnError(0);
|
OnError(0);
|
||||||
|
@ -632,18 +635,16 @@ void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t calibrate, uint8_t *dat
|
||||||
uint32_t auth1_time, auth2_time;
|
uint32_t auth1_time, auth2_time;
|
||||||
static uint16_t delta_time;
|
static uint16_t delta_time;
|
||||||
|
|
||||||
|
LED_A_ON();
|
||||||
|
LED_C_OFF();
|
||||||
|
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
||||||
|
|
||||||
// free eventually allocated BigBuf memory
|
// free eventually allocated BigBuf memory
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
// clear trace
|
|
||||||
clear_trace();
|
clear_trace();
|
||||||
set_tracing(false);
|
set_tracing(false);
|
||||||
|
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
|
||||||
|
|
||||||
LED_A_ON();
|
|
||||||
LED_C_OFF();
|
|
||||||
|
|
||||||
|
|
||||||
// statistics on nonce distance
|
// statistics on nonce distance
|
||||||
int16_t isOK = 0;
|
int16_t isOK = 0;
|
||||||
#define NESTED_MAX_TRIES 12
|
#define NESTED_MAX_TRIES 12
|
||||||
|
@ -847,15 +848,13 @@ void MifareChkKeys(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
|
||||||
int OLD_MF_DBGLEVEL = MF_DBGLEVEL;
|
int OLD_MF_DBGLEVEL = MF_DBGLEVEL;
|
||||||
MF_DBGLEVEL = MF_DBG_NONE;
|
MF_DBGLEVEL = MF_DBG_NONE;
|
||||||
|
|
||||||
// clear trace
|
|
||||||
clear_trace();
|
|
||||||
set_tracing(TRUE);
|
|
||||||
|
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
|
||||||
|
|
||||||
LED_A_ON();
|
LED_A_ON();
|
||||||
LED_B_OFF();
|
LED_B_OFF();
|
||||||
LED_C_OFF();
|
LED_C_OFF();
|
||||||
|
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
||||||
|
|
||||||
|
clear_trace();
|
||||||
|
set_tracing(TRUE);
|
||||||
|
|
||||||
for (i = 0; i < keyCount; i++) {
|
for (i = 0; i < keyCount; i++) {
|
||||||
if(mifare_classic_halt(pcs, cuid)) {
|
if(mifare_classic_halt(pcs, cuid)) {
|
||||||
|
@ -902,16 +901,23 @@ void MifareSetDbgLvl(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datai
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Work with emulator memory
|
// Work with emulator memory
|
||||||
//
|
//
|
||||||
|
// Note: we call FpgaDownloadAndGo(FPGA_BITSTREAM_HF) here although FPGA is not
|
||||||
|
// involved in dealing with emulator memory. But if it is called later, it might
|
||||||
|
// destroy the Emulator Memory.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
void MifareEMemClr(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain){
|
void MifareEMemClr(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain){
|
||||||
|
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||||
emlClearMem();
|
emlClearMem();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MifareEMemSet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain){
|
void MifareEMemSet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain){
|
||||||
|
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||||
emlSetMem(datain, arg0, arg1); // data, block num, blocks count
|
emlSetMem(datain, arg0, arg1); // data, block num, blocks count
|
||||||
}
|
}
|
||||||
|
|
||||||
void MifareEMemGet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain){
|
void MifareEMemGet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain){
|
||||||
|
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||||
byte_t buf[USB_CMD_DATA_SIZE];
|
byte_t buf[USB_CMD_DATA_SIZE];
|
||||||
emlGetMem(buf, arg0, arg1); // data, block num, blocks count (max 4)
|
emlGetMem(buf, arg0, arg1); // data, block num, blocks count (max 4)
|
||||||
|
|
||||||
|
@ -938,15 +944,13 @@ void MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datai
|
||||||
byte_t dataoutbuf2[16];
|
byte_t dataoutbuf2[16];
|
||||||
uint8_t uid[10];
|
uint8_t uid[10];
|
||||||
|
|
||||||
// clear trace
|
|
||||||
clear_trace();
|
|
||||||
set_tracing(false);
|
|
||||||
|
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
|
||||||
|
|
||||||
LED_A_ON();
|
LED_A_ON();
|
||||||
LED_B_OFF();
|
LED_B_OFF();
|
||||||
LED_C_OFF();
|
LED_C_OFF();
|
||||||
|
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
||||||
|
|
||||||
|
clear_trace();
|
||||||
|
set_tracing(false);
|
||||||
|
|
||||||
bool isOK = true;
|
bool isOK = true;
|
||||||
|
|
||||||
|
@ -1040,10 +1044,10 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datai
|
||||||
LED_A_ON();
|
LED_A_ON();
|
||||||
LED_B_OFF();
|
LED_B_OFF();
|
||||||
LED_C_OFF();
|
LED_C_OFF();
|
||||||
|
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
||||||
|
|
||||||
clear_trace();
|
clear_trace();
|
||||||
set_tracing(TRUE);
|
set_tracing(TRUE);
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -1158,10 +1162,10 @@ void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datai
|
||||||
LED_A_ON();
|
LED_A_ON();
|
||||||
LED_B_OFF();
|
LED_B_OFF();
|
||||||
LED_C_OFF();
|
LED_C_OFF();
|
||||||
|
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
||||||
|
|
||||||
clear_trace();
|
clear_trace();
|
||||||
set_tracing(TRUE);
|
set_tracing(TRUE);
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -1236,7 +1240,7 @@ void MifareCIdent(){
|
||||||
cmd_send(CMD_ACK,isOK,0,0,0,0);
|
cmd_send(CMD_ACK,isOK,0,0,0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// DESFIRE
|
// DESFIRE
|
||||||
//
|
//
|
||||||
|
|
||||||
|
@ -1246,8 +1250,8 @@ void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain){
|
||||||
uint8_t uid[10] = {0x00};
|
uint8_t uid[10] = {0x00};
|
||||||
uint32_t cuid;
|
uint32_t cuid;
|
||||||
|
|
||||||
clear_trace();
|
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
||||||
|
clear_trace();
|
||||||
|
|
||||||
int len = iso14443a_select_card(uid, NULL, &cuid);
|
int len = iso14443a_select_card(uid, NULL, &cuid);
|
||||||
if(!len) {
|
if(!len) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue