mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 13:23:51 -07:00
rename globals
This commit is contained in:
parent
437f5f6448
commit
5b54385347
34 changed files with 458 additions and 458 deletions
|
@ -169,7 +169,7 @@ void BigBuf_print_status(void) {
|
||||||
Dbprintf(" tracing ................ %d", tracing);
|
Dbprintf(" tracing ................ %d", tracing);
|
||||||
Dbprintf(" traceLen ............... %d", trace_len);
|
Dbprintf(" traceLen ............... %d", trace_len);
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
DbpString(_CYAN_("Sending buffers"));
|
DbpString(_CYAN_("Sending buffers"));
|
||||||
|
|
||||||
uint16_t d8 = 0;
|
uint16_t d8 = 0;
|
||||||
|
@ -250,7 +250,7 @@ bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_
|
||||||
|
|
||||||
if (duration > 0xFFFF) {
|
if (duration > 0xFFFF) {
|
||||||
/*
|
/*
|
||||||
if (DBGLEVEL >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
Dbprintf("Error in LogTrace: duration too long for 16 bits encoding: 0x%08x start: 0x%08x end: 0x%08x", duration, timestamp_start, timestamp_end);
|
Dbprintf("Error in LogTrace: duration too long for 16 bits encoding: 0x%08x start: 0x%08x end: 0x%08x", duration, timestamp_start, timestamp_end);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -80,7 +80,7 @@ static void RAMFUNC SniffAndStore(uint8_t param) {
|
||||||
|
|
||||||
// Setup and start DMA.
|
// Setup and start DMA.
|
||||||
if (!FpgaSetupSscDma((uint8_t *)dmaBuf, DMA_BUFFER_SIZE)) {
|
if (!FpgaSetupSscDma((uint8_t *)dmaBuf, DMA_BUFFER_SIZE)) {
|
||||||
if (DBGLEVEL > 1)
|
if (g_dbglevel > 1)
|
||||||
Dbprintf("FpgaSetupSscDma failed. Exiting");
|
Dbprintf("FpgaSetupSscDma failed. Exiting");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ static void RAMFUNC SniffAndStore(uint8_t param) {
|
||||||
if (triggered) {
|
if (triggered) {
|
||||||
if ((receivedCmd) &&
|
if ((receivedCmd) &&
|
||||||
((receivedCmd[0] == MIFARE_ULEV1_AUTH) || (receivedCmd[0] == MIFARE_ULC_AUTH_1))) {
|
((receivedCmd[0] == MIFARE_ULEV1_AUTH) || (receivedCmd[0] == MIFARE_ULC_AUTH_1))) {
|
||||||
if (DBGLEVEL > 1)
|
if (g_dbglevel > 1)
|
||||||
Dbprintf("PWD-AUTH KEY: 0x%02x%02x%02x%02x", receivedCmd[1], receivedCmd[2],
|
Dbprintf("PWD-AUTH KEY: 0x%02x%02x%02x%02x", receivedCmd[1], receivedCmd[2],
|
||||||
receivedCmd[3], receivedCmd[4]);
|
receivedCmd[3], receivedCmd[4]);
|
||||||
|
|
||||||
|
@ -214,7 +214,7 @@ static void RAMFUNC SniffAndStore(uint8_t param) {
|
||||||
|
|
||||||
// Write stuff to spiffs logfile
|
// Write stuff to spiffs logfile
|
||||||
if (auth_attempts > 0) {
|
if (auth_attempts > 0) {
|
||||||
if (DBGLEVEL > 1)
|
if (g_dbglevel > 1)
|
||||||
Dbprintf("[!] Authentication attempts = %u", auth_attempts);
|
Dbprintf("[!] Authentication attempts = %u", auth_attempts);
|
||||||
|
|
||||||
if (!exists_in_spiffs((char *)HF_BOG_LOGFILE)) {
|
if (!exists_in_spiffs((char *)HF_BOG_LOGFILE)) {
|
||||||
|
@ -224,7 +224,7 @@ static void RAMFUNC SniffAndStore(uint8_t param) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBGLEVEL > 1)
|
if (g_dbglevel > 1)
|
||||||
Dbprintf("[!] Wrote %u Authentification attempts into logfile", auth_attempts);
|
Dbprintf("[!] Wrote %u Authentification attempts into logfile", auth_attempts);
|
||||||
|
|
||||||
SpinErr(LED_A, 200, 5);
|
SpinErr(LED_A, 200, 5);
|
||||||
|
|
|
@ -333,7 +333,7 @@ void RunMod(void) {
|
||||||
Dbprintf(">> HF Mifare ultra fast sniff/sim/clone a.k.a VIGIKPWN Started <<");
|
Dbprintf(">> HF Mifare ultra fast sniff/sim/clone a.k.a VIGIKPWN Started <<");
|
||||||
|
|
||||||
// turn off all debugging.
|
// turn off all debugging.
|
||||||
DBGLEVEL = DBG_NONE;
|
g_dbglevel = DBG_NONE;
|
||||||
|
|
||||||
// add_schema(Schemas, Noralsy, &total_schemas);
|
// add_schema(Schemas, Noralsy, &total_schemas);
|
||||||
// add_schema(Schemas, InfiHexact, &total_schemas);
|
// add_schema(Schemas, InfiHexact, &total_schemas);
|
||||||
|
|
|
@ -178,7 +178,7 @@ static int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_
|
||||||
a particular sector. also no tracing no dbg */
|
a particular sector. also no tracing no dbg */
|
||||||
static int saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace,
|
static int saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace,
|
||||||
uint8_t keyCount, uint8_t *datain, uint64_t *key) {
|
uint8_t keyCount, uint8_t *datain, uint64_t *key) {
|
||||||
DBGLEVEL = DBG_NONE;
|
g_dbglevel = DBG_NONE;
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
||||||
set_tracing(false);
|
set_tracing(false);
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ static int saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace,
|
||||||
* - tracing is falsed
|
* - tracing is falsed
|
||||||
*/
|
*/
|
||||||
static int saMifareECardLoad(uint32_t numofsectors, uint8_t keytype) {
|
static int saMifareECardLoad(uint32_t numofsectors, uint8_t keytype) {
|
||||||
DBGLEVEL = DBG_NONE;
|
g_dbglevel = DBG_NONE;
|
||||||
|
|
||||||
uint8_t numSectors = numofsectors;
|
uint8_t numSectors = numofsectors;
|
||||||
uint8_t keyType = keytype;
|
uint8_t keyType = keytype;
|
||||||
|
|
|
@ -59,7 +59,7 @@ static bool fill_eml_from_file(char *dumpfile) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//read and load dump file
|
//read and load dump file
|
||||||
if (DBGLEVEL >= DBG_INFO)
|
if (g_dbglevel >= DBG_INFO)
|
||||||
Dbprintf(_YELLOW_("Found dump file %s. Uploading to emulator memory..."), dumpfile);
|
Dbprintf(_YELLOW_("Found dump file %s. Uploading to emulator memory..."), dumpfile);
|
||||||
emlClearMem();
|
emlClearMem();
|
||||||
uint8_t *emCARD = BigBuf_get_EM_addr();
|
uint8_t *emCARD = BigBuf_get_EM_addr();
|
||||||
|
|
|
@ -203,9 +203,9 @@ void RunMod(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
LED_D_OFF();
|
LED_D_OFF();
|
||||||
gLogin = false;
|
g_Login = false;
|
||||||
gPassword = reflect32(tag[0]);
|
g_Password = reflect32(tag[0]);
|
||||||
gWritePasswordProcess = false;
|
g_WritePasswordProcess = false;
|
||||||
command = EM4X50_COMMAND_STANDARD_READ;
|
command = EM4X50_COMMAND_STANDARD_READ;
|
||||||
no_pwd = 0;
|
no_pwd = 0;
|
||||||
memset(pwdlist, 0, sizeof(pwdlist));
|
memset(pwdlist, 0, sizeof(pwdlist));
|
||||||
|
@ -223,19 +223,19 @@ void RunMod(void) {
|
||||||
em4x50_handle_commands(&command, tag);
|
em4x50_handle_commands(&command, tag);
|
||||||
|
|
||||||
// check if new password was found
|
// check if new password was found
|
||||||
if (gPassword != reflect32(tag[EM4X50_DEVICE_PASSWORD])) {
|
if (g_Password != reflect32(tag[EM4X50_DEVICE_PASSWORD])) {
|
||||||
if (no_pwd < MAX_NO_PWDS_TO_SAVE) {
|
if (no_pwd < MAX_NO_PWDS_TO_SAVE) {
|
||||||
pwdlist[no_pwd] = gPassword;
|
pwdlist[no_pwd] = g_Password;
|
||||||
no_pwd++;
|
no_pwd++;
|
||||||
}
|
}
|
||||||
gPassword = reflect32(tag[EM4X50_DEVICE_PASSWORD]);
|
g_Password = reflect32(tag[EM4X50_DEVICE_PASSWORD]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if timeout (e.g. no reader field) continue with standard read
|
// if timeout (e.g. no reader field) continue with standard read
|
||||||
// mode and reset former authentication
|
// mode and reset former authentication
|
||||||
if (command == PM3_ETIMEOUT) {
|
if (command == PM3_ETIMEOUT) {
|
||||||
command = EM4X50_COMMAND_STANDARD_READ;
|
command = EM4X50_COMMAND_STANDARD_READ;
|
||||||
gLogin = false;
|
g_Login = false;
|
||||||
LED_D_OFF();
|
LED_D_OFF();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,25 +67,25 @@
|
||||||
#include "spiffs.h"
|
#include "spiffs.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int DBGLEVEL = DBG_ERROR;
|
int g_dbglevel = DBG_ERROR;
|
||||||
uint8_t g_trigger = 0;
|
uint8_t g_trigger = 0;
|
||||||
bool g_hf_field_active = false;
|
bool g_hf_field_active = false;
|
||||||
extern uint32_t _stack_start[], _stack_end[];
|
extern uint32_t _stack_start[], _stack_end[];
|
||||||
struct common_area common_area __attribute__((section(".commonarea")));
|
struct common_area common_area __attribute__((section(".commonarea")));
|
||||||
static int button_status = BUTTON_NO_CLICK;
|
static int button_status = BUTTON_NO_CLICK;
|
||||||
static bool allow_send_wtx = false;
|
static bool allow_send_wtx = false;
|
||||||
uint16_t tearoff_delay_us = 0;
|
uint16_t g_tearoff_delay_us = 0;
|
||||||
bool tearoff_enabled = false;
|
bool g_tearoff_enabled = false;
|
||||||
|
|
||||||
int tearoff_hook(void) {
|
int tearoff_hook(void) {
|
||||||
if (tearoff_enabled) {
|
if (g_tearoff_enabled) {
|
||||||
if (tearoff_delay_us == 0) {
|
if (g_tearoff_delay_us == 0) {
|
||||||
Dbprintf(_RED_("No tear-off delay configured!"));
|
Dbprintf(_RED_("No tear-off delay configured!"));
|
||||||
return PM3_SUCCESS; // SUCCESS = the hook didn't do anything
|
return PM3_SUCCESS; // SUCCESS = the hook didn't do anything
|
||||||
}
|
}
|
||||||
SpinDelayUsPrecision(tearoff_delay_us);
|
SpinDelayUsPrecision(g_tearoff_delay_us);
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
tearoff_enabled = false;
|
g_tearoff_enabled = false;
|
||||||
Dbprintf(_YELLOW_("Tear-off triggered!"));
|
Dbprintf(_YELLOW_("Tear-off triggered!"));
|
||||||
return PM3_ETEAROFF;
|
return PM3_ETEAROFF;
|
||||||
} else {
|
} else {
|
||||||
|
@ -336,7 +336,7 @@ static void TimingIntervalAcquisition(void) {
|
||||||
|
|
||||||
static void print_debug_level(void) {
|
static void print_debug_level(void) {
|
||||||
char dbglvlstr[20] = {0};
|
char dbglvlstr[20] = {0};
|
||||||
switch (DBGLEVEL) {
|
switch (g_dbglevel) {
|
||||||
case DBG_NONE:
|
case DBG_NONE:
|
||||||
sprintf(dbglvlstr, "none");
|
sprintf(dbglvlstr, "none");
|
||||||
break;
|
break;
|
||||||
|
@ -353,7 +353,7 @@ static void print_debug_level(void) {
|
||||||
sprintf(dbglvlstr, "extended");
|
sprintf(dbglvlstr, "extended");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Dbprintf(" Debug log level......... %d ( " _YELLOW_("%s")" )", DBGLEVEL, dbglvlstr);
|
Dbprintf(" Debug log level......... %d ( " _YELLOW_("%s")" )", g_dbglevel, dbglvlstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// measure the Connection Speed by sending SpeedTestBufferSize bytes to client and measuring the elapsed time.
|
// measure the Connection Speed by sending SpeedTestBufferSize bytes to client and measuring the elapsed time.
|
||||||
|
@ -772,7 +772,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||||
}
|
}
|
||||||
// emulator
|
// emulator
|
||||||
case CMD_SET_DBGMODE: {
|
case CMD_SET_DBGMODE: {
|
||||||
DBGLEVEL = packet->data.asBytes[0];
|
g_dbglevel = packet->data.asBytes[0];
|
||||||
print_debug_level();
|
print_debug_level();
|
||||||
reply_ng(CMD_SET_DBGMODE, PM3_SUCCESS, NULL, 0);
|
reply_ng(CMD_SET_DBGMODE, PM3_SUCCESS, NULL, 0);
|
||||||
break;
|
break;
|
||||||
|
@ -787,11 +787,11 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||||
if (payload->on && payload->off)
|
if (payload->on && payload->off)
|
||||||
reply_ng(CMD_SET_TEAROFF, PM3_EINVARG, NULL, 0);
|
reply_ng(CMD_SET_TEAROFF, PM3_EINVARG, NULL, 0);
|
||||||
if (payload->on)
|
if (payload->on)
|
||||||
tearoff_enabled = true;
|
g_tearoff_enabled = true;
|
||||||
if (payload->off)
|
if (payload->off)
|
||||||
tearoff_enabled = false;
|
g_tearoff_enabled = false;
|
||||||
if (payload->delay_us > 0)
|
if (payload->delay_us > 0)
|
||||||
tearoff_delay_us = payload->delay_us;
|
g_tearoff_delay_us = payload->delay_us;
|
||||||
reply_ng(CMD_SET_TEAROFF, PM3_SUCCESS, NULL, 0);
|
reply_ng(CMD_SET_TEAROFF, PM3_SUCCESS, NULL, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2094,7 +2094,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||||
uint8_t filename[32];
|
uint8_t filename[32];
|
||||||
uint8_t *pfilename = packet->data.asBytes;
|
uint8_t *pfilename = packet->data.asBytes;
|
||||||
memcpy(filename, pfilename, SPIFFS_OBJ_NAME_LEN);
|
memcpy(filename, pfilename, SPIFFS_OBJ_NAME_LEN);
|
||||||
if (DBGLEVEL >= DBG_DEBUG) Dbprintf("Filename received for spiffs dump : %s", filename);
|
if (g_dbglevel >= DBG_DEBUG) Dbprintf("Filename received for spiffs dump : %s", filename);
|
||||||
|
|
||||||
uint32_t size = packet->oldarg[1];
|
uint32_t size = packet->oldarg[1];
|
||||||
|
|
||||||
|
@ -2121,7 +2121,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||||
uint8_t filename[32];
|
uint8_t filename[32];
|
||||||
uint8_t *pfilename = packet->data.asBytes;
|
uint8_t *pfilename = packet->data.asBytes;
|
||||||
memcpy(filename, pfilename, SPIFFS_OBJ_NAME_LEN);
|
memcpy(filename, pfilename, SPIFFS_OBJ_NAME_LEN);
|
||||||
if (DBGLEVEL >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
Dbprintf("Filename received for spiffs STAT : %s", filename);
|
Dbprintf("Filename received for spiffs STAT : %s", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2144,7 +2144,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||||
} PACKED;
|
} PACKED;
|
||||||
struct p *payload = (struct p *) packet->data.asBytes;
|
struct p *payload = (struct p *) packet->data.asBytes;
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
Dbprintf("Filename received for spiffs REMOVE : %s", payload->fn);
|
Dbprintf("Filename received for spiffs REMOVE : %s", payload->fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2163,7 +2163,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||||
} PACKED;
|
} PACKED;
|
||||||
struct p *payload = (struct p *) packet->data.asBytes;
|
struct p *payload = (struct p *) packet->data.asBytes;
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
Dbprintf("SPIFFS RENAME");
|
Dbprintf("SPIFFS RENAME");
|
||||||
Dbprintf("Source........ %s", payload->src);
|
Dbprintf("Source........ %s", payload->src);
|
||||||
Dbprintf("Destination... %s", payload->dest);
|
Dbprintf("Destination... %s", payload->dest);
|
||||||
|
@ -2183,7 +2183,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||||
} PACKED;
|
} PACKED;
|
||||||
struct p *payload = (struct p *) packet->data.asBytes;
|
struct p *payload = (struct p *) packet->data.asBytes;
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
Dbprintf("SPIFFS COPY");
|
Dbprintf("SPIFFS COPY");
|
||||||
Dbprintf("Source........ %s", payload->src);
|
Dbprintf("Source........ %s", payload->src);
|
||||||
Dbprintf("Destination... %s", payload->dest);
|
Dbprintf("Destination... %s", payload->dest);
|
||||||
|
@ -2198,7 +2198,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||||
|
|
||||||
flashmem_write_t *payload = (flashmem_write_t *)packet->data.asBytes;
|
flashmem_write_t *payload = (flashmem_write_t *)packet->data.asBytes;
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
Dbprintf("SPIFFS WRITE, dest `%s` with APPEND set to: %c", payload->fn, payload->append ? 'Y' : 'N');
|
Dbprintf("SPIFFS WRITE, dest `%s` with APPEND set to: %c", payload->fn, payload->append ? 'Y' : 'N');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,18 +63,18 @@
|
||||||
#define EM4X50_TAG_MAX_NO_BYTES 136
|
#define EM4X50_TAG_MAX_NO_BYTES 136
|
||||||
#define EM4X50_TIMEOUT_PULSE_EVAL 2500
|
#define EM4X50_TIMEOUT_PULSE_EVAL 2500
|
||||||
|
|
||||||
int gHigh = 190;
|
int g_High = 190;
|
||||||
int gLow = 60;
|
int g_Low = 60;
|
||||||
|
|
||||||
// indication whether a previous login has been successful, so operations
|
// indication whether a previous login has been successful, so operations
|
||||||
// that require authentication can be handled
|
// that require authentication can be handled
|
||||||
bool gLogin = false;
|
bool g_Login = false;
|
||||||
// WritePassword process in simulation mode is handled in a different way
|
// WritePassword process in simulation mode is handled in a different way
|
||||||
// compared to operations like read, write, login, so it is necessary to
|
// compared to operations like read, write, login, so it is necessary to
|
||||||
// to be able to identfiy it
|
// to be able to identfiy it
|
||||||
bool gWritePasswordProcess = false;
|
bool g_WritePasswordProcess = false;
|
||||||
// if reader sends a different password than "expected" -> save it
|
// if reader sends a different password than "expected" -> save it
|
||||||
uint32_t gPassword = 0;
|
uint32_t g_Password = 0;
|
||||||
|
|
||||||
// extract and check parities
|
// extract and check parities
|
||||||
// return result of parity check and extracted plain data
|
// return result of parity check and extracted plain data
|
||||||
|
@ -173,7 +173,7 @@ void em4x50_setup_sim(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate signal properties (mean amplitudes) from measured data:
|
// calculate signal properties (mean amplitudes) from measured data:
|
||||||
// 32 amplitudes (maximum values) -> mean amplitude value -> gHigh -> gLow
|
// 32 amplitudes (maximum values) -> mean amplitude value -> g_High -> g_Low
|
||||||
static bool get_signalproperties(void) {
|
static bool get_signalproperties(void) {
|
||||||
|
|
||||||
bool signal_found = false;
|
bool signal_found = false;
|
||||||
|
@ -224,8 +224,8 @@ static bool get_signalproperties(void) {
|
||||||
sample_max_mean = sample_max_sum / no_periods;
|
sample_max_mean = sample_max_sum / no_periods;
|
||||||
|
|
||||||
// set global envelope variables
|
// set global envelope variables
|
||||||
gHigh = sample_ref + pct * (sample_max_mean - sample_ref) / 100;
|
g_High = sample_ref + pct * (sample_max_mean - sample_ref) / 100;
|
||||||
gLow = sample_ref - pct * (sample_max_mean - sample_ref) / 100;
|
g_Low = sample_ref - pct * (sample_max_mean - sample_ref) / 100;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -245,7 +245,7 @@ static bool invalid_bit(void) {
|
||||||
WaitUS(EM4X50_T_TAG_QUARTER_PERIOD * CYCLES2MUSEC);
|
WaitUS(EM4X50_T_TAG_QUARTER_PERIOD * CYCLES2MUSEC);
|
||||||
|
|
||||||
// bit in "undefined" state?
|
// bit in "undefined" state?
|
||||||
if (sample <= gHigh && sample >= gLow)
|
if (sample <= g_High && sample >= g_Low)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -259,7 +259,7 @@ static uint32_t get_pulse_length(void) {
|
||||||
|
|
||||||
volatile uint8_t sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
volatile uint8_t sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||||
|
|
||||||
while (sample > gLow && (timeout--))
|
while (sample > g_Low && (timeout--))
|
||||||
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||||
|
|
||||||
if (timeout <= 0)
|
if (timeout <= 0)
|
||||||
|
@ -268,14 +268,14 @@ static uint32_t get_pulse_length(void) {
|
||||||
tval = GetTicks();
|
tval = GetTicks();
|
||||||
timeout = EM4X50_TIMEOUT_PULSE_EVAL;
|
timeout = EM4X50_TIMEOUT_PULSE_EVAL;
|
||||||
|
|
||||||
while (sample < gHigh && (timeout--))
|
while (sample < g_High && (timeout--))
|
||||||
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||||
|
|
||||||
if (timeout <= 0)
|
if (timeout <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
timeout = EM4X50_TIMEOUT_PULSE_EVAL;
|
timeout = EM4X50_TIMEOUT_PULSE_EVAL;
|
||||||
while (sample > gLow && (timeout--))
|
while (sample > g_Low && (timeout--))
|
||||||
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||||
|
|
||||||
if (timeout <= 0)
|
if (timeout <= 0)
|
||||||
|
@ -617,7 +617,7 @@ static int login(uint32_t password) {
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (DBGLEVEL >= DBG_DEBUG)
|
if (g_dbglevel >= DBG_DEBUG)
|
||||||
Dbprintf("error in command request");
|
Dbprintf("error in command request");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -732,7 +732,7 @@ void em4x50_chk(uint8_t *filename) {
|
||||||
|
|
||||||
em4x50_setup_read();
|
em4x50_setup_read();
|
||||||
|
|
||||||
// set gHigh and gLow
|
// set g_High and g_Low
|
||||||
LED_C_ON();
|
LED_C_ON();
|
||||||
if (get_signalproperties() && find_em4x50_tag()) {
|
if (get_signalproperties() && find_em4x50_tag()) {
|
||||||
|
|
||||||
|
@ -781,7 +781,7 @@ static int reset(void) {
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (DBGLEVEL >= DBG_DEBUG)
|
if (g_dbglevel >= DBG_DEBUG)
|
||||||
Dbprintf("error in command request");
|
Dbprintf("error in command request");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -808,7 +808,7 @@ int standard_read(int *now, uint32_t *words) {
|
||||||
*now -= fwr;
|
*now -= fwr;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (DBGLEVEL >= DBG_DEBUG)
|
if (g_dbglevel >= DBG_DEBUG)
|
||||||
Dbprintf("didn't find a listen window");
|
Dbprintf("didn't find a listen window");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -841,7 +841,7 @@ static int selective_read(uint32_t addresses, uint32_t *words) {
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (DBGLEVEL >= DBG_DEBUG)
|
if (g_dbglevel >= DBG_DEBUG)
|
||||||
Dbprintf("error in command request");
|
Dbprintf("error in command request");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -855,7 +855,7 @@ void em4x50_read(em4x50_data_t *etd) {
|
||||||
|
|
||||||
em4x50_setup_read();
|
em4x50_setup_read();
|
||||||
|
|
||||||
// set gHigh and gLow
|
// set g_High and g_Low
|
||||||
LED_C_ON();
|
LED_C_ON();
|
||||||
if (get_signalproperties() && find_em4x50_tag()) {
|
if (get_signalproperties() && find_em4x50_tag()) {
|
||||||
|
|
||||||
|
@ -964,7 +964,7 @@ static int write(uint32_t word, uint32_t addresses) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (DBGLEVEL >= DBG_DEBUG)
|
if (g_dbglevel >= DBG_DEBUG)
|
||||||
Dbprintf("error in command request");
|
Dbprintf("error in command request");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1013,7 +1013,7 @@ static int write_password(uint32_t password, uint32_t new_password) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (DBGLEVEL >= DBG_DEBUG)
|
if (g_dbglevel >= DBG_DEBUG)
|
||||||
Dbprintf("error in command request");
|
Dbprintf("error in command request");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1338,7 +1338,7 @@ static int check_rm_request(uint32_t *tag) {
|
||||||
|
|
||||||
// if command before was EM4X50_COMMAND_WRITE_PASSWORD
|
// if command before was EM4X50_COMMAND_WRITE_PASSWORD
|
||||||
// switch to separate process
|
// switch to separate process
|
||||||
if (gWritePasswordProcess) {
|
if (g_WritePasswordProcess) {
|
||||||
return EM4X50_COMMAND_WRITE_PASSWORD;
|
return EM4X50_COMMAND_WRITE_PASSWORD;
|
||||||
} else {
|
} else {
|
||||||
// read mode request detected, get command from reader
|
// read mode request detected, get command from reader
|
||||||
|
@ -1454,7 +1454,7 @@ static int em4x50_sim_handle_standard_read_command(uint32_t *tag) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((gLogin == false) && (i >= fwrp) && (i <= lwrp)) {
|
if ((g_Login == false) && (i >= fwrp) && (i <= lwrp)) {
|
||||||
em4x50_sim_send_word(0x00);
|
em4x50_sim_send_word(0x00);
|
||||||
} else {
|
} else {
|
||||||
em4x50_sim_send_word(reflect32(tag[i]));
|
em4x50_sim_send_word(reflect32(tag[i]));
|
||||||
|
@ -1509,7 +1509,7 @@ static int em4x50_sim_handle_selective_read_command(uint32_t *tag) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if not authenticated do not send read protected words
|
// if not authenticated do not send read protected words
|
||||||
if ((gLogin == false) && (i >= fwrp) && (i <= lwrp)) {
|
if ((g_Login == false) && (i >= fwrp) && (i <= lwrp)) {
|
||||||
em4x50_sim_send_word(0x00);
|
em4x50_sim_send_word(0x00);
|
||||||
} else {
|
} else {
|
||||||
em4x50_sim_send_word(reflect32(tag[i]));
|
em4x50_sim_send_word(reflect32(tag[i]));
|
||||||
|
@ -1532,15 +1532,15 @@ static int em4x50_sim_handle_login_command(uint32_t *tag) {
|
||||||
|
|
||||||
if (pwd && (password == reflect32(tag[EM4X50_DEVICE_PASSWORD]))) {
|
if (pwd && (password == reflect32(tag[EM4X50_DEVICE_PASSWORD]))) {
|
||||||
em4x50_sim_send_ack();
|
em4x50_sim_send_ack();
|
||||||
gLogin = true;
|
g_Login = true;
|
||||||
LED_D_ON();
|
LED_D_ON();
|
||||||
} else {
|
} else {
|
||||||
em4x50_sim_send_nak();
|
em4x50_sim_send_nak();
|
||||||
gLogin = false;
|
g_Login = false;
|
||||||
LED_D_OFF();
|
LED_D_OFF();
|
||||||
|
|
||||||
// save transmitted password (to be used in standalone mode)
|
// save transmitted password (to be used in standalone mode)
|
||||||
gPassword = password;
|
g_Password = password;
|
||||||
}
|
}
|
||||||
// continue with standard read mode
|
// continue with standard read mode
|
||||||
return EM4X50_COMMAND_STANDARD_READ;
|
return EM4X50_COMMAND_STANDARD_READ;
|
||||||
|
@ -1554,7 +1554,7 @@ static int em4x50_sim_handle_reset_command(uint32_t *tag) {
|
||||||
|
|
||||||
// send ACK
|
// send ACK
|
||||||
em4x50_sim_send_ack();
|
em4x50_sim_send_ack();
|
||||||
gLogin = false;
|
g_Login = false;
|
||||||
LED_D_OFF();
|
LED_D_OFF();
|
||||||
|
|
||||||
// wait for initialization (tinit)
|
// wait for initialization (tinit)
|
||||||
|
@ -1598,7 +1598,7 @@ static int em4x50_sim_handle_write_command(uint32_t *tag) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EM4X50_PROTECTION:
|
case EM4X50_PROTECTION:
|
||||||
if (gLogin) {
|
if (g_Login) {
|
||||||
tag[address] = reflect32(data);
|
tag[address] = reflect32(data);
|
||||||
em4x50_sim_send_ack();
|
em4x50_sim_send_ack();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1608,7 +1608,7 @@ static int em4x50_sim_handle_write_command(uint32_t *tag) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EM4X50_CONTROL:
|
case EM4X50_CONTROL:
|
||||||
if (gLogin) {
|
if (g_Login) {
|
||||||
tag[address] = reflect32(data);
|
tag[address] = reflect32(data);
|
||||||
em4x50_sim_send_ack();
|
em4x50_sim_send_ack();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1629,7 +1629,7 @@ static int em4x50_sim_handle_write_command(uint32_t *tag) {
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if ((address >= fwwp) && (address <= lwwp)) {
|
if ((address >= fwwp) && (address <= lwwp)) {
|
||||||
if (gLogin) {
|
if (g_Login) {
|
||||||
tag[address] = reflect32(data);
|
tag[address] = reflect32(data);
|
||||||
em4x50_sim_send_ack();
|
em4x50_sim_send_ack();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1675,7 +1675,7 @@ static int em4x50_sim_handle_writepwd_command(uint32_t *tag) {
|
||||||
|
|
||||||
bool pwd = false;
|
bool pwd = false;
|
||||||
|
|
||||||
gWritePasswordProcess = true;
|
g_WritePasswordProcess = true;
|
||||||
|
|
||||||
// read password
|
// read password
|
||||||
uint32_t act_password = 0;
|
uint32_t act_password = 0;
|
||||||
|
@ -1686,20 +1686,20 @@ static int em4x50_sim_handle_writepwd_command(uint32_t *tag) {
|
||||||
|
|
||||||
if (pwd && (act_password == reflect32(tag[EM4X50_DEVICE_PASSWORD]))) {
|
if (pwd && (act_password == reflect32(tag[EM4X50_DEVICE_PASSWORD]))) {
|
||||||
em4x50_sim_send_ack();
|
em4x50_sim_send_ack();
|
||||||
gLogin = true;
|
g_Login = true;
|
||||||
} else {
|
} else {
|
||||||
em4x50_sim_send_nak();
|
em4x50_sim_send_nak();
|
||||||
gLogin = false;
|
g_Login = false;
|
||||||
gWritePasswordProcess = false;
|
g_WritePasswordProcess = false;
|
||||||
|
|
||||||
// save transmitted password (to be used in standalone mode)
|
// save transmitted password (to be used in standalone mode)
|
||||||
gPassword = act_password;
|
g_Password = act_password;
|
||||||
|
|
||||||
return EM4X50_COMMAND_STANDARD_READ;
|
return EM4X50_COMMAND_STANDARD_READ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int command = em4x50_sim_send_listen_window(tag);
|
int command = em4x50_sim_send_listen_window(tag);
|
||||||
gWritePasswordProcess = false;
|
g_WritePasswordProcess = false;
|
||||||
if (command != EM4X50_COMMAND_WRITE_PASSWORD) {
|
if (command != EM4X50_COMMAND_WRITE_PASSWORD) {
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
@ -1714,7 +1714,7 @@ static int em4x50_sim_handle_writepwd_command(uint32_t *tag) {
|
||||||
if (pwd) {
|
if (pwd) {
|
||||||
em4x50_sim_send_ack();
|
em4x50_sim_send_ack();
|
||||||
tag[EM4X50_DEVICE_PASSWORD] = reflect32(new_password);
|
tag[EM4X50_DEVICE_PASSWORD] = reflect32(new_password);
|
||||||
gPassword = new_password;
|
g_Password = new_password;
|
||||||
} else {
|
} else {
|
||||||
em4x50_sim_send_nak();
|
em4x50_sim_send_nak();
|
||||||
return EM4X50_COMMAND_STANDARD_READ;
|
return EM4X50_COMMAND_STANDARD_READ;
|
||||||
|
@ -1793,8 +1793,8 @@ void em4x50_sim(uint32_t *password) {
|
||||||
// init
|
// init
|
||||||
LEDsoff();
|
LEDsoff();
|
||||||
em4x50_setup_sim();
|
em4x50_setup_sim();
|
||||||
gLogin = false;
|
g_Login = false;
|
||||||
gWritePasswordProcess = false;
|
g_WritePasswordProcess = false;
|
||||||
|
|
||||||
// start with inital command = standard read mode
|
// start with inital command = standard read mode
|
||||||
command = EM4X50_COMMAND_STANDARD_READ;
|
command = EM4X50_COMMAND_STANDARD_READ;
|
||||||
|
@ -1812,7 +1812,7 @@ void em4x50_sim(uint32_t *password) {
|
||||||
// mode and reset former authentication
|
// mode and reset former authentication
|
||||||
if (command == PM3_ETIMEOUT) {
|
if (command == PM3_ETIMEOUT) {
|
||||||
command = EM4X50_COMMAND_STANDARD_READ;
|
command = EM4X50_COMMAND_STANDARD_READ;
|
||||||
gLogin = false;
|
g_Login = false;
|
||||||
LED_D_OFF();
|
LED_D_OFF();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -227,21 +227,21 @@ static uint8_t felica_select_card(felica_card_select_t *card) {
|
||||||
|
|
||||||
// timed-out
|
// timed-out
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
if (DBGLEVEL >= DBG_DEBUG)
|
if (g_dbglevel >= DBG_DEBUG)
|
||||||
Dbprintf("Error: Time out card selection!");
|
Dbprintf("Error: Time out card selection!");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// wrong answer
|
// wrong answer
|
||||||
if (FelicaFrame.framebytes[3] != FELICA_POLL_ACK) {
|
if (FelicaFrame.framebytes[3] != FELICA_POLL_ACK) {
|
||||||
if (DBGLEVEL >= DBG_DEBUG)
|
if (g_dbglevel >= DBG_DEBUG)
|
||||||
Dbprintf("Error: Wrong answer selecting card!");
|
Dbprintf("Error: Wrong answer selecting card!");
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// VALIDATE CRC residue is 0, hence if crc is a value it failed.
|
// VALIDATE CRC residue is 0, hence if crc is a value it failed.
|
||||||
if (!check_crc(CRC_FELICA, FelicaFrame.framebytes + 2, FelicaFrame.len - 2)) {
|
if (!check_crc(CRC_FELICA, FelicaFrame.framebytes + 2, FelicaFrame.len - 2)) {
|
||||||
if (DBGLEVEL >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
Dbprintf("Error: CRC check failed!");
|
Dbprintf("Error: CRC check failed!");
|
||||||
Dbprintf("CRC check was done on Frame: ");
|
Dbprintf("CRC check was done on Frame: ");
|
||||||
Dbhexdump(FelicaFrame.len - 2, FelicaFrame.framebytes + 2, 0);
|
Dbhexdump(FelicaFrame.len - 2, FelicaFrame.framebytes + 2, 0);
|
||||||
|
@ -249,7 +249,7 @@ static uint8_t felica_select_card(felica_card_select_t *card) {
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_DEBUG)
|
if (g_dbglevel >= DBG_DEBUG)
|
||||||
Dbprintf("Card selection successful!");
|
Dbprintf("Card selection successful!");
|
||||||
// copy UID
|
// copy UID
|
||||||
// idm 8
|
// idm 8
|
||||||
|
@ -261,7 +261,7 @@ static uint8_t felica_select_card(felica_card_select_t *card) {
|
||||||
memcpy(card->uid, card->IDm + 2, 6);
|
memcpy(card->uid, card->IDm + 2, 6);
|
||||||
memcpy(card->iccode, card->PMm, 2);
|
memcpy(card->iccode, card->PMm, 2);
|
||||||
memcpy(card->mrt, card->PMm + 2, 6);
|
memcpy(card->mrt, card->PMm + 2, 6);
|
||||||
if (DBGLEVEL >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
Dbprintf("Received Frame: ");
|
Dbprintf("Received Frame: ");
|
||||||
Dbhexdump(FelicaFrame.len, FelicaFrame.framebytes, 0);
|
Dbhexdump(FelicaFrame.len, FelicaFrame.framebytes, 0);
|
||||||
}
|
}
|
||||||
|
@ -362,7 +362,7 @@ static void TransmitFor18092_AsReader(uint8_t *frame, int len, uint32_t *timing,
|
||||||
}
|
}
|
||||||
// sending data with sync bytes
|
// sending data with sync bytes
|
||||||
c = 0;
|
c = 0;
|
||||||
if (DBGLEVEL >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
Dbprintf("Sending frame:");
|
Dbprintf("Sending frame:");
|
||||||
Dbhexdump(len, frame, 0);
|
Dbhexdump(len, frame, 0);
|
||||||
}
|
}
|
||||||
|
@ -399,7 +399,7 @@ static void TransmitFor18092_AsReader(uint8_t *frame, int len, uint32_t *timing,
|
||||||
// stop when button is pressed
|
// stop when button is pressed
|
||||||
// or return TRUE when command is captured
|
// or return TRUE when command is captured
|
||||||
bool WaitForFelicaReply(uint16_t maxbytes) {
|
bool WaitForFelicaReply(uint16_t maxbytes) {
|
||||||
if (DBGLEVEL >= DBG_DEBUG)
|
if (g_dbglevel >= DBG_DEBUG)
|
||||||
Dbprintf("WaitForFelicaReply Start");
|
Dbprintf("WaitForFelicaReply Start");
|
||||||
uint32_t c = 0;
|
uint32_t c = 0;
|
||||||
// power, no modulation
|
// power, no modulation
|
||||||
|
@ -429,10 +429,10 @@ bool WaitForFelicaReply(uint16_t maxbytes) {
|
||||||
NULL,
|
NULL,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
if (DBGLEVEL >= DBG_DEBUG) Dbprintf("All bytes received! STATE_FULL");
|
if (g_dbglevel >= DBG_DEBUG) Dbprintf("All bytes received! STATE_FULL");
|
||||||
return true;
|
return true;
|
||||||
} else if (c++ > timeout && (FelicaFrame.state == STATE_UNSYNCD || FelicaFrame.state == STATE_TRYING_SYNC)) {
|
} else if (c++ > timeout && (FelicaFrame.state == STATE_UNSYNCD || FelicaFrame.state == STATE_TRYING_SYNC)) {
|
||||||
if (DBGLEVEL >= DBG_DEBUG) Dbprintf("Error: Timeout! STATE_UNSYNCD");
|
if (g_dbglevel >= DBG_DEBUG) Dbprintf("Error: Timeout! STATE_UNSYNCD");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -442,7 +442,7 @@ bool WaitForFelicaReply(uint16_t maxbytes) {
|
||||||
// Set up FeliCa communication (similar to iso14443a_setup)
|
// Set up FeliCa communication (similar to iso14443a_setup)
|
||||||
// field is setup for "Sending as Reader"
|
// field is setup for "Sending as Reader"
|
||||||
static void iso18092_setup(uint8_t fpga_minor_mode) {
|
static void iso18092_setup(uint8_t fpga_minor_mode) {
|
||||||
if (DBGLEVEL >= DBG_DEBUG) Dbprintf("Start iso18092_setup");
|
if (g_dbglevel >= DBG_DEBUG) Dbprintf("Start iso18092_setup");
|
||||||
|
|
||||||
LEDsoff();
|
LEDsoff();
|
||||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF_FELICA);
|
FpgaDownloadAndGo(FPGA_BITSTREAM_HF_FELICA);
|
||||||
|
@ -495,7 +495,7 @@ static void felica_reset_frame_mode(void) {
|
||||||
// arg1 len of commandbytes
|
// arg1 len of commandbytes
|
||||||
// d.asBytes command bytes to send
|
// d.asBytes command bytes to send
|
||||||
void felica_sendraw(PacketCommandNG *c) {
|
void felica_sendraw(PacketCommandNG *c) {
|
||||||
if (DBGLEVEL >= DBG_DEBUG) Dbprintf("FeliCa_sendraw Enter");
|
if (g_dbglevel >= DBG_DEBUG) Dbprintf("FeliCa_sendraw Enter");
|
||||||
|
|
||||||
felica_command_t param = c->oldarg[0];
|
felica_command_t param = c->oldarg[0];
|
||||||
size_t len = c->oldarg[1] & 0xffff;
|
size_t len = c->oldarg[1] & 0xffff;
|
||||||
|
@ -505,7 +505,7 @@ void felica_sendraw(PacketCommandNG *c) {
|
||||||
felica_card_select_t card;
|
felica_card_select_t card;
|
||||||
|
|
||||||
if ((param & FELICA_CONNECT))
|
if ((param & FELICA_CONNECT))
|
||||||
if (DBGLEVEL >= DBG_DEBUG) Dbprintf("Clear trace");
|
if (g_dbglevel >= DBG_DEBUG) Dbprintf("Clear trace");
|
||||||
clear_trace();
|
clear_trace();
|
||||||
|
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
@ -518,13 +518,13 @@ void felica_sendraw(PacketCommandNG *c) {
|
||||||
arg0 = felica_select_card(&card);
|
arg0 = felica_select_card(&card);
|
||||||
reply_mix(CMD_ACK, arg0, sizeof(card.uid), 0, &card, sizeof(felica_card_select_t));
|
reply_mix(CMD_ACK, arg0, sizeof(card.uid), 0, &card, sizeof(felica_card_select_t));
|
||||||
if (arg0 > 0) {
|
if (arg0 > 0) {
|
||||||
if (DBGLEVEL >= DBG_DEBUG) Dbprintf("Error: Failed selecting card! ");
|
if (g_dbglevel >= DBG_DEBUG) Dbprintf("Error: Failed selecting card! ");
|
||||||
felica_reset_frame_mode();
|
felica_reset_frame_mode();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (DBGLEVEL >= DBG_DEBUG) Dbprintf("No card selection");
|
if (g_dbglevel >= DBG_DEBUG) Dbprintf("No card selection");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((param & FELICA_RAW)) {
|
if ((param & FELICA_RAW)) {
|
||||||
|
@ -545,14 +545,14 @@ void felica_sendraw(PacketCommandNG *c) {
|
||||||
AddCrc(buf, len);
|
AddCrc(buf, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (DBGLEVEL >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
Dbprintf("Transmit Frame (no CRC shown):");
|
Dbprintf("Transmit Frame (no CRC shown):");
|
||||||
Dbhexdump(len, buf, 0);
|
Dbhexdump(len, buf, 0);
|
||||||
Dbprintf("Buffer Length: %i", buf[2] + 4);
|
Dbprintf("Buffer Length: %i", buf[2] + 4);
|
||||||
};
|
};
|
||||||
TransmitFor18092_AsReader(buf, buf[2] + 4, NULL, 1, 0);
|
TransmitFor18092_AsReader(buf, buf[2] + 4, NULL, 1, 0);
|
||||||
arg0 = WaitForFelicaReply(1024);
|
arg0 = WaitForFelicaReply(1024);
|
||||||
if (DBGLEVEL >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
Dbprintf("Received Frame Code: %d", arg0);
|
Dbprintf("Received Frame Code: %d", arg0);
|
||||||
Dbhexdump(FelicaFrame.len, FelicaFrame.framebytes, 0);
|
Dbhexdump(FelicaFrame.len, FelicaFrame.framebytes, 0);
|
||||||
};
|
};
|
||||||
|
@ -565,7 +565,7 @@ void felica_sendraw(PacketCommandNG *c) {
|
||||||
if ((param & FELICA_NO_DISCONNECT)) {
|
if ((param & FELICA_NO_DISCONNECT)) {
|
||||||
Dbprintf("Disconnect");
|
Dbprintf("Disconnect");
|
||||||
}
|
}
|
||||||
if (DBGLEVEL >= DBG_DEBUG)
|
if (g_dbglevel >= DBG_DEBUG)
|
||||||
Dbprintf("FeliCa_sendraw Exit");
|
Dbprintf("FeliCa_sendraw Exit");
|
||||||
felica_reset_frame_mode();
|
felica_reset_frame_mode();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -155,7 +155,7 @@ void FlashStop(void) {
|
||||||
// SPI disable
|
// SPI disable
|
||||||
AT91C_BASE_SPI->SPI_CR = AT91C_SPI_SPIDIS;
|
AT91C_BASE_SPI->SPI_CR = AT91C_SPI_SPIDIS;
|
||||||
|
|
||||||
if (DBGLEVEL > 3) Dbprintf("FlashStop");
|
if (g_dbglevel > 3) Dbprintf("FlashStop");
|
||||||
|
|
||||||
StopTicks();
|
StopTicks();
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,7 @@ bool Flash_CheckBusy(uint32_t timeout) {
|
||||||
StartCountUS();
|
StartCountUS();
|
||||||
uint32_t _time = GetCountUS();
|
uint32_t _time = GetCountUS();
|
||||||
|
|
||||||
if (DBGLEVEL > 3) Dbprintf("Checkbusy in...");
|
if (g_dbglevel > 3) Dbprintf("Checkbusy in...");
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (!(Flash_ReadStat1() & BUSY)) {
|
if (!(Flash_ReadStat1() & BUSY)) {
|
||||||
|
@ -224,7 +224,7 @@ uint8_t Flash_ReadID(void) {
|
||||||
uint8_t man_id = FlashSendByte(0xFF);
|
uint8_t man_id = FlashSendByte(0xFF);
|
||||||
uint8_t dev_id = FlashSendLastByte(0xFF);
|
uint8_t dev_id = FlashSendLastByte(0xFF);
|
||||||
|
|
||||||
if (DBGLEVEL > 3) Dbprintf("Flash ReadID | Man ID %02x | Device ID %02x", man_id, dev_id);
|
if (g_dbglevel > 3) Dbprintf("Flash ReadID | Man ID %02x | Device ID %02x", man_id, dev_id);
|
||||||
|
|
||||||
if ((man_id == WINBOND_MANID) && (dev_id == WINBOND_DEVID))
|
if ((man_id == WINBOND_MANID) && (dev_id == WINBOND_DEVID))
|
||||||
return dev_id;
|
return dev_id;
|
||||||
|
@ -331,7 +331,7 @@ uint16_t Flash_WriteData(uint32_t address, uint8_t *in, uint16_t len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FlashInit()) {
|
if (!FlashInit()) {
|
||||||
if (DBGLEVEL > 3) Dbprintf("Flash_WriteData init fail");
|
if (g_dbglevel > 3) Dbprintf("Flash_WriteData init fail");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,7 +421,7 @@ out:
|
||||||
|
|
||||||
bool Flash_WipeMemoryPage(uint8_t page) {
|
bool Flash_WipeMemoryPage(uint8_t page) {
|
||||||
if (!FlashInit()) {
|
if (!FlashInit()) {
|
||||||
if (DBGLEVEL > 3) Dbprintf("Flash_WriteData init fail");
|
if (g_dbglevel > 3) Dbprintf("Flash_WriteData init fail");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Flash_ReadStat1();
|
Flash_ReadStat1();
|
||||||
|
@ -437,7 +437,7 @@ bool Flash_WipeMemoryPage(uint8_t page) {
|
||||||
// Wipes flash memory completely, fills with 0xFF
|
// Wipes flash memory completely, fills with 0xFF
|
||||||
bool Flash_WipeMemory(void) {
|
bool Flash_WipeMemory(void) {
|
||||||
if (!FlashInit()) {
|
if (!FlashInit()) {
|
||||||
if (DBGLEVEL > 3) Dbprintf("Flash_WriteData init fail");
|
if (g_dbglevel > 3) Dbprintf("Flash_WriteData init fail");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Flash_ReadStat1();
|
Flash_ReadStat1();
|
||||||
|
@ -464,7 +464,7 @@ bool Flash_WipeMemory(void) {
|
||||||
// enable the flash write
|
// enable the flash write
|
||||||
void Flash_WriteEnable(void) {
|
void Flash_WriteEnable(void) {
|
||||||
FlashSendLastByte(WRITEENABLE);
|
FlashSendLastByte(WRITEENABLE);
|
||||||
if (DBGLEVEL > 3) Dbprintf("Flash Write enabled");
|
if (g_dbglevel > 3) Dbprintf("Flash Write enabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
// erase 4K at one time
|
// erase 4K at one time
|
||||||
|
@ -485,7 +485,7 @@ bool Flash_Erase4k(uint8_t block, uint8_t sector) {
|
||||||
// execution time: 0,3s / 300ms
|
// execution time: 0,3s / 300ms
|
||||||
bool Flash_Erase32k(uint32_t address) {
|
bool Flash_Erase32k(uint32_t address) {
|
||||||
if (address & (32*1024 - 1)) {
|
if (address & (32*1024 - 1)) {
|
||||||
if ( DBGLEVEL > 1 ) Dbprintf("Flash_Erase32k : Address is not align at 4096");
|
if ( g_dbglevel > 1 ) Dbprintf("Flash_Erase32k : Address is not align at 4096");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
FlashSendByte(BLOCK32ERASE);
|
FlashSendByte(BLOCK32ERASE);
|
||||||
|
|
|
@ -411,7 +411,7 @@ void FpgaDownloadAndGo(int bitstream_version) {
|
||||||
// Send waiting time extension request as this will take a while
|
// Send waiting time extension request as this will take a while
|
||||||
send_wtx(1500);
|
send_wtx(1500);
|
||||||
|
|
||||||
bool verbose = (DBGLEVEL > 3);
|
bool verbose = (g_dbglevel > 3);
|
||||||
|
|
||||||
// make sure that we have enough memory to decompress
|
// make sure that we have enough memory to decompress
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
|
@ -525,7 +525,7 @@ int FpgaGetCurrent(void) {
|
||||||
// if HF, Disable SSC DMA
|
// if HF, Disable SSC DMA
|
||||||
// turn off trace and leds off.
|
// turn off trace and leds off.
|
||||||
void switch_off(void) {
|
void switch_off(void) {
|
||||||
if (DBGLEVEL > 3) {
|
if (g_dbglevel > 3) {
|
||||||
Dbprintf("switch_off");
|
Dbprintf("switch_off");
|
||||||
}
|
}
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
|
|
|
@ -99,7 +99,7 @@ int HfSniff(uint32_t samplesToSkip, uint32_t triggersToSkip, uint16_t *len) {
|
||||||
|
|
||||||
optimizedSniff((uint16_t *)mem, *len);
|
optimizedSniff((uint16_t *)mem, *len);
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_INFO) {
|
if (g_dbglevel >= DBG_INFO) {
|
||||||
Dbprintf("Trigger kicked in (%d >= 180)", r);
|
Dbprintf("Trigger kicked in (%d >= 180)", r);
|
||||||
Dbprintf("Collected %u samples", *len);
|
Dbprintf("Collected %u samples", *len);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
// Anon, 2019
|
// Anon, 2019
|
||||||
// Doegox, 2020
|
// Doegox, 2020
|
||||||
|
|
||||||
#define DBG if (DBGLEVEL >= DBG_EXTENDED)
|
#define DBG if (g_dbglevel >= DBG_EXTENDED)
|
||||||
|
|
||||||
#include "hitag2.h"
|
#include "hitag2.h"
|
||||||
#include "hitag2_crypto.h"
|
#include "hitag2_crypto.h"
|
||||||
|
|
|
@ -222,7 +222,7 @@ static void hitag_send_bit(int bit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hitag_send_frame(const uint8_t *frame, size_t frame_len) {
|
static void hitag_send_frame(const uint8_t *frame, size_t frame_len) {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("hitag_send_frame: (%i) %02X %02X %02X %02X", frame_len, frame[0], frame[1], frame[2], frame[3]);
|
Dbprintf("hitag_send_frame: (%i) %02X %02X %02X %02X", frame_len, frame[0], frame[1], frame[2], frame[3]);
|
||||||
// The beginning of the frame is hidden in some high level; pause until our bits will have an effect
|
// The beginning of the frame is hidden in some high level; pause until our bits will have an effect
|
||||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
|
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
|
||||||
|
@ -368,12 +368,12 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
|
||||||
switch (rxlen) {
|
switch (rxlen) {
|
||||||
case 5: {
|
case 5: {
|
||||||
//UID request with a selected response protocol mode
|
//UID request with a selected response protocol mode
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("UID request: length: %i first byte: %02x", rxlen, rx[0]);
|
Dbprintf("UID request: length: %i first byte: %02x", rxlen, rx[0]);
|
||||||
tag.pstate = HT_READY;
|
tag.pstate = HT_READY;
|
||||||
tag.tstate = HT_NO_OP;
|
tag.tstate = HT_NO_OP;
|
||||||
if ((rx[0] & 0xf0) == 0x30) {
|
if ((rx[0] & 0xf0) == 0x30) {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("HT_STANDARD");
|
Dbprintf("HT_STANDARD");
|
||||||
tag.mode = HT_STANDARD;
|
tag.mode = HT_STANDARD;
|
||||||
sof_bits = 1;
|
sof_bits = 1;
|
||||||
|
@ -381,14 +381,14 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
|
||||||
}
|
}
|
||||||
if ((rx[0] & 0xf0) == 0xc0) {
|
if ((rx[0] & 0xf0) == 0xc0) {
|
||||||
tag.mode = HT_ADVANCED;
|
tag.mode = HT_ADVANCED;
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("HT_ADVANCED");
|
Dbprintf("HT_ADVANCED");
|
||||||
sof_bits = 3;
|
sof_bits = 3;
|
||||||
m = AC2K;
|
m = AC2K;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rx[0] & 0xf0) == 0xd0) {
|
if ((rx[0] & 0xf0) == 0xd0) {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("HT_FAST_ADVANCED");
|
Dbprintf("HT_FAST_ADVANCED");
|
||||||
tag.mode = HT_FAST_ADVANCED;
|
tag.mode = HT_FAST_ADVANCED;
|
||||||
sof_bits = 3;
|
sof_bits = 3;
|
||||||
|
@ -402,10 +402,10 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
|
||||||
break;
|
break;
|
||||||
case 45: {
|
case 45: {
|
||||||
//select command from reader received
|
//select command from reader received
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
DbpString("SELECT");
|
DbpString("SELECT");
|
||||||
if (check_select(rx, tag.uid) == 1) {
|
if (check_select(rx, tag.uid) == 1) {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
DbpString("SELECT match");
|
DbpString("SELECT match");
|
||||||
//if the right tag was selected
|
//if the right tag was selected
|
||||||
*txlen = 32;
|
*txlen = 32;
|
||||||
|
@ -478,7 +478,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 40:
|
case 40:
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("WRITE");
|
Dbprintf("WRITE");
|
||||||
//data received to be written
|
//data received to be written
|
||||||
if (tag.tstate == HT_WRITING_PAGE_DATA) {
|
if (tag.tstate == HT_WRITING_PAGE_DATA) {
|
||||||
|
@ -596,7 +596,7 @@ static void hitagS_handle_reader_command(uint8_t *rx, const size_t rxlen,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("unknown rxlen: (%i) %02X %02X %02X %02X ...", rxlen, rx[0], rx[1], rx[2], rx[3]);
|
Dbprintf("unknown rxlen: (%i) %02X %02X %02X %02X ...", rxlen, rx[0], rx[1], rx[2], rx[3]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -675,7 +675,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
|
||||||
| (uid[30] << 1)
|
| (uid[30] << 1)
|
||||||
| uid[31];
|
| uid[31];
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("UID: %02X %02X %02X %02X", uid1, uid2, uid3, uid4);
|
Dbprintf("UID: %02X %02X %02X %02X", uid1, uid2, uid3, uid4);
|
||||||
|
|
||||||
tag.uid = (uid4 << 24 | uid3 << 16 | uid2 << 8 | uid1);
|
tag.uid = (uid4 << 24 | uid3 << 16 | uid2 << 8 | uid1);
|
||||||
|
@ -769,7 +769,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
|
||||||
tag.LCK1 = response_bit[26];
|
tag.LCK1 = response_bit[26];
|
||||||
tag.LCK0 = response_bit[27];
|
tag.LCK0 = response_bit[27];
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("conf0: %02X conf1: %02X conf2: %02X", conf_pages[0], conf_pages[1], conf_pages[2]);
|
Dbprintf("conf0: %02X conf1: %02X conf2: %02X", conf_pages[0], conf_pages[1], conf_pages[2]);
|
||||||
|
|
||||||
if (tag.auth == 1) {
|
if (tag.auth == 1) {
|
||||||
|
@ -792,7 +792,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
|
||||||
tx[5] = auth_ks[1];
|
tx[5] = auth_ks[1];
|
||||||
tx[6] = auth_ks[2];
|
tx[6] = auth_ks[2];
|
||||||
tx[7] = auth_ks[3];
|
tx[7] = auth_ks[3];
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("%02X %02X %02X %02X %02X %02X %02X %02X", tx[0],
|
Dbprintf("%02X %02X %02X %02X %02X %02X %02X %02X", tx[0],
|
||||||
tx[1], tx[2], tx[3], tx[4], tx[5], tx[6], tx[7]);
|
tx[1], tx[2], tx[3], tx[4], tx[5], tx[6], tx[7]);
|
||||||
} else if (htf == 01 || htf == 03) { //RHTS_CHALLENGE //WHTS_CHALLENGE
|
} else if (htf == 01 || htf == 03) { //RHTS_CHALLENGE //WHTS_CHALLENGE
|
||||||
|
@ -817,7 +817,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
|
||||||
calc_crc(&crc, ((rx[1] & 0x0f) * 16 + ((rx[2] & 0xf0) / 16)), 8);
|
calc_crc(&crc, ((rx[1] & 0x0f) * 16 + ((rx[2] & 0xf0) / 16)), 8);
|
||||||
calc_crc(&crc, ((rx[2] & 0x0f) * 16 + ((rx[3] & 0xf0) / 16)), 8);
|
calc_crc(&crc, ((rx[2] & 0x0f) * 16 + ((rx[3] & 0xf0) / 16)), 8);
|
||||||
calc_crc(&crc, ((rx[3] & 0x0f) * 16 + ((rx[4] & 0xf0) / 16)), 8);
|
calc_crc(&crc, ((rx[3] & 0x0f) * 16 + ((rx[4] & 0xf0) / 16)), 8);
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
Dbprintf("UID:::%X", tag.uid);
|
Dbprintf("UID:::%X", tag.uid);
|
||||||
Dbprintf("RND:::%X", rnd);
|
Dbprintf("RND:::%X", rnd);
|
||||||
}
|
}
|
||||||
|
@ -837,7 +837,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
|
||||||
pwdl1 = ((rx[3] & 0x0f) * 16 + ((rx[4] & 0xf0) / 16)) ^ _hitag2_byte(&state);
|
pwdl1 = ((rx[3] & 0x0f) * 16 + ((rx[4] & 0xf0) / 16)) ^ _hitag2_byte(&state);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("pwdh0 %02X pwdl0 %02X pwdl1 %02X", pwdh0, pwdl0, pwdl1);
|
Dbprintf("pwdh0 %02X pwdl0 %02X pwdl1 %02X", pwdh0, pwdl0, pwdl1);
|
||||||
|
|
||||||
//Dbprintf("%X %02X", rnd, ((rx[4] & 0x0f) * 16) + ((rx[5] & 0xf0) / 16));
|
//Dbprintf("%X %02X", rnd, ((rx[4] & 0x0f) * 16) + ((rx[5] & 0xf0) / 16));
|
||||||
|
@ -911,7 +911,7 @@ void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data) {
|
||||||
tag.max_page = 8;
|
tag.max_page = 8;
|
||||||
if ((tag.pages[1][0] & 0x2) == 0 && (tag.pages[1][0] & 0x1) == 0)
|
if ((tag.pages[1][0] & 0x2) == 0 && (tag.pages[1][0] & 0x1) == 0)
|
||||||
tag.max_page = 0;
|
tag.max_page = 0;
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
for (i = 0; i < tag.max_page; i++)
|
for (i = 0; i < tag.max_page; i++)
|
||||||
Dbprintf("Page[%2d]: %02X %02X %02X %02X", i,
|
Dbprintf("Page[%2d]: %02X %02X %02X %02X", i,
|
||||||
(tag.pages[i][3]) & 0xff,
|
(tag.pages[i][3]) & 0xff,
|
||||||
|
|
16
armsrc/i2c.c
16
armsrc/i2c.c
|
@ -351,7 +351,7 @@ bool I2C_WriteCmd(uint8_t device_cmd, uint8_t device_address) {
|
||||||
|
|
||||||
I2C_Stop();
|
I2C_Stop();
|
||||||
if (bBreak) {
|
if (bBreak) {
|
||||||
if (DBGLEVEL > 3) DbpString(I2C_ERROR);
|
if (g_dbglevel > 3) DbpString(I2C_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -381,7 +381,7 @@ bool I2C_WriteByte(uint8_t data, uint8_t device_cmd, uint8_t device_address) {
|
||||||
|
|
||||||
I2C_Stop();
|
I2C_Stop();
|
||||||
if (bBreak) {
|
if (bBreak) {
|
||||||
if (DBGLEVEL > 3) DbpString(I2C_ERROR);
|
if (g_dbglevel > 3) DbpString(I2C_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -419,7 +419,7 @@ bool I2C_BufferWrite(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t dev
|
||||||
|
|
||||||
I2C_Stop();
|
I2C_Stop();
|
||||||
if (bBreak) {
|
if (bBreak) {
|
||||||
if (DBGLEVEL > 3) DbpString(I2C_ERROR);
|
if (g_dbglevel > 3) DbpString(I2C_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -463,7 +463,7 @@ int16_t I2C_BufferRead(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t d
|
||||||
|
|
||||||
if (bBreak) {
|
if (bBreak) {
|
||||||
I2C_Stop();
|
I2C_Stop();
|
||||||
if (DBGLEVEL > 3) DbpString(I2C_ERROR);
|
if (g_dbglevel > 3) DbpString(I2C_ERROR);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -532,7 +532,7 @@ int16_t I2C_ReadFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t
|
||||||
|
|
||||||
if (bBreak) {
|
if (bBreak) {
|
||||||
I2C_Stop();
|
I2C_Stop();
|
||||||
if (DBGLEVEL > 3) DbpString(I2C_ERROR);
|
if (g_dbglevel > 3) DbpString(I2C_ERROR);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -596,7 +596,7 @@ bool I2C_WriteFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t d
|
||||||
|
|
||||||
I2C_Stop();
|
I2C_Stop();
|
||||||
if (bBreak) {
|
if (bBreak) {
|
||||||
if (DBGLEVEL > 3) DbpString(I2C_ERROR);
|
if (g_dbglevel > 3) DbpString(I2C_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -694,7 +694,7 @@ bool GetATR(smart_card_atr_t *card_ptr, bool verbose) {
|
||||||
chksum ^= card_ptr->atr[i];
|
chksum ^= card_ptr->atr[i];
|
||||||
|
|
||||||
if (chksum) {
|
if (chksum) {
|
||||||
if (DBGLEVEL > 2) DbpString("Wrong ATR checksum");
|
if (g_dbglevel > 2) DbpString("Wrong ATR checksum");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -763,7 +763,7 @@ void SmartCardRaw(smart_card_raw_t *p) {
|
||||||
((flags & SC_RAW_T0) ? I2C_DEVICE_CMD_SEND_T0 : I2C_DEVICE_CMD_SEND),
|
((flags & SC_RAW_T0) ? I2C_DEVICE_CMD_SEND_T0 : I2C_DEVICE_CMD_SEND),
|
||||||
I2C_DEVICE_ADDRESS_MAIN
|
I2C_DEVICE_ADDRESS_MAIN
|
||||||
);
|
);
|
||||||
if (res == false && DBGLEVEL > 3) {
|
if (res == false && g_dbglevel > 3) {
|
||||||
DbpString(I2C_ERROR);
|
DbpString(I2C_ERROR);
|
||||||
reply_ng(CMD_SMART_RAW, PM3_ESOFT, NULL, 0);
|
reply_ng(CMD_SMART_RAW, PM3_ESOFT, NULL, 0);
|
||||||
goto OUT;
|
goto OUT;
|
||||||
|
|
|
@ -706,7 +706,7 @@ int do_iclass_simulation(int simulationMode, uint8_t *reader_mac_buf) {
|
||||||
|
|
||||||
if (simulationMode == ICLASS_SIM_MODE_EXIT_AFTER_MAC) {
|
if (simulationMode == ICLASS_SIM_MODE_EXIT_AFTER_MAC) {
|
||||||
|
|
||||||
if (DBGLEVEL == DBG_EXTENDED) {
|
if (g_dbglevel == DBG_EXTENDED) {
|
||||||
Dbprintf("CSN: %02x %02x %02x %02x %02x %02x %02x %02x", csn[0], csn[1], csn[2], csn[3], csn[4], csn[5], csn[6], csn[7]);
|
Dbprintf("CSN: %02x %02x %02x %02x %02x %02x %02x %02x", csn[0], csn[1], csn[2], csn[3], csn[4], csn[5], csn[6], csn[7]);
|
||||||
Dbprintf("RDR: (len=%02d): %02x %02x %02x %02x %02x %02x %02x %02x %02x", len,
|
Dbprintf("RDR: (len=%02d): %02x %02x %02x %02x %02x %02x %02x %02x %02x", len,
|
||||||
receivedCmd[0], receivedCmd[1], receivedCmd[2],
|
receivedCmd[0], receivedCmd[1], receivedCmd[2],
|
||||||
|
@ -864,7 +864,7 @@ int do_iclass_simulation(int simulationMode, uint8_t *reader_mac_buf) {
|
||||||
// standard ISO15693 INVENTORY command. Ignore.
|
// standard ISO15693 INVENTORY command. Ignore.
|
||||||
} else {
|
} else {
|
||||||
// Never seen this command before
|
// Never seen this command before
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
print_result("Unhandled command received ", receivedCmd, len);
|
print_result("Unhandled command received ", receivedCmd, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1217,7 +1217,7 @@ int do_iclass_simulation_nonsec(void) {
|
||||||
// standard ISO15693 INVENTORY command. Ignore.
|
// standard ISO15693 INVENTORY command. Ignore.
|
||||||
} else {
|
} else {
|
||||||
// Never seen this command before
|
// Never seen this command before
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
print_result("Unhandled command received ", receivedCmd, len);
|
print_result("Unhandled command received ", receivedCmd, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -671,7 +671,7 @@ void RAMFUNC SniffIso14443a(uint8_t param) {
|
||||||
|
|
||||||
// Setup and start DMA.
|
// Setup and start DMA.
|
||||||
if (!FpgaSetupSscDma((uint8_t *) dma->buf, DMA_BUFFER_SIZE)) {
|
if (!FpgaSetupSscDma((uint8_t *) dma->buf, DMA_BUFFER_SIZE)) {
|
||||||
if (DBGLEVEL > 1) Dbprintf("FpgaSetupSscDma failed. Exiting");
|
if (g_dbglevel > 1) Dbprintf("FpgaSetupSscDma failed. Exiting");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -784,7 +784,7 @@ void RAMFUNC SniffIso14443a(uint8_t param) {
|
||||||
|
|
||||||
FpgaDisableTracing();
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_ERROR) {
|
if (g_dbglevel >= DBG_ERROR) {
|
||||||
Dbprintf("trace len = " _YELLOW_("%d"), BigBuf_get_traceLen());
|
Dbprintf("trace len = " _YELLOW_("%d"), BigBuf_get_traceLen());
|
||||||
}
|
}
|
||||||
switch_off();
|
switch_off();
|
||||||
|
@ -1112,7 +1112,7 @@ bool SimulateIso14443aInit(int tagType, int flags, uint8_t *data, tag_response_i
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Error: unknown tagtype (%d)", tagType);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Error: unknown tagtype (%d)", tagType);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1199,7 +1199,7 @@ bool SimulateIso14443aInit(int tagType, int flags, uint8_t *data, tag_response_i
|
||||||
|
|
||||||
*cuid = bytes_to_num(data + 3 + 3, 4);
|
*cuid = bytes_to_num(data + 3 + 3, 4);
|
||||||
} else {
|
} else {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("[-] ERROR: UID size not defined");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("[-] ERROR: UID size not defined");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1241,7 +1241,7 @@ bool SimulateIso14443aInit(int tagType, int flags, uint8_t *data, tag_response_i
|
||||||
for (size_t i = 0; i < ARRAYLEN(responses_init); i++) {
|
for (size_t i = 0; i < ARRAYLEN(responses_init); i++) {
|
||||||
if (prepare_allocated_tag_modulation(&responses_init[i], &free_buffer_pointer, &free_buffer_size) == false) {
|
if (prepare_allocated_tag_modulation(&responses_init[i], &free_buffer_pointer, &free_buffer_size) == false) {
|
||||||
BigBuf_free_keep_EM();
|
BigBuf_free_keep_EM();
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Not enough modulation buffer size, exit after %d elements", i);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Not enough modulation buffer size, exit after %d elements", i);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1636,7 +1636,7 @@ void SimulateIso14443aTag(uint8_t tagType, uint8_t flags, uint8_t *data, uint8_t
|
||||||
EmSendCmd(pack, sizeof(pack));
|
EmSendCmd(pack, sizeof(pack));
|
||||||
} else {
|
} else {
|
||||||
EmSend4bit(CARD_NACK_NA);
|
EmSend4bit(CARD_NACK_NA);
|
||||||
if (DBGLEVEL >= DBG_DEBUG) Dbprintf("Auth attempt: %08x", bytes_to_num(receivedCmd + 1, 4));
|
if (g_dbglevel >= DBG_DEBUG) Dbprintf("Auth attempt: %08x", bytes_to_num(receivedCmd + 1, 4));
|
||||||
}
|
}
|
||||||
p_response = NULL;
|
p_response = NULL;
|
||||||
} else if (receivedCmd[0] == MIFARE_ULEV1_VCSL && len == 23 && tagType == 7) {
|
} else if (receivedCmd[0] == MIFARE_ULEV1_VCSL && len == 23 && tagType == 7) {
|
||||||
|
@ -1732,7 +1732,7 @@ void SimulateIso14443aTag(uint8_t tagType, uint8_t flags, uint8_t *data, uint8_t
|
||||||
default: {
|
default: {
|
||||||
// Never seen this command before
|
// Never seen this command before
|
||||||
LogTrace(receivedCmd, Uart.len, Uart.startTime * 16 - DELAY_AIR2ARM_AS_TAG, Uart.endTime * 16 - DELAY_AIR2ARM_AS_TAG, Uart.parity, true);
|
LogTrace(receivedCmd, Uart.len, Uart.startTime * 16 - DELAY_AIR2ARM_AS_TAG, Uart.endTime * 16 - DELAY_AIR2ARM_AS_TAG, Uart.parity, true);
|
||||||
if (DBGLEVEL >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
Dbprintf("Received unknown command (len=%d):", len);
|
Dbprintf("Received unknown command (len=%d):", len);
|
||||||
Dbhexdump(len, receivedCmd, false);
|
Dbhexdump(len, receivedCmd, false);
|
||||||
}
|
}
|
||||||
|
@ -1755,7 +1755,7 @@ void SimulateIso14443aTag(uint8_t tagType, uint8_t flags, uint8_t *data, uint8_t
|
||||||
dynamic_response_info.response_n += 2;
|
dynamic_response_info.response_n += 2;
|
||||||
|
|
||||||
if (prepare_tag_modulation(&dynamic_response_info, DYNAMIC_MODULATION_BUFFER_SIZE) == false) {
|
if (prepare_tag_modulation(&dynamic_response_info, DYNAMIC_MODULATION_BUFFER_SIZE) == false) {
|
||||||
if (DBGLEVEL >= DBG_DEBUG) DbpString("Error preparing tag response");
|
if (g_dbglevel >= DBG_DEBUG) DbpString("Error preparing tag response");
|
||||||
LogTrace(receivedCmd, Uart.len, Uart.startTime * 16 - DELAY_AIR2ARM_AS_TAG, Uart.endTime * 16 - DELAY_AIR2ARM_AS_TAG, Uart.parity, true);
|
LogTrace(receivedCmd, Uart.len, Uart.startTime * 16 - DELAY_AIR2ARM_AS_TAG, Uart.endTime * 16 - DELAY_AIR2ARM_AS_TAG, Uart.parity, true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1780,7 +1780,7 @@ void SimulateIso14443aTag(uint8_t tagType, uint8_t flags, uint8_t *data, uint8_t
|
||||||
set_tracing(false);
|
set_tracing(false);
|
||||||
BigBuf_free_keep_EM();
|
BigBuf_free_keep_EM();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
Dbprintf("-[ Wake ups after halt [%d]", happened);
|
Dbprintf("-[ Wake ups after halt [%d]", happened);
|
||||||
Dbprintf("-[ Messages after halt [%d]", happened2);
|
Dbprintf("-[ Messages after halt [%d]", happened2);
|
||||||
Dbprintf("-[ Num of received cmd [%d]", cmdsRecvd);
|
Dbprintf("-[ Num of received cmd [%d]", cmdsRecvd);
|
||||||
|
@ -1837,7 +1837,7 @@ static void TransmitFor14443a(const uint8_t *cmd, uint16_t len, uint32_t *timing
|
||||||
else
|
else
|
||||||
PrepareDelayedTransfer(*timing & 0x00000007); // Delay transfer (fine tuning - up to 7 MF clock ticks)
|
PrepareDelayedTransfer(*timing & 0x00000007); // Delay transfer (fine tuning - up to 7 MF clock ticks)
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED && GetCountSspClk() >= (*timing & 0xfffffff8))
|
if (g_dbglevel >= DBG_EXTENDED && GetCountSspClk() >= (*timing & 0xfffffff8))
|
||||||
Dbprintf("TransmitFor14443a: Missed timing");
|
Dbprintf("TransmitFor14443a: Missed timing");
|
||||||
while (GetCountSspClk() < (*timing & 0xfffffff8)) {}; // Delay transfer (multiple of 8 MF clock ticks)
|
while (GetCountSspClk() < (*timing & 0xfffffff8)) {}; // Delay transfer (multiple of 8 MF clock ticks)
|
||||||
LastTimeProxToAirStart = *timing;
|
LastTimeProxToAirStart = *timing;
|
||||||
|
@ -2419,12 +2419,12 @@ void iso14443a_antifuzz(uint32_t flags) {
|
||||||
|
|
||||||
// trigger a faulty/collision response
|
// trigger a faulty/collision response
|
||||||
EmSendCmdEx(resp, 5, true);
|
EmSendCmdEx(resp, 5, true);
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("ANTICOLL or SELECT %x", received[1]);
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("ANTICOLL or SELECT %x", received[1]);
|
||||||
LED_D_INV();
|
LED_D_INV();
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
} else if (received[1] == 0x20 && received[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT_2) { // Received request for UID (cascade 2)
|
} else if (received[1] == 0x20 && received[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT_2) { // Received request for UID (cascade 2)
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("ANTICOLL or SELECT_2");
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("ANTICOLL or SELECT_2");
|
||||||
} else if (received[1] == 0x70 && received[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT) { // Received a SELECT (cascade 1)
|
} else if (received[1] == 0x70 && received[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT) { // Received a SELECT (cascade 1)
|
||||||
} else if (received[1] == 0x70 && received[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT_2) { // Received a SELECT (cascade 2)
|
} else if (received[1] == 0x70 && received[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT_2) { // Received a SELECT (cascade 2)
|
||||||
} else {
|
} else {
|
||||||
|
@ -3113,7 +3113,7 @@ void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype) {
|
||||||
if (!have_uid) { // need a full select cycle to get the uid first
|
if (!have_uid) { // need a full select cycle to get the uid first
|
||||||
iso14a_card_select_t card_info;
|
iso14a_card_select_t card_info;
|
||||||
if (!iso14443a_select_card(uid, &card_info, &cuid, true, 0, true)) {
|
if (!iso14443a_select_card(uid, &card_info, &cuid, true, 0, true)) {
|
||||||
if (DBGLEVEL >= DBG_INFO) Dbprintf("Mifare: Can't select card (ALL)");
|
if (g_dbglevel >= DBG_INFO) Dbprintf("Mifare: Can't select card (ALL)");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
switch (card_info.uidlen) {
|
switch (card_info.uidlen) {
|
||||||
|
@ -3132,7 +3132,7 @@ void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype) {
|
||||||
have_uid = true;
|
have_uid = true;
|
||||||
} else { // no need for anticollision. We can directly select the card
|
} else { // no need for anticollision. We can directly select the card
|
||||||
if (!iso14443a_fast_select_card(uid, cascade_levels)) {
|
if (!iso14443a_fast_select_card(uid, cascade_levels)) {
|
||||||
if (DBGLEVEL >= DBG_INFO) Dbprintf("Mifare: Can't select card (UID)");
|
if (g_dbglevel >= DBG_INFO) Dbprintf("Mifare: Can't select card (UID)");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3212,7 +3212,7 @@ void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype) {
|
||||||
sync_time = GetCountSspClk() & 0xfffffff8;
|
sync_time = GetCountSspClk() & 0xfffffff8;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("calibrating in cycle %d. nt_distance=%d, elapsed_prng_sequences=%d, new sync_cycles: %d\n", i, nt_distance, elapsed_prng_sequences, sync_cycles);
|
Dbprintf("calibrating in cycle %d. nt_distance=%d, elapsed_prng_sequences=%d, new sync_cycles: %d\n", i, nt_distance, elapsed_prng_sequences, sync_cycles);
|
||||||
|
|
||||||
LED_B_OFF();
|
LED_B_OFF();
|
||||||
|
@ -3239,13 +3239,13 @@ void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (consecutive_resyncs < 3) {
|
if (consecutive_resyncs < 3) {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
Dbprintf("Lost sync in cycle %d. nt_distance=%d. Consecutive Resyncs = %d. Trying one time catch up...\n", i, catch_up_cycles, consecutive_resyncs);
|
Dbprintf("Lost sync in cycle %d. nt_distance=%d. Consecutive Resyncs = %d. Trying one time catch up...\n", i, catch_up_cycles, consecutive_resyncs);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sync_cycles += catch_up_cycles;
|
sync_cycles += catch_up_cycles;
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("Lost sync in cycle %d for the fourth time consecutively (nt_distance = %d). Adjusting sync_cycles to %d.\n", i, catch_up_cycles, sync_cycles);
|
Dbprintf("Lost sync in cycle %d for the fourth time consecutively (nt_distance = %d). Adjusting sync_cycles to %d.\n", i, catch_up_cycles, sync_cycles);
|
||||||
|
|
||||||
last_catch_up = 0;
|
last_catch_up = 0;
|
||||||
|
@ -3295,7 +3295,7 @@ void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype) {
|
||||||
|
|
||||||
mf_nr_ar[3] &= 0x1F;
|
mf_nr_ar[3] &= 0x1F;
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("Number of sent auth requests: %u", i);
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("Number of sent auth requests: %u", i);
|
||||||
|
|
||||||
FpgaDisableTracing();
|
FpgaDisableTracing();
|
||||||
|
|
||||||
|
@ -3388,7 +3388,7 @@ void DetectNACKbug(void) {
|
||||||
if (!have_uid) { // need a full select cycle to get the uid first
|
if (!have_uid) { // need a full select cycle to get the uid first
|
||||||
iso14a_card_select_t card_info;
|
iso14a_card_select_t card_info;
|
||||||
if (!iso14443a_select_card(uid, &card_info, &cuid, true, 0, true)) {
|
if (!iso14443a_select_card(uid, &card_info, &cuid, true, 0, true)) {
|
||||||
if (DBGLEVEL >= DBG_INFO) Dbprintf("Mifare: Can't select card (ALL)");
|
if (g_dbglevel >= DBG_INFO) Dbprintf("Mifare: Can't select card (ALL)");
|
||||||
i = 0;
|
i = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -3410,7 +3410,7 @@ void DetectNACKbug(void) {
|
||||||
have_uid = true;
|
have_uid = true;
|
||||||
} else { // no need for anticollision. We can directly select the card
|
} else { // no need for anticollision. We can directly select the card
|
||||||
if (!iso14443a_fast_select_card(uid, cascade_levels)) {
|
if (!iso14443a_fast_select_card(uid, cascade_levels)) {
|
||||||
if (DBGLEVEL >= DBG_INFO) Dbprintf("Mifare: Can't select card (UID)");
|
if (g_dbglevel >= DBG_INFO) Dbprintf("Mifare: Can't select card (UID)");
|
||||||
i = 0;
|
i = 0;
|
||||||
have_uid = false;
|
have_uid = false;
|
||||||
continue;
|
continue;
|
||||||
|
@ -3491,7 +3491,7 @@ void DetectNACKbug(void) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("calibrating in cycle %d. nt_distance=%d, elapsed_prng_sequences=%d, new sync_cycles: %d\n", i, nt_distance, elapsed_prng_sequences, sync_cycles);
|
Dbprintf("calibrating in cycle %d. nt_distance=%d, elapsed_prng_sequences=%d, new sync_cycles: %d\n", i, nt_distance, elapsed_prng_sequences, sync_cycles);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
@ -3518,13 +3518,13 @@ void DetectNACKbug(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (consecutive_resyncs < 3) {
|
if (consecutive_resyncs < 3) {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
Dbprintf("Lost sync in cycle %d. nt_distance=%d. Consecutive Resyncs = %d. Trying one time catch up...\n", i, catch_up_cycles, consecutive_resyncs);
|
Dbprintf("Lost sync in cycle %d. nt_distance=%d. Consecutive Resyncs = %d. Trying one time catch up...\n", i, catch_up_cycles, consecutive_resyncs);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sync_cycles += catch_up_cycles;
|
sync_cycles += catch_up_cycles;
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
Dbprintf("Lost sync in cycle %d for the fourth time consecutively (nt_distance = %d). Adjusting sync_cycles to %d.\n", i, catch_up_cycles, sync_cycles);
|
Dbprintf("Lost sync in cycle %d for the fourth time consecutively (nt_distance = %d). Adjusting sync_cycles to %d.\n", i, catch_up_cycles, sync_cycles);
|
||||||
Dbprintf("nt [%08x] attacted [%08x]", nt, nt_attacked);
|
Dbprintf("nt [%08x] attacted [%08x]", nt, nt_attacked);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include "iso14443b.h"
|
#include "iso14443b.h"
|
||||||
|
|
||||||
#include "proxmark3_arm.h"
|
#include "proxmark3_arm.h"
|
||||||
#include "common.h" // access to global variable: DBGLEVEL
|
#include "common.h" // access to global variable: g_dbglevel
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "crc16.h"
|
#include "crc16.h"
|
||||||
|
@ -437,7 +437,7 @@ static void iso14b_set_timeout(uint32_t timeout_etu) {
|
||||||
ssp = MAX_14B_TIMEOUT;
|
ssp = MAX_14B_TIMEOUT;
|
||||||
|
|
||||||
iso14b_timeout = ssp;
|
iso14b_timeout = ssp;
|
||||||
if (DBGLEVEL >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
Dbprintf("ISO14443B Timeout set to %ld fwt", iso14b_timeout);
|
Dbprintf("ISO14443B Timeout set to %ld fwt", iso14b_timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -453,7 +453,7 @@ static void iso14b_set_maxframesize(uint16_t size) {
|
||||||
size = MAX_FRAME_SIZE;
|
size = MAX_FRAME_SIZE;
|
||||||
|
|
||||||
Uart.byteCntMax = size;
|
Uart.byteCntMax = size;
|
||||||
if (DBGLEVEL >= DBG_DEBUG) Dbprintf("ISO14443B Max frame size set to %d bytes", Uart.byteCntMax);
|
if (g_dbglevel >= DBG_DEBUG) Dbprintf("ISO14443B Max frame size set to %d bytes", Uart.byteCntMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -846,19 +846,19 @@ void SimulateIso14443bTag(uint8_t *pupi) {
|
||||||
// - SLOT MARKER
|
// - SLOT MARKER
|
||||||
// - ISO7816
|
// - ISO7816
|
||||||
// - emulate with a memory dump
|
// - emulate with a memory dump
|
||||||
if (DBGLEVEL >= DBG_DEBUG)
|
if (g_dbglevel >= DBG_DEBUG)
|
||||||
Dbprintf("new cmd from reader: len=%d, cmdsRecvd=%d", len, cmdsReceived);
|
Dbprintf("new cmd from reader: len=%d, cmdsRecvd=%d", len, cmdsReceived);
|
||||||
|
|
||||||
// CRC Check
|
// CRC Check
|
||||||
if (len >= 3) { // if crc exists
|
if (len >= 3) { // if crc exists
|
||||||
|
|
||||||
if (!check_crc(CRC_14443_B, receivedCmd, len)) {
|
if (!check_crc(CRC_14443_B, receivedCmd, len)) {
|
||||||
if (DBGLEVEL >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
DbpString("CRC fail");
|
DbpString("CRC fail");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (DBGLEVEL >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
DbpString("CRC passed");
|
DbpString("CRC passed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -873,7 +873,7 @@ void SimulateIso14443bTag(uint8_t *pupi) {
|
||||||
++cmdsReceived;
|
++cmdsReceived;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_DEBUG)
|
if (g_dbglevel >= DBG_DEBUG)
|
||||||
Dbprintf("Emulator stopped. Trace length: %d ", BigBuf_get_traceLen());
|
Dbprintf("Emulator stopped. Trace length: %d ", BigBuf_get_traceLen());
|
||||||
|
|
||||||
switch_off(); //simulate
|
switch_off(); //simulate
|
||||||
|
@ -1050,19 +1050,19 @@ void Simulate_iso14443b_srx_tag(uint8_t *uid) {
|
||||||
// - SLOT MARKER
|
// - SLOT MARKER
|
||||||
// - ISO7816
|
// - ISO7816
|
||||||
// - emulate with a memory dump
|
// - emulate with a memory dump
|
||||||
if (DBGLEVEL >= DBG_DEBUG)
|
if (g_dbglevel >= DBG_DEBUG)
|
||||||
Dbprintf("new cmd from reader: len=%d, cmdsRecvd=%d", len, cmdsReceived);
|
Dbprintf("new cmd from reader: len=%d, cmdsRecvd=%d", len, cmdsReceived);
|
||||||
|
|
||||||
// CRC Check
|
// CRC Check
|
||||||
if (len >= 3) { // if crc exists
|
if (len >= 3) { // if crc exists
|
||||||
|
|
||||||
if (!check_crc(CRC_14443_B, receivedCmd, len)) {
|
if (!check_crc(CRC_14443_B, receivedCmd, len)) {
|
||||||
if (DBGLEVEL >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
DbpString("CRC fail");
|
DbpString("CRC fail");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (DBGLEVEL >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
DbpString("CRC passed");
|
DbpString("CRC passed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1077,7 +1077,7 @@ void Simulate_iso14443b_srx_tag(uint8_t *uid) {
|
||||||
++cmdsReceived;
|
++cmdsReceived;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_DEBUG)
|
if (g_dbglevel >= DBG_DEBUG)
|
||||||
Dbprintf("Emulator stopped. Trace length: %d ", BigBuf_get_traceLen());
|
Dbprintf("Emulator stopped. Trace length: %d ", BigBuf_get_traceLen());
|
||||||
|
|
||||||
switch_off(); //simulate
|
switch_off(); //simulate
|
||||||
|
@ -1301,7 +1301,7 @@ static int Get14443bAnswerFromTag(uint8_t *response, uint16_t max_len, uint32_t
|
||||||
// The DMA buffer, used to stream samples from the FPGA
|
// The DMA buffer, used to stream samples from the FPGA
|
||||||
dmabuf16_t *dma = get_dma16();
|
dmabuf16_t *dma = get_dma16();
|
||||||
if (FpgaSetupSscDma((uint8_t *) dma->buf, DMA_BUFFER_SIZE) == false) {
|
if (FpgaSetupSscDma((uint8_t *) dma->buf, DMA_BUFFER_SIZE) == false) {
|
||||||
if (DBGLEVEL > DBG_ERROR) Dbprintf("FpgaSetupSscDma failed. Exiting");
|
if (g_dbglevel > DBG_ERROR) Dbprintf("FpgaSetupSscDma failed. Exiting");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1936,7 +1936,7 @@ static int read_srx_block(uint8_t blocknr, uint8_t *block) {
|
||||||
memcpy(block, r_block, 4);
|
memcpy(block, r_block, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
Dbprintf("Address=%02x, Contents=%08x, CRC=%04x",
|
Dbprintf("Address=%02x, Contents=%08x, CRC=%04x",
|
||||||
blocknr,
|
blocknr,
|
||||||
(r_block[3] << 24) + (r_block[2] << 16) + (r_block[1] << 8) + r_block[0],
|
(r_block[3] << 24) + (r_block[2] << 16) + (r_block[1] << 8) + r_block[0],
|
||||||
|
@ -2027,7 +2027,7 @@ void SniffIso14443b(void) {
|
||||||
|
|
||||||
// Setup and start DMA.
|
// Setup and start DMA.
|
||||||
if (!FpgaSetupSscDma((uint8_t *) dma->buf, DMA_BUFFER_SIZE)) {
|
if (!FpgaSetupSscDma((uint8_t *) dma->buf, DMA_BUFFER_SIZE)) {
|
||||||
if (DBGLEVEL > DBG_ERROR) DbpString("FpgaSetupSscDma failed. Exiting");
|
if (g_dbglevel > DBG_ERROR) DbpString("FpgaSetupSscDma failed. Exiting");
|
||||||
switch_off();
|
switch_off();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2175,7 +2175,7 @@ void SendRawCommand14443B_Ex(iso14b_raw_cmd_t *p) {
|
||||||
// receive buffer
|
// receive buffer
|
||||||
uint8_t buf[PM3_CMD_DATA_SIZE];
|
uint8_t buf[PM3_CMD_DATA_SIZE];
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
if (DBGLEVEL > DBG_DEBUG) {
|
if (g_dbglevel > DBG_DEBUG) {
|
||||||
Dbprintf("14b raw: param, %04x", p->flags);
|
Dbprintf("14b raw: param, %04x", p->flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -667,7 +667,7 @@ int GetIso15693AnswerFromTag(uint8_t *response, uint16_t max_len, uint16_t timeo
|
||||||
|
|
||||||
// Setup and start DMA.
|
// Setup and start DMA.
|
||||||
if (FpgaSetupSscDma((uint8_t *) dma->buf, DMA_BUFFER_SIZE) == false) {
|
if (FpgaSetupSscDma((uint8_t *) dma->buf, DMA_BUFFER_SIZE) == false) {
|
||||||
if (DBGLEVEL > DBG_ERROR) Dbprintf("FpgaSetupSscDma failed. Exiting");
|
if (g_dbglevel > DBG_ERROR) Dbprintf("FpgaSetupSscDma failed. Exiting");
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -743,7 +743,7 @@ int GetIso15693AnswerFromTag(uint8_t *response, uint16_t max_len, uint16_t timeo
|
||||||
- (32 * 16) // time for SOF transfer
|
- (32 * 16) // time for SOF transfer
|
||||||
- (dt->lastBit != SOF_PART2 ? (32 * 16) : 0); // time for EOF transfer
|
- (dt->lastBit != SOF_PART2 ? (32 * 16) : 0); // time for EOF transfer
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
Dbprintf("samples = %d, ret = %d, Decoder: state = %d, lastBit = %d, len = %d, bitCount = %d, posCount = %d, maxlen = %u",
|
Dbprintf("samples = %d, ret = %d, Decoder: state = %d, lastBit = %d, len = %d, bitCount = %d, posCount = %d, maxlen = %u",
|
||||||
samples,
|
samples,
|
||||||
ret,
|
ret,
|
||||||
|
@ -1120,7 +1120,7 @@ int GetIso15693CommandFromReader(uint8_t *received, size_t max_len, uint32_t *eo
|
||||||
// Setup and start DMA.
|
// Setup and start DMA.
|
||||||
dmabuf8_t *dma = get_dma8();
|
dmabuf8_t *dma = get_dma8();
|
||||||
if (FpgaSetupSscDma(dma->buf, DMA_BUFFER_SIZE) == false) {
|
if (FpgaSetupSscDma(dma->buf, DMA_BUFFER_SIZE) == false) {
|
||||||
if (DBGLEVEL > DBG_ERROR) Dbprintf("FpgaSetupSscDma failed. Exiting");
|
if (g_dbglevel > DBG_ERROR) Dbprintf("FpgaSetupSscDma failed. Exiting");
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
uint8_t *upTo = dma->buf;
|
uint8_t *upTo = dma->buf;
|
||||||
|
@ -1172,7 +1172,7 @@ int GetIso15693CommandFromReader(uint8_t *received, size_t max_len, uint32_t *eo
|
||||||
|
|
||||||
FpgaDisableSscDma();
|
FpgaDisableSscDma();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
Dbprintf("samples = %d, gotFrame = %d, Decoder: state = %d, len = %d, bitCount = %d, posCount = %d",
|
Dbprintf("samples = %d, gotFrame = %d, Decoder: state = %d, len = %d, bitCount = %d, posCount = %d",
|
||||||
samples, gotFrame, dr->state, dr->byteCount,
|
samples, gotFrame, dr->state, dr->byteCount,
|
||||||
dr->bitCount, dr->posCount);
|
dr->bitCount, dr->posCount);
|
||||||
|
@ -1287,7 +1287,7 @@ void SniffIso15693(uint8_t jam_search_len, uint8_t *jam_search_string) {
|
||||||
|
|
||||||
// Setup and start DMA.
|
// Setup and start DMA.
|
||||||
if (FpgaSetupSscDma((uint8_t *) dma->buf, DMA_BUFFER_SIZE) == false) {
|
if (FpgaSetupSscDma((uint8_t *) dma->buf, DMA_BUFFER_SIZE) == false) {
|
||||||
if (DBGLEVEL > DBG_ERROR) DbpString("FpgaSetupSscDma failed. Exiting");
|
if (g_dbglevel > DBG_ERROR) DbpString("FpgaSetupSscDma failed. Exiting");
|
||||||
switch_off();
|
switch_off();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1587,7 +1587,7 @@ static void DbdecodeIso15693Answer(int len, uint8_t *d) {
|
||||||
else
|
else
|
||||||
strncat(status, "[!] crc (" _RED_("fail") ")", DBD15STATLEN - strlen(status));
|
strncat(status, "[!] crc (" _RED_("fail") ")", DBD15STATLEN - strlen(status));
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("%s", status);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("%s", status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1642,7 +1642,7 @@ void ReaderIso15693(uint32_t parameter, iso15_card_select_t *p_card) {
|
||||||
p_card->uidlen = 8;
|
p_card->uidlen = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
Dbprintf("[+] UID = %02X%02X%02X%02X%02X%02X%02X%02X",
|
Dbprintf("[+] UID = %02X%02X%02X%02X%02X%02X%02X%02X",
|
||||||
uid[0], uid[1], uid[2], uid[3],
|
uid[0], uid[1], uid[2], uid[3],
|
||||||
uid[4], uid[5], uid[5], uid[6]
|
uid[4], uid[5], uid[5], uid[6]
|
||||||
|
@ -1655,7 +1655,7 @@ void ReaderIso15693(uint32_t parameter, iso15_card_select_t *p_card) {
|
||||||
// asbytes = uid.
|
// asbytes = uid.
|
||||||
reply_mix(CMD_ACK, 1, sizeof(uid), 0, uid, sizeof(uid));
|
reply_mix(CMD_ACK, 1, sizeof(uid), 0, uid, sizeof(uid));
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
Dbprintf("[+] %d octets read from IDENTIFY request:", recvlen);
|
Dbprintf("[+] %d octets read from IDENTIFY request:", recvlen);
|
||||||
DbdecodeIso15693Answer(recvlen, answer);
|
DbdecodeIso15693Answer(recvlen, answer);
|
||||||
Dbhexdump(recvlen, answer, true);
|
Dbhexdump(recvlen, answer, true);
|
||||||
|
|
|
@ -503,7 +503,7 @@ void LegicRfSimulate(uint8_t tagtype, bool send_reply) {
|
||||||
|
|
||||||
OUT:
|
OUT:
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_ERROR) {
|
if (g_dbglevel >= DBG_ERROR) {
|
||||||
Dbprintf("Emulator stopped. Tracing: %d trace length: %d ", get_tracing(), BigBuf_get_traceLen());
|
Dbprintf("Emulator stopped. Tracing: %d trace length: %d ", get_tracing(), BigBuf_get_traceLen());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ void lf_sample_mean(void) {
|
||||||
adc_avg = adc_sum >> 5;
|
adc_avg = adc_sum >> 5;
|
||||||
previous_adc_val = adc_avg;
|
previous_adc_val = adc_avg;
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("LF ADC average %u", adc_avg);
|
Dbprintf("LF ADC average %u", adc_avg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -338,7 +338,7 @@ void setT55xxConfig(uint8_t arg0, t55xx_configurations_t *c) {
|
||||||
// write new
|
// write new
|
||||||
res = Flash_Write(T55XX_CONFIG_OFFSET, buf, T55XX_CONFIG_LEN);
|
res = Flash_Write(T55XX_CONFIG_OFFSET, buf, T55XX_CONFIG_LEN);
|
||||||
|
|
||||||
if (res == T55XX_CONFIG_LEN && DBGLEVEL > 1) {
|
if (res == T55XX_CONFIG_LEN && g_dbglevel > 1) {
|
||||||
DbpString("T55XX Config save " _GREEN_("success"));
|
DbpString("T55XX Config save " _GREEN_("success"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,7 +378,7 @@ void loadT55xxConfig(void) {
|
||||||
memcpy((uint8_t *)&T55xx_Timing, buf, T55XX_CONFIG_LEN);
|
memcpy((uint8_t *)&T55xx_Timing, buf, T55XX_CONFIG_LEN);
|
||||||
|
|
||||||
if (isok == T55XX_CONFIG_LEN) {
|
if (isok == T55XX_CONFIG_LEN) {
|
||||||
if (DBGLEVEL > 1) DbpString("T55XX Config load success");
|
if (g_dbglevel > 1) DbpString("T55XX Config load success");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -1854,7 +1854,7 @@ void T55xxDangerousRawTest(uint8_t *data) {
|
||||||
for (uint8_t i = 0; i < c->bitlen; i++)
|
for (uint8_t i = 0; i < c->bitlen; i++)
|
||||||
len = T55xx_SetBits(bs, len, c->data[i], 1, sizeof(bs));
|
len = T55xx_SetBits(bs, len, c->data[i], 1, sizeof(bs));
|
||||||
|
|
||||||
if (DBGLEVEL > 1) {
|
if (g_dbglevel > 1) {
|
||||||
Dbprintf("LEN %i, TIMING %i", len, c->time);
|
Dbprintf("LEN %i, TIMING %i", len, c->time);
|
||||||
for (uint8_t i = 0; i < len; i++) {
|
for (uint8_t i = 0; i < len; i++) {
|
||||||
uint8_t sendbits = (bs[BITSTREAM_BYTE(i)] >> BITSTREAM_BIT(i));
|
uint8_t sendbits = (bs[BITSTREAM_BYTE(i)] >> BITSTREAM_BIT(i));
|
||||||
|
@ -2101,7 +2101,7 @@ void T55xx_ChkPwds(uint8_t flags) {
|
||||||
}
|
}
|
||||||
baseline_faulty >>= 5;
|
baseline_faulty >>= 5;
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_DEBUG)
|
if (g_dbglevel >= DBG_DEBUG)
|
||||||
Dbprintf("Baseline " _YELLOW_("%llu"), baseline_faulty);
|
Dbprintf("Baseline " _YELLOW_("%llu"), baseline_faulty);
|
||||||
|
|
||||||
uint8_t *pwds = BigBuf_get_EM_addr();
|
uint8_t *pwds = BigBuf_get_EM_addr();
|
||||||
|
@ -2163,7 +2163,7 @@ void T55xx_ChkPwds(uint8_t flags) {
|
||||||
int64_t tmp_dist = (baseline_faulty - sum);
|
int64_t tmp_dist = (baseline_faulty - sum);
|
||||||
curr = ABS(tmp_dist);
|
curr = ABS(tmp_dist);
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_DEBUG)
|
if (g_dbglevel >= DBG_DEBUG)
|
||||||
Dbprintf("%08x has distance " _YELLOW_("%llu"), pwd, curr);
|
Dbprintf("%08x has distance " _YELLOW_("%llu"), pwd, curr);
|
||||||
|
|
||||||
if (curr > prev) {
|
if (curr > prev) {
|
||||||
|
@ -2268,7 +2268,7 @@ void CopyHIDtoT55x7(uint32_t hi2, uint32_t hi, uint32_t lo, uint8_t longFMT, boo
|
||||||
LED_D_ON();
|
LED_D_ON();
|
||||||
if (em) {
|
if (em) {
|
||||||
Dbprintf("Clone HID Prox to EM4x05 is untested and disabled until verified");
|
Dbprintf("Clone HID Prox to EM4x05 is untested and disabled until verified");
|
||||||
if (DBGLEVEL == DBG_DEBUG) {
|
if (g_dbglevel == DBG_DEBUG) {
|
||||||
Dbprintf("# | data ( EM4x05 )");
|
Dbprintf("# | data ( EM4x05 )");
|
||||||
Dbprintf("--+----------------");
|
Dbprintf("--+----------------");
|
||||||
Dbprintf("0 | ", data[0]);
|
Dbprintf("0 | ", data[0]);
|
||||||
|
|
|
@ -284,7 +284,7 @@ uint32_t DoAcquisition(uint8_t decimation, uint8_t bits_per_sample, bool avg, in
|
||||||
|
|
||||||
initSampleBuffer(&sample_size);
|
initSampleBuffer(&sample_size);
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
printSamples();
|
printSamples();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,7 +443,7 @@ void doT55x7Acquisition(size_t sample_size) {
|
||||||
|
|
||||||
uint16_t checker = 0;
|
uint16_t checker = 0;
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
Dbprintf("doT55x7Acquisition - after init");
|
Dbprintf("doT55x7Acquisition - after init");
|
||||||
print_stack_usage();
|
print_stack_usage();
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,22 +83,22 @@ void MifareReadBlock(uint8_t blockNo, uint8_t keyType, uint8_t *datain) {
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Can't select card");
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (mifare_classic_auth(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST)) {
|
if (mifare_classic_auth(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Auth error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Auth error");
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (mifare_classic_readblock(pcs, cuid, blockNo, dataoutbuf)) {
|
if (mifare_classic_readblock(pcs, cuid, blockNo, dataoutbuf)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Read block error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Read block error");
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (mifare_classic_halt(pcs, cuid)) {
|
if (mifare_classic_halt(pcs, cuid)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Halt error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Halt error");
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ void MifareReadBlock(uint8_t blockNo, uint8_t keyType, uint8_t *datain) {
|
||||||
|
|
||||||
crypto1_deinit(pcs);
|
crypto1_deinit(pcs);
|
||||||
|
|
||||||
if (DBGLEVEL >= 2) DbpString("READ BLOCK FINISHED");
|
if (g_dbglevel >= 2) DbpString("READ BLOCK FINISHED");
|
||||||
|
|
||||||
LED_B_ON();
|
LED_B_ON();
|
||||||
reply_ng(CMD_HF_MIFARE_READBL, status, dataoutbuf, 16);
|
reply_ng(CMD_HF_MIFARE_READBL, status, dataoutbuf, 16);
|
||||||
|
@ -132,13 +132,13 @@ void MifareUC_Auth(uint8_t arg0, uint8_t *keybytes) {
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
|
||||||
if (!iso14443a_select_card(NULL, NULL, NULL, true, 0, true)) {
|
if (!iso14443a_select_card(NULL, NULL, NULL, true, 0, true)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Can't select card");
|
||||||
OnError(0);
|
OnError(0);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!mifare_ultra_auth(keybytes)) {
|
if (!mifare_ultra_auth(keybytes)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Authentication failed");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Authentication failed");
|
||||||
OnError(1);
|
OnError(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,7 @@ void MifareUReadBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain) {
|
||||||
|
|
||||||
int len = iso14443a_select_card(NULL, NULL, NULL, true, 0, true);
|
int len = iso14443a_select_card(NULL, NULL, NULL, true, 0, true);
|
||||||
if (!len) {
|
if (!len) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card (RC:%02X)", len);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Can't select card (RC:%02X)", len);
|
||||||
OnError(1);
|
OnError(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -196,13 +196,13 @@ void MifareUReadBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mifare_ultra_readblock(blockNo, dataout)) {
|
if (mifare_ultra_readblock(blockNo, dataout)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Read block error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Read block error");
|
||||||
OnError(2);
|
OnError(2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mifare_ultra_halt()) {
|
if (mifare_ultra_halt()) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Halt error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Halt error");
|
||||||
OnError(3);
|
OnError(3);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -244,28 +244,28 @@ void MifareReadSector(uint8_t arg0, uint8_t arg1, uint8_t *datain) {
|
||||||
isOK = 1;
|
isOK = 1;
|
||||||
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
||||||
isOK = 0;
|
isOK = 0;
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Can't select card");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (isOK && mifare_classic_auth(pcs, cuid, FirstBlockOfSector(sectorNo), keyType, ui64Key, AUTH_FIRST)) {
|
if (isOK && mifare_classic_auth(pcs, cuid, FirstBlockOfSector(sectorNo), keyType, ui64Key, AUTH_FIRST)) {
|
||||||
isOK = 0;
|
isOK = 0;
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Auth error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Auth error");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t blockNo = 0; isOK && blockNo < NumBlocksPerSector(sectorNo); blockNo++) {
|
for (uint8_t blockNo = 0; isOK && blockNo < NumBlocksPerSector(sectorNo); blockNo++) {
|
||||||
if (mifare_classic_readblock(pcs, cuid, FirstBlockOfSector(sectorNo) + blockNo, dataoutbuf + 16 * blockNo)) {
|
if (mifare_classic_readblock(pcs, cuid, FirstBlockOfSector(sectorNo) + blockNo, dataoutbuf + 16 * blockNo)) {
|
||||||
isOK = 0;
|
isOK = 0;
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Read sector %2d block %2d error", sectorNo, blockNo);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Read sector %2d block %2d error", sectorNo, blockNo);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mifare_classic_halt(pcs, cuid)) {
|
if (mifare_classic_halt(pcs, cuid)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Halt error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Halt error");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBGLEVEL >= 2) DbpString("READ SECTOR FINISHED");
|
if (g_dbglevel >= 2) DbpString("READ SECTOR FINISHED");
|
||||||
|
|
||||||
crypto1_deinit(pcs);
|
crypto1_deinit(pcs);
|
||||||
|
|
||||||
|
@ -308,7 +308,7 @@ void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain)
|
||||||
|
|
||||||
int len = iso14443a_select_card(NULL, NULL, NULL, true, 0, true);
|
int len = iso14443a_select_card(NULL, NULL, NULL, true, 0, true);
|
||||||
if (!len) {
|
if (!len) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card (RC:%d)", len);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Can't select card (RC:%d)", len);
|
||||||
OnError(1);
|
OnError(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -345,7 +345,7 @@ void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain)
|
||||||
len = mifare_ultra_readblock(blockNo + i, dataout + 4 * i);
|
len = mifare_ultra_readblock(blockNo + i, dataout + 4 * i);
|
||||||
|
|
||||||
if (len) {
|
if (len) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Read block %d error", i);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Read block %d error", i);
|
||||||
// if no blocks read - error out
|
// if no blocks read - error out
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
OnError(2);
|
OnError(2);
|
||||||
|
@ -361,12 +361,12 @@ void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain)
|
||||||
|
|
||||||
len = mifare_ultra_halt();
|
len = mifare_ultra_halt();
|
||||||
if (len) {
|
if (len) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Halt error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Halt error");
|
||||||
OnError(3);
|
OnError(3);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("Blocks read %d", countblocks);
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("Blocks read %d", countblocks);
|
||||||
|
|
||||||
countblocks *= 4;
|
countblocks *= 4;
|
||||||
|
|
||||||
|
@ -410,22 +410,22 @@ void MifareWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain) {
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Can't select card");
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (mifare_classic_auth(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST)) {
|
if (mifare_classic_auth(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Auth error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Auth error");
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (mifare_classic_writeblock(pcs, cuid, blockNo, blockdata)) {
|
if (mifare_classic_writeblock(pcs, cuid, blockNo, blockdata)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Write block error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Write block error");
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (mifare_classic_halt(pcs, cuid)) {
|
if (mifare_classic_halt(pcs, cuid)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Halt error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Halt error");
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -435,7 +435,7 @@ void MifareWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain) {
|
||||||
|
|
||||||
crypto1_deinit(pcs);
|
crypto1_deinit(pcs);
|
||||||
|
|
||||||
if (DBGLEVEL >= 2) DbpString("WRITE BLOCK FINISHED");
|
if (g_dbglevel >= 2) DbpString("WRITE BLOCK FINISHED");
|
||||||
|
|
||||||
reply_mix(CMD_ACK, isOK, 0, 0, 0, 0);
|
reply_mix(CMD_ACK, isOK, 0, 0, 0, 0);
|
||||||
|
|
||||||
|
@ -466,7 +466,7 @@ static void MifareUWriteBlockEx(uint8_t arg0, uint8_t arg1, uint8_t *datain, boo
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
|
||||||
if (!iso14443a_select_card(NULL, NULL, NULL, true, 0, true)) {
|
if (!iso14443a_select_card(NULL, NULL, NULL, true, 0, true)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Can't select card");
|
||||||
OnError(0);
|
OnError(0);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
@ -494,18 +494,18 @@ static void MifareUWriteBlockEx(uint8_t arg0, uint8_t arg1, uint8_t *datain, boo
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mifare_ultra_writeblock(blockNo, blockdata)) {
|
if (mifare_ultra_writeblock(blockNo, blockdata)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Write block error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Write block error");
|
||||||
OnError(0);
|
OnError(0);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (mifare_ultra_halt()) {
|
if (mifare_ultra_halt()) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Halt error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Halt error");
|
||||||
OnError(0);
|
OnError(0);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (DBGLEVEL >= 2) DbpString("WRITE BLOCK FINISHED");
|
if (g_dbglevel >= 2) DbpString("WRITE BLOCK FINISHED");
|
||||||
|
|
||||||
if (reply)
|
if (reply)
|
||||||
reply_mix(CMD_ACK, 1, 0, 0, 0, 0);
|
reply_mix(CMD_ACK, 1, 0, 0, 0, 0);
|
||||||
|
@ -540,7 +540,7 @@ void MifareUWriteBlockCompat(uint8_t arg0, uint8_t arg1, uint8_t *datain) {
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
|
||||||
if (!iso14443a_select_card(NULL, NULL, NULL, true, 0, true)) {
|
if (!iso14443a_select_card(NULL, NULL, NULL, true, 0, true)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Can't select card");
|
||||||
OnError(0);
|
OnError(0);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
@ -568,18 +568,18 @@ void MifareUWriteBlockCompat(uint8_t arg0, uint8_t arg1, uint8_t *datain) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mifare_ultra_writeblock_compat(blockNo, blockdata)) {
|
if (mifare_ultra_writeblock_compat(blockNo, blockdata)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Write block error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Write block error");
|
||||||
OnError(0);
|
OnError(0);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (mifare_ultra_halt()) {
|
if (mifare_ultra_halt()) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Halt error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Halt error");
|
||||||
OnError(0);
|
OnError(0);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (DBGLEVEL >= 2) DbpString("WRITE BLOCK FINISHED");
|
if (g_dbglevel >= 2) DbpString("WRITE BLOCK FINISHED");
|
||||||
|
|
||||||
reply_mix(CMD_ACK, 1, 0, 0, 0, 0);
|
reply_mix(CMD_ACK, 1, 0, 0, 0, 0);
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
|
@ -603,7 +603,7 @@ void MifareUSetPwd(uint8_t arg0, uint8_t *datain) {
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
|
||||||
if (!iso14443a_select_card(NULL, NULL, NULL, true, 0, true)) {
|
if (!iso14443a_select_card(NULL, NULL, NULL, true, 0, true)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Can't select card");
|
||||||
OnError(0);
|
OnError(0);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
@ -613,7 +613,7 @@ void MifareUSetPwd(uint8_t arg0, uint8_t *datain) {
|
||||||
blockdata[2] = pwd[5];
|
blockdata[2] = pwd[5];
|
||||||
blockdata[3] = pwd[4];
|
blockdata[3] = pwd[4];
|
||||||
if (mifare_ultra_writeblock(44, blockdata)) {
|
if (mifare_ultra_writeblock(44, blockdata)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Write block error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Write block error");
|
||||||
OnError(44);
|
OnError(44);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
@ -623,7 +623,7 @@ void MifareUSetPwd(uint8_t arg0, uint8_t *datain) {
|
||||||
blockdata[2] = pwd[1];
|
blockdata[2] = pwd[1];
|
||||||
blockdata[3] = pwd[0];
|
blockdata[3] = pwd[0];
|
||||||
if (mifare_ultra_writeblock(45, blockdata)) {
|
if (mifare_ultra_writeblock(45, blockdata)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Write block error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Write block error");
|
||||||
OnError(45);
|
OnError(45);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
@ -633,7 +633,7 @@ void MifareUSetPwd(uint8_t arg0, uint8_t *datain) {
|
||||||
blockdata[2] = pwd[13];
|
blockdata[2] = pwd[13];
|
||||||
blockdata[3] = pwd[12];
|
blockdata[3] = pwd[12];
|
||||||
if (mifare_ultra_writeblock(46, blockdata)) {
|
if (mifare_ultra_writeblock(46, blockdata)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Write block error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Write block error");
|
||||||
OnError(46);
|
OnError(46);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
@ -643,13 +643,13 @@ void MifareUSetPwd(uint8_t arg0, uint8_t *datain) {
|
||||||
blockdata[2] = pwd[9];
|
blockdata[2] = pwd[9];
|
||||||
blockdata[3] = pwd[8];
|
blockdata[3] = pwd[8];
|
||||||
if (mifare_ultra_writeblock(47, blockdata)) {
|
if (mifare_ultra_writeblock(47, blockdata)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Write block error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Write block error");
|
||||||
OnError(47);
|
OnError(47);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (mifare_ultra_halt()) {
|
if (mifare_ultra_halt()) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Halt error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Halt error");
|
||||||
OnError(0);
|
OnError(0);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
@ -710,7 +710,7 @@ void MifareAcquireNonces(uint32_t arg0, uint32_t flags) {
|
||||||
if (!have_uid) { // need a full select cycle to get the uid first
|
if (!have_uid) { // need a full select cycle to get the uid first
|
||||||
iso14a_card_select_t card_info;
|
iso14a_card_select_t card_info;
|
||||||
if (!iso14443a_select_card(uid, &card_info, &cuid, true, 0, true)) {
|
if (!iso14443a_select_card(uid, &card_info, &cuid, true, 0, true)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("AcquireNonces: Can't select card (ALL)");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("AcquireNonces: Can't select card (ALL)");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
switch (card_info.uidlen) {
|
switch (card_info.uidlen) {
|
||||||
|
@ -729,7 +729,7 @@ void MifareAcquireNonces(uint32_t arg0, uint32_t flags) {
|
||||||
have_uid = true;
|
have_uid = true;
|
||||||
} else { // no need for anticollision. We can directly select the card
|
} else { // no need for anticollision. We can directly select the card
|
||||||
if (!iso14443a_fast_select_card(uid, cascade_levels)) {
|
if (!iso14443a_fast_select_card(uid, cascade_levels)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("AcquireNonces: Can't select card (UID)");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("AcquireNonces: Can't select card (UID)");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -744,7 +744,7 @@ void MifareAcquireNonces(uint32_t arg0, uint32_t flags) {
|
||||||
CHK_TIMEOUT();
|
CHK_TIMEOUT();
|
||||||
|
|
||||||
if (len != 4) {
|
if (len != 4) {
|
||||||
if (DBGLEVEL >= 2) Dbprintf("AcquireNonces: Auth1 error");
|
if (g_dbglevel >= 2) Dbprintf("AcquireNonces: Auth1 error");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -758,7 +758,7 @@ void MifareAcquireNonces(uint32_t arg0, uint32_t flags) {
|
||||||
reply_old(CMD_ACK, isOK, cuid, num_nonces, buf, sizeof(buf));
|
reply_old(CMD_ACK, isOK, cuid, num_nonces, buf, sizeof(buf));
|
||||||
LED_B_OFF();
|
LED_B_OFF();
|
||||||
|
|
||||||
if (DBGLEVEL >= 3) DbpString("AcquireNonces finished");
|
if (g_dbglevel >= 3) DbpString("AcquireNonces finished");
|
||||||
|
|
||||||
if (field_off) {
|
if (field_off) {
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
|
@ -824,7 +824,7 @@ void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags,
|
||||||
if (!have_uid) { // need a full select cycle to get the uid first
|
if (!have_uid) { // need a full select cycle to get the uid first
|
||||||
iso14a_card_select_t card_info;
|
iso14a_card_select_t card_info;
|
||||||
if (!iso14443a_select_card(uid, &card_info, &cuid, true, 0, true)) {
|
if (!iso14443a_select_card(uid, &card_info, &cuid, true, 0, true)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("AcquireEncryptedNonces: Can't select card (ALL)");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("AcquireEncryptedNonces: Can't select card (ALL)");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
switch (card_info.uidlen) {
|
switch (card_info.uidlen) {
|
||||||
|
@ -843,7 +843,7 @@ void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags,
|
||||||
have_uid = true;
|
have_uid = true;
|
||||||
} else { // no need for anticollision. We can directly select the card
|
} else { // no need for anticollision. We can directly select the card
|
||||||
if (!iso14443a_fast_select_card(uid, cascade_levels)) {
|
if (!iso14443a_fast_select_card(uid, cascade_levels)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("AcquireEncryptedNonces: Can't select card (UID)");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("AcquireEncryptedNonces: Can't select card (UID)");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -853,7 +853,7 @@ void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags,
|
||||||
|
|
||||||
uint32_t nt1;
|
uint32_t nt1;
|
||||||
if (mifare_classic_authex(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST, &nt1, NULL)) {
|
if (mifare_classic_authex(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST, &nt1, NULL)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("AcquireEncryptedNonces: Auth1 error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("AcquireEncryptedNonces: Auth1 error");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -864,7 +864,7 @@ void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags,
|
||||||
CHK_TIMEOUT();
|
CHK_TIMEOUT();
|
||||||
|
|
||||||
if (len != 4) {
|
if (len != 4) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("AcquireEncryptedNonces: Auth2 error len=%d", len);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("AcquireEncryptedNonces: Auth2 error len=%d", len);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -886,7 +886,7 @@ void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags,
|
||||||
reply_old(CMD_ACK, isOK, cuid, num_nonces, buf, sizeof(buf));
|
reply_old(CMD_ACK, isOK, cuid, num_nonces, buf, sizeof(buf));
|
||||||
LED_B_OFF();
|
LED_B_OFF();
|
||||||
|
|
||||||
if (DBGLEVEL >= 3) DbpString("AcquireEncryptedNonces finished");
|
if (g_dbglevel >= 3) DbpString("AcquireEncryptedNonces finished");
|
||||||
|
|
||||||
if (field_off) {
|
if (field_off) {
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
|
@ -959,27 +959,27 @@ void MifareNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo, uint8
|
||||||
|
|
||||||
// prepare next select. No need to power down the card.
|
// prepare next select. No need to power down the card.
|
||||||
if (mifare_classic_halt(pcs, cuid)) {
|
if (mifare_classic_halt(pcs, cuid)) {
|
||||||
if (DBGLEVEL >= DBG_INFO) Dbprintf("Nested: Halt error");
|
if (g_dbglevel >= DBG_INFO) Dbprintf("Nested: Halt error");
|
||||||
rtr--;
|
rtr--;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
||||||
if (DBGLEVEL >= DBG_INFO) Dbprintf("Nested: Can't select card");
|
if (g_dbglevel >= DBG_INFO) Dbprintf("Nested: Can't select card");
|
||||||
rtr--;
|
rtr--;
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
auth1_time = 0;
|
auth1_time = 0;
|
||||||
if (mifare_classic_authex(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST, &nt1, &auth1_time)) {
|
if (mifare_classic_authex(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST, &nt1, &auth1_time)) {
|
||||||
if (DBGLEVEL >= DBG_INFO) Dbprintf("Nested: Auth1 error");
|
if (g_dbglevel >= DBG_INFO) Dbprintf("Nested: Auth1 error");
|
||||||
rtr--;
|
rtr--;
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
auth2_time = (delta_time) ? auth1_time + delta_time : 0;
|
auth2_time = (delta_time) ? auth1_time + delta_time : 0;
|
||||||
|
|
||||||
if (mifare_classic_authex(pcs, cuid, blockNo, keyType, ui64Key, AUTH_NESTED, &nt2, &auth2_time)) {
|
if (mifare_classic_authex(pcs, cuid, blockNo, keyType, ui64Key, AUTH_NESTED, &nt2, &auth2_time)) {
|
||||||
if (DBGLEVEL >= DBG_INFO) Dbprintf("Nested: Auth2 error");
|
if (g_dbglevel >= DBG_INFO) Dbprintf("Nested: Auth2 error");
|
||||||
rtr--;
|
rtr--;
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
@ -1004,7 +1004,7 @@ void MifareNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo, uint8
|
||||||
} else {
|
} else {
|
||||||
delta_time = auth2_time - auth1_time + 32; // allow some slack for proper timing
|
delta_time = auth2_time - auth1_time + 32; // allow some slack for proper timing
|
||||||
}
|
}
|
||||||
if (DBGLEVEL >= DBG_DEBUG) Dbprintf("Nested: calibrating... ntdist=%d", i);
|
if (g_dbglevel >= DBG_DEBUG) Dbprintf("Nested: calibrating... ntdist=%d", i);
|
||||||
} else {
|
} else {
|
||||||
unsuccessful_tries++;
|
unsuccessful_tries++;
|
||||||
if (unsuccessful_tries > NESTED_MAX_TRIES) { // card isn't vulnerable to nested attack (random numbers are not predictable)
|
if (unsuccessful_tries > NESTED_MAX_TRIES) { // card isn't vulnerable to nested attack (random numbers are not predictable)
|
||||||
|
@ -1016,7 +1016,7 @@ void MifareNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo, uint8
|
||||||
if (rtr > 1)
|
if (rtr > 1)
|
||||||
davg = (davg + (rtr - 1) / 2) / (rtr - 1);
|
davg = (davg + (rtr - 1) / 2) / (rtr - 1);
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_DEBUG) Dbprintf("rtr=%d isOK=%d min=%d max=%d avg=%d, delta_time=%d", rtr, isOK, dmin, dmax, davg, delta_time);
|
if (g_dbglevel >= DBG_DEBUG) Dbprintf("rtr=%d isOK=%d min=%d max=%d avg=%d, delta_time=%d", rtr, isOK, dmin, dmax, davg, delta_time);
|
||||||
|
|
||||||
dmin = davg - 2;
|
dmin = davg - 2;
|
||||||
dmax = davg + 2;
|
dmax = davg + 2;
|
||||||
|
@ -1041,18 +1041,18 @@ void MifareNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo, uint8
|
||||||
|
|
||||||
// prepare next select. No need to power down the card.
|
// prepare next select. No need to power down the card.
|
||||||
if (mifare_classic_halt(pcs, cuid)) {
|
if (mifare_classic_halt(pcs, cuid)) {
|
||||||
if (DBGLEVEL >= DBG_INFO) Dbprintf("Nested: Halt error");
|
if (g_dbglevel >= DBG_INFO) Dbprintf("Nested: Halt error");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
||||||
if (DBGLEVEL >= DBG_INFO) Dbprintf("Nested: Can't select card");
|
if (g_dbglevel >= DBG_INFO) Dbprintf("Nested: Can't select card");
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
auth1_time = 0;
|
auth1_time = 0;
|
||||||
if (mifare_classic_authex(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST, &nt1, &auth1_time)) {
|
if (mifare_classic_authex(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST, &nt1, &auth1_time)) {
|
||||||
if (DBGLEVEL >= DBG_INFO) Dbprintf("Nested: Auth1 error");
|
if (g_dbglevel >= DBG_INFO) Dbprintf("Nested: Auth1 error");
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1061,12 +1061,12 @@ void MifareNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo, uint8
|
||||||
|
|
||||||
len = mifare_sendcmd_short(pcs, AUTH_NESTED, 0x60 + (targetKeyType & 0x01), targetBlockNo, receivedAnswer, par, &auth2_time);
|
len = mifare_sendcmd_short(pcs, AUTH_NESTED, 0x60 + (targetKeyType & 0x01), targetBlockNo, receivedAnswer, par, &auth2_time);
|
||||||
if (len != 4) {
|
if (len != 4) {
|
||||||
if (DBGLEVEL >= DBG_INFO) Dbprintf("Nested: Auth2 error len=%d", len);
|
if (g_dbglevel >= DBG_INFO) Dbprintf("Nested: Auth2 error len=%d", len);
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
nt2 = bytes_to_num(receivedAnswer, 4);
|
nt2 = bytes_to_num(receivedAnswer, 4);
|
||||||
if (DBGLEVEL >= DBG_DEBUG) Dbprintf("Nonce#%d: Testing nt1=%08x nt2enc=%08x nt2par=%02x", i + 1, nt1, nt2, par[0]);
|
if (g_dbglevel >= DBG_DEBUG) Dbprintf("Nonce#%d: Testing nt1=%08x nt2enc=%08x nt2par=%02x", i + 1, nt1, nt2, par[0]);
|
||||||
|
|
||||||
// Parity validity check
|
// Parity validity check
|
||||||
for (j = 0; j < 4; j++) {
|
for (j = 0; j < 4; j++) {
|
||||||
|
@ -1081,7 +1081,7 @@ void MifareNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo, uint8
|
||||||
|
|
||||||
if (valid_nonce(nttest, nt2, ks1, par_array)) {
|
if (valid_nonce(nttest, nt2, ks1, par_array)) {
|
||||||
if (ncount > 0) { // we are only interested in disambiguous nonces, try again
|
if (ncount > 0) { // we are only interested in disambiguous nonces, try again
|
||||||
if (DBGLEVEL >= DBG_DEBUG) Dbprintf("Nonce#%d: dismissed (ambiguous), ntdist=%d", i + 1, j);
|
if (g_dbglevel >= DBG_DEBUG) Dbprintf("Nonce#%d: dismissed (ambiguous), ntdist=%d", i + 1, j);
|
||||||
target_nt[i] = 0;
|
target_nt[i] = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1090,13 +1090,13 @@ void MifareNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo, uint8
|
||||||
ncount++;
|
ncount++;
|
||||||
if (i == 1 && target_nt[1] == target_nt[0]) { // we need two different nonces
|
if (i == 1 && target_nt[1] == target_nt[0]) { // we need two different nonces
|
||||||
target_nt[i] = 0;
|
target_nt[i] = 0;
|
||||||
if (DBGLEVEL >= DBG_DEBUG) Dbprintf("Nonce#2: dismissed (= nonce#1), ntdist=%d", j);
|
if (g_dbglevel >= DBG_DEBUG) Dbprintf("Nonce#2: dismissed (= nonce#1), ntdist=%d", j);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (DBGLEVEL >= DBG_DEBUG) Dbprintf("Nonce#%d: valid, ntdist=%d", i + 1, j);
|
if (g_dbglevel >= DBG_DEBUG) Dbprintf("Nonce#%d: valid, ntdist=%d", i + 1, j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (target_nt[i] == 0 && j == dmax + 1 && DBGLEVEL >= 3) Dbprintf("Nonce#%d: dismissed (all invalid)", i + 1);
|
if (target_nt[i] == 0 && j == dmax + 1 && g_dbglevel >= 3) Dbprintf("Nonce#%d: dismissed (all invalid)", i + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1165,20 +1165,20 @@ void MifareStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo,
|
||||||
|
|
||||||
// prepare next select. No need to power down the card.
|
// prepare next select. No need to power down the card.
|
||||||
if (mifare_classic_halt(pcs, cuid)) {
|
if (mifare_classic_halt(pcs, cuid)) {
|
||||||
if (DBGLEVEL >= DBG_INFO) Dbprintf("Nested: Halt error");
|
if (g_dbglevel >= DBG_INFO) Dbprintf("Nested: Halt error");
|
||||||
retry--;
|
retry--;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
||||||
if (DBGLEVEL >= DBG_INFO) Dbprintf("Nested: Can't select card");
|
if (g_dbglevel >= DBG_INFO) Dbprintf("Nested: Can't select card");
|
||||||
retry--;
|
retry--;
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
// First authentication. Normal auth.
|
// First authentication. Normal auth.
|
||||||
if (mifare_classic_authex(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST, &nt1, NULL)) {
|
if (mifare_classic_authex(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST, &nt1, NULL)) {
|
||||||
if (DBGLEVEL >= DBG_INFO) Dbprintf("Nested: Auth1 error");
|
if (g_dbglevel >= DBG_INFO) Dbprintf("Nested: Auth1 error");
|
||||||
retry--;
|
retry--;
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
@ -1186,7 +1186,7 @@ void MifareStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo,
|
||||||
// second authentication. Nested auth
|
// second authentication. Nested auth
|
||||||
len = mifare_sendcmd_short(pcs, AUTH_NESTED, 0x60 + (targetKeyType & 0x01), targetBlockNo, receivedAnswer, par, NULL);
|
len = mifare_sendcmd_short(pcs, AUTH_NESTED, 0x60 + (targetKeyType & 0x01), targetBlockNo, receivedAnswer, par, NULL);
|
||||||
if (len != 4) {
|
if (len != 4) {
|
||||||
if (DBGLEVEL >= DBG_INFO) Dbprintf("Nested: Auth2 error len=%d", len);
|
if (g_dbglevel >= DBG_INFO) Dbprintf("Nested: Auth2 error len=%d", len);
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1195,7 +1195,7 @@ void MifareStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo,
|
||||||
target_ks = nt2 ^ target_nt;
|
target_ks = nt2 ^ target_nt;
|
||||||
isOK = 1;
|
isOK = 1;
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_DEBUG) Dbprintf("Testing nt1=%08x nt2enc=%08x nt2par=%02x ks=%08x", nt1, nt2, par[0], target_ks);
|
if (g_dbglevel >= DBG_DEBUG) Dbprintf("Testing nt1=%08x nt2enc=%08x nt2par=%02x ks=%08x", nt1, nt2, par[0], target_ks);
|
||||||
}
|
}
|
||||||
|
|
||||||
LED_C_OFF();
|
LED_C_OFF();
|
||||||
|
@ -1311,7 +1311,7 @@ static void chkKey_scanA(struct chk_t *c, struct sector_t *k_sector, uint8_t *fo
|
||||||
found[(s * 2)] = 1;
|
found[(s * 2)] = 1;
|
||||||
++*foundkeys;
|
++*foundkeys;
|
||||||
|
|
||||||
if (DBGLEVEL >= 3) Dbprintf("ChkKeys_fast: Scan A found (%d)", c->block);
|
if (g_dbglevel >= 3) Dbprintf("ChkKeys_fast: Scan A found (%d)", c->block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1329,7 +1329,7 @@ static void chkKey_scanB(struct chk_t *c, struct sector_t *k_sector, uint8_t *fo
|
||||||
found[(s * 2) + 1] = 1;
|
found[(s * 2) + 1] = 1;
|
||||||
++*foundkeys;
|
++*foundkeys;
|
||||||
|
|
||||||
if (DBGLEVEL >= 3) Dbprintf("ChkKeys_fast: Scan B found (%d)", c->block);
|
if (g_dbglevel >= 3) Dbprintf("ChkKeys_fast: Scan B found (%d)", c->block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1354,7 +1354,7 @@ static void chkKey_loopBonly(struct chk_t *c, struct sector_t *k_sector, uint8_t
|
||||||
found[(s * 2) + 1] = 1;
|
found[(s * 2) + 1] = 1;
|
||||||
++*foundkeys;
|
++*foundkeys;
|
||||||
|
|
||||||
if (DBGLEVEL >= 3) Dbprintf("ChkKeys_fast: Reading B found (%d)", c->block);
|
if (g_dbglevel >= 3) Dbprintf("ChkKeys_fast: Reading B found (%d)", c->block);
|
||||||
|
|
||||||
// try quick find all B?
|
// try quick find all B?
|
||||||
// assume: keys comes in groups. Find one B, test against all B.
|
// assume: keys comes in groups. Find one B, test against all B.
|
||||||
|
@ -1397,7 +1397,7 @@ void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *da
|
||||||
static uint8_t found[80];
|
static uint8_t found[80];
|
||||||
static uint8_t *uid;
|
static uint8_t *uid;
|
||||||
|
|
||||||
int oldbg = DBGLEVEL;
|
int oldbg = g_dbglevel;
|
||||||
|
|
||||||
#ifdef WITH_FLASH
|
#ifdef WITH_FLASH
|
||||||
if (use_flashmem) {
|
if (use_flashmem) {
|
||||||
|
@ -1451,7 +1451,7 @@ void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *da
|
||||||
|
|
||||||
iso14a_card_select_t card_info;
|
iso14a_card_select_t card_info;
|
||||||
if (!iso14443a_select_card(uid, &card_info, &cuid, true, 0, true)) {
|
if (!iso14443a_select_card(uid, &card_info, &cuid, true, 0, true)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("ChkKeys_fast: Can't select card (ALL)");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("ChkKeys_fast: Can't select card (ALL)");
|
||||||
goto OUT;
|
goto OUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1473,7 +1473,7 @@ void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *da
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear debug level. We are expecting lots of authentication failures...
|
// clear debug level. We are expecting lots of authentication failures...
|
||||||
DBGLEVEL = DBG_NONE;
|
g_dbglevel = DBG_NONE;
|
||||||
|
|
||||||
// set check struct.
|
// set check struct.
|
||||||
chk_data.uid = uid;
|
chk_data.uid = uid;
|
||||||
|
@ -1709,7 +1709,7 @@ OUT:
|
||||||
reply_mix(CMD_ACK, foundkeys, 0, 0, 0, 0);
|
reply_mix(CMD_ACK, foundkeys, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
DBGLEVEL = oldbg;
|
g_dbglevel = oldbg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MifareChkKeys(uint8_t *datain, uint8_t reserved_mem) {
|
void MifareChkKeys(uint8_t *datain, uint8_t reserved_mem) {
|
||||||
|
@ -1756,8 +1756,8 @@ void MifareChkKeys(uint8_t *datain, uint8_t reserved_mem) {
|
||||||
if (clearTrace)
|
if (clearTrace)
|
||||||
clear_trace();
|
clear_trace();
|
||||||
|
|
||||||
int oldbg = DBGLEVEL;
|
int oldbg = g_dbglevel;
|
||||||
DBGLEVEL = DBG_NONE;
|
g_dbglevel = DBG_NONE;
|
||||||
|
|
||||||
set_tracing(false);
|
set_tracing(false);
|
||||||
|
|
||||||
|
@ -1767,7 +1767,7 @@ void MifareChkKeys(uint8_t *datain, uint8_t reserved_mem) {
|
||||||
if (!have_uid) { // need a full select cycle to get the uid first
|
if (!have_uid) { // need a full select cycle to get the uid first
|
||||||
iso14a_card_select_t card_info;
|
iso14a_card_select_t card_info;
|
||||||
if (!iso14443a_select_card(uid, &card_info, &cuid, true, 0, true)) {
|
if (!iso14443a_select_card(uid, &card_info, &cuid, true, 0, true)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("ChkKeys: Can't select card (ALL)");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("ChkKeys: Can't select card (ALL)");
|
||||||
--i; // try same key once again
|
--i; // try same key once again
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1787,7 +1787,7 @@ void MifareChkKeys(uint8_t *datain, uint8_t reserved_mem) {
|
||||||
have_uid = true;
|
have_uid = true;
|
||||||
} else { // no need for anticollision. We can directly select the card
|
} else { // no need for anticollision. We can directly select the card
|
||||||
if (!iso14443a_select_card(uid, NULL, NULL, false, cascade_levels, true)) {
|
if (!iso14443a_select_card(uid, NULL, NULL, false, cascade_levels, true)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("ChkKeys: Can't select card (UID)");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("ChkKeys: Can't select card (UID)");
|
||||||
--i; // try same key once again
|
--i; // try same key once again
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1815,7 +1815,7 @@ void MifareChkKeys(uint8_t *datain, uint8_t reserved_mem) {
|
||||||
set_tracing(false);
|
set_tracing(false);
|
||||||
crypto1_deinit(pcs);
|
crypto1_deinit(pcs);
|
||||||
|
|
||||||
DBGLEVEL = oldbg;
|
g_dbglevel = oldbg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MifareChkKeys_file(uint8_t *fn) {
|
void MifareChkKeys_file(uint8_t *fn) {
|
||||||
|
@ -1863,13 +1863,13 @@ void MifarePersonalizeUID(uint8_t keyType, uint8_t perso_option, uint64_t key) {
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Can't select card");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t block_number = 0;
|
uint8_t block_number = 0;
|
||||||
if (mifare_classic_auth(pcs, cuid, block_number, keyType, key, AUTH_FIRST)) {
|
if (mifare_classic_auth(pcs, cuid, block_number, keyType, key, AUTH_FIRST)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Auth error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Auth error");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1877,12 +1877,12 @@ void MifarePersonalizeUID(uint8_t keyType, uint8_t perso_option, uint64_t key) {
|
||||||
uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE];
|
uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE];
|
||||||
int len = mifare_sendcmd_short(pcs, true, MIFARE_EV1_PERSONAL_UID, perso_option, receivedAnswer, receivedAnswerPar, NULL);
|
int len = mifare_sendcmd_short(pcs, true, MIFARE_EV1_PERSONAL_UID, perso_option, receivedAnswer, receivedAnswerPar, NULL);
|
||||||
if (len != 1 || receivedAnswer[0] != CARD_ACK) {
|
if (len != 1 || receivedAnswer[0] != CARD_ACK) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd Error: %02x", receivedAnswer[0]);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Cmd Error: %02x", receivedAnswer[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mifare_classic_halt(pcs, cuid)) {
|
if (mifare_classic_halt(pcs, cuid)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Halt error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Halt error");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
isOK = PM3_SUCCESS;
|
isOK = PM3_SUCCESS;
|
||||||
|
@ -1974,7 +1974,7 @@ int MifareECardLoad(uint8_t sectorcnt, uint8_t keytype) {
|
||||||
|
|
||||||
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
||||||
retval = PM3_ESOFT;
|
retval = PM3_ESOFT;
|
||||||
if (DBGLEVEL > DBG_ERROR) Dbprintf("Can't select card");
|
if (g_dbglevel > DBG_ERROR) Dbprintf("Can't select card");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1983,13 +1983,13 @@ int MifareECardLoad(uint8_t sectorcnt, uint8_t keytype) {
|
||||||
if (sectorNo == 0) {
|
if (sectorNo == 0) {
|
||||||
if (mifare_classic_auth(pcs, cuid, FirstBlockOfSector(sectorNo), keytype, ui64Key, AUTH_FIRST)) {
|
if (mifare_classic_auth(pcs, cuid, FirstBlockOfSector(sectorNo), keytype, ui64Key, AUTH_FIRST)) {
|
||||||
retval = PM3_EPARTIAL;
|
retval = PM3_EPARTIAL;
|
||||||
if (DBGLEVEL > DBG_ERROR) Dbprintf("Sector[%2d]. Auth error", sectorNo);
|
if (g_dbglevel > DBG_ERROR) Dbprintf("Sector[%2d]. Auth error", sectorNo);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (mifare_classic_auth(pcs, cuid, FirstBlockOfSector(sectorNo), keytype, ui64Key, AUTH_NESTED)) {
|
if (mifare_classic_auth(pcs, cuid, FirstBlockOfSector(sectorNo), keytype, ui64Key, AUTH_NESTED)) {
|
||||||
retval = PM3_EPARTIAL;
|
retval = PM3_EPARTIAL;
|
||||||
if (DBGLEVEL > DBG_ERROR) Dbprintf("Sector[%2d]. Auth nested error", sectorNo);
|
if (g_dbglevel > DBG_ERROR) Dbprintf("Sector[%2d]. Auth nested error", sectorNo);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1998,7 +1998,7 @@ int MifareECardLoad(uint8_t sectorcnt, uint8_t keytype) {
|
||||||
if (mifare_classic_readblock(pcs, cuid, FirstBlockOfSector(sectorNo) + blockNo, dataoutbuf)) {
|
if (mifare_classic_readblock(pcs, cuid, FirstBlockOfSector(sectorNo) + blockNo, dataoutbuf)) {
|
||||||
retval = PM3_EPARTIAL;
|
retval = PM3_EPARTIAL;
|
||||||
|
|
||||||
if (DBGLEVEL > DBG_ERROR) Dbprintf("Error reading sector %2d block %2d", sectorNo, blockNo);
|
if (g_dbglevel > DBG_ERROR) Dbprintf("Error reading sector %2d block %2d", sectorNo, blockNo);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2019,7 +2019,7 @@ int MifareECardLoad(uint8_t sectorcnt, uint8_t keytype) {
|
||||||
int res = mifare_classic_halt(pcs, cuid);
|
int res = mifare_classic_halt(pcs, cuid);
|
||||||
(void)res;
|
(void)res;
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_INFO) DbpString("Emulator fill sectors finished");
|
if (g_dbglevel >= DBG_INFO) DbpString("Emulator fill sectors finished");
|
||||||
|
|
||||||
out:
|
out:
|
||||||
crypto1_deinit(pcs);
|
crypto1_deinit(pcs);
|
||||||
|
@ -2079,7 +2079,7 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) {
|
||||||
// read UID and return to client with write
|
// read UID and return to client with write
|
||||||
if (workFlags & MAGIC_UID) {
|
if (workFlags & MAGIC_UID) {
|
||||||
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Can't select card");
|
||||||
errormsg = MAGIC_UID;
|
errormsg = MAGIC_UID;
|
||||||
mifare_classic_halt_ex(NULL);
|
mifare_classic_halt_ex(NULL);
|
||||||
break;
|
break;
|
||||||
|
@ -2091,7 +2091,7 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) {
|
||||||
if (workFlags & MAGIC_WIPE) {
|
if (workFlags & MAGIC_WIPE) {
|
||||||
ReaderTransmitBitsPar(wupC1, 7, NULL, NULL);
|
ReaderTransmitBitsPar(wupC1, 7, NULL, NULL);
|
||||||
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
|
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("wupC1 error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("wupC1 error");
|
||||||
errormsg = MAGIC_WIPE;
|
errormsg = MAGIC_WIPE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2104,7 +2104,7 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) {
|
||||||
|
|
||||||
ReaderTransmit(wipeC, sizeof(wipeC), NULL);
|
ReaderTransmit(wipeC, sizeof(wipeC), NULL);
|
||||||
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
|
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("wipeC error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("wipeC error");
|
||||||
errormsg = MAGIC_WIPE;
|
errormsg = MAGIC_WIPE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2117,7 +2117,7 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) {
|
||||||
if (workFlags & MAGIC_WUPC) {
|
if (workFlags & MAGIC_WUPC) {
|
||||||
ReaderTransmitBitsPar(wupC1, 7, NULL, NULL);
|
ReaderTransmitBitsPar(wupC1, 7, NULL, NULL);
|
||||||
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
|
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("wupC1 error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("wupC1 error");
|
||||||
errormsg = MAGIC_WUPC;
|
errormsg = MAGIC_WUPC;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2125,7 +2125,7 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) {
|
||||||
if (!is1b) {
|
if (!is1b) {
|
||||||
ReaderTransmit(wupC2, sizeof(wupC2), NULL);
|
ReaderTransmit(wupC2, sizeof(wupC2), NULL);
|
||||||
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
|
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
|
||||||
if (DBGLEVEL >= DBG_INFO) Dbprintf("Assuming Magic Gen 1B tag. [wupC2 failed]");
|
if (g_dbglevel >= DBG_INFO) Dbprintf("Assuming Magic Gen 1B tag. [wupC2 failed]");
|
||||||
is1b = true;
|
is1b = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -2133,7 +2133,7 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((mifare_sendcmd_short(NULL, CRYPT_NONE, ISO14443A_CMD_WRITEBLOCK, blockNo, receivedAnswer, receivedAnswerPar, NULL) != 1) || (receivedAnswer[0] != 0x0a)) {
|
if ((mifare_sendcmd_short(NULL, CRYPT_NONE, ISO14443A_CMD_WRITEBLOCK, blockNo, receivedAnswer, receivedAnswerPar, NULL) != 1) || (receivedAnswer[0] != 0x0a)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("write block send command error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("write block send command error");
|
||||||
errormsg = 4;
|
errormsg = 4;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2143,7 +2143,7 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) {
|
||||||
|
|
||||||
ReaderTransmit(data, sizeof(data), NULL);
|
ReaderTransmit(data, sizeof(data), NULL);
|
||||||
if ((ReaderReceive(receivedAnswer, receivedAnswerPar) != 1) || (receivedAnswer[0] != 0x0a)) {
|
if ((ReaderReceive(receivedAnswer, receivedAnswerPar) != 1) || (receivedAnswer[0] != 0x0a)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("write block send data error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("write block send data error");
|
||||||
errormsg = 0;
|
errormsg = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2195,7 +2195,7 @@ void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) {
|
||||||
if (workFlags & MAGIC_WUPC) {
|
if (workFlags & MAGIC_WUPC) {
|
||||||
ReaderTransmitBitsPar(wupC1, 7, NULL, NULL);
|
ReaderTransmitBitsPar(wupC1, 7, NULL, NULL);
|
||||||
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
|
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("wupC1 error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("wupC1 error");
|
||||||
errormsg = MAGIC_WUPC;
|
errormsg = MAGIC_WUPC;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2203,7 +2203,7 @@ void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) {
|
||||||
if (!is1b) {
|
if (!is1b) {
|
||||||
ReaderTransmit(wupC2, sizeof(wupC2), NULL);
|
ReaderTransmit(wupC2, sizeof(wupC2), NULL);
|
||||||
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
|
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
|
||||||
if (DBGLEVEL >= DBG_INFO) Dbprintf("Assuming Magic Gen 1B tag. [wupC2 failed]");
|
if (g_dbglevel >= DBG_INFO) Dbprintf("Assuming Magic Gen 1B tag. [wupC2 failed]");
|
||||||
is1b = true;
|
is1b = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -2212,7 +2212,7 @@ void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) {
|
||||||
|
|
||||||
// read block
|
// read block
|
||||||
if ((mifare_sendcmd_short(NULL, CRYPT_NONE, ISO14443A_CMD_READBLOCK, blockNo, receivedAnswer, receivedAnswerPar, NULL) != 18)) {
|
if ((mifare_sendcmd_short(NULL, CRYPT_NONE, ISO14443A_CMD_READBLOCK, blockNo, receivedAnswer, receivedAnswerPar, NULL) != 18)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("read block send command error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("read block send command error");
|
||||||
errormsg = 0;
|
errormsg = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2465,7 +2465,7 @@ int DoGen3Cmd(uint8_t *cmd, uint8_t cmd_len) {
|
||||||
// timeout for card memory reset
|
// timeout for card memory reset
|
||||||
SpinDelay(1000);
|
SpinDelay(1000);
|
||||||
} else {
|
} else {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Card operation not completed");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Card operation not completed");
|
||||||
retval = PM3_ESOFT;
|
retval = PM3_ESOFT;
|
||||||
}
|
}
|
||||||
iso14a_set_timeout(save_iso14a_timeout);
|
iso14a_set_timeout(save_iso14a_timeout);
|
||||||
|
@ -2490,7 +2490,7 @@ void MifareGen3UID(uint8_t uidlen, uint8_t *uid) {
|
||||||
goto OUT;
|
goto OUT;
|
||||||
}
|
}
|
||||||
if (card_info->uidlen != uidlen) {
|
if (card_info->uidlen != uidlen) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Wrong UID length");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Wrong UID length");
|
||||||
retval = PM3_ESOFT;
|
retval = PM3_ESOFT;
|
||||||
goto OUT;
|
goto OUT;
|
||||||
}
|
}
|
||||||
|
@ -2528,7 +2528,7 @@ void MifareGen3Blk(uint8_t block_len, uint8_t *block) {
|
||||||
bool doReselect = false;
|
bool doReselect = false;
|
||||||
if (block_len < MIFARE_BLOCK_SIZE) {
|
if (block_len < MIFARE_BLOCK_SIZE) {
|
||||||
if ((mifare_sendcmd_short(NULL, CRYPT_NONE, ISO14443A_CMD_READBLOCK, 0, &cmd[sizeof(block_cmd)], NULL, NULL) != MAX_MIFARE_FRAME_SIZE)) {
|
if ((mifare_sendcmd_short(NULL, CRYPT_NONE, ISO14443A_CMD_READBLOCK, 0, &cmd[sizeof(block_cmd)], NULL, NULL) != MAX_MIFARE_FRAME_SIZE)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Read manufacturer block failed");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Read manufacturer block failed");
|
||||||
retval = PM3_ESOFT;
|
retval = PM3_ESOFT;
|
||||||
goto OUT;
|
goto OUT;
|
||||||
}
|
}
|
||||||
|
@ -2545,7 +2545,7 @@ void MifareGen3Blk(uint8_t block_len, uint8_t *block) {
|
||||||
} else if (card_info->uidlen == 7) {
|
} else if (card_info->uidlen == 7) {
|
||||||
ofs += 7;
|
ofs += 7;
|
||||||
} else {
|
} else {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Wrong Card UID length");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Wrong Card UID length");
|
||||||
retval = PM3_ESOFT;
|
retval = PM3_ESOFT;
|
||||||
goto OUT;
|
goto OUT;
|
||||||
}
|
}
|
||||||
|
@ -2655,23 +2655,23 @@ void MifareSetMod(uint8_t *datain) {
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Can't select card");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mifare_classic_auth(pcs, cuid, 0, 0, ui64Key, AUTH_FIRST)) {
|
if (mifare_classic_auth(pcs, cuid, 0, 0, ui64Key, AUTH_FIRST)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Auth error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Auth error");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int respLen;
|
int respLen;
|
||||||
if (((respLen = mifare_sendcmd_short(pcs, CRYPT_ALL, 0x43, mod, receivedAnswer, receivedAnswerPar, NULL)) != 1) || (receivedAnswer[0] != 0x0a)) {
|
if (((respLen = mifare_sendcmd_short(pcs, CRYPT_ALL, 0x43, mod, receivedAnswer, receivedAnswerPar, NULL)) != 1) || (receivedAnswer[0] != 0x0a)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("SetMod error; response[0]: %hhX, len: %d", receivedAnswer[0], respLen);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("SetMod error; response[0]: %hhX, len: %d", receivedAnswer[0], respLen);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mifare_classic_halt(pcs, cuid)) {
|
if (mifare_classic_halt(pcs, cuid)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Halt error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Halt error");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2703,18 +2703,18 @@ void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain) {
|
||||||
|
|
||||||
int len = iso14443a_select_card(uid, NULL, &cuid, true, 0, false);
|
int len = iso14443a_select_card(uid, NULL, &cuid, true, 0, false);
|
||||||
if (!len) {
|
if (!len) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Can't select card");
|
||||||
OnError(1);
|
OnError(1);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (mifare_desfire_des_auth1(cuid, dataout)) {
|
if (mifare_desfire_des_auth1(cuid, dataout)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Authentication part1: Fail.");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Authentication part1: Fail.");
|
||||||
OnError(4);
|
OnError(4);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) DbpString("AUTH 1 FINISHED");
|
if (g_dbglevel >= DBG_EXTENDED) DbpString("AUTH 1 FINISHED");
|
||||||
reply_mix(CMD_ACK, 1, cuid, 0, dataout, sizeof(dataout));
|
reply_mix(CMD_ACK, 1, cuid, 0, dataout, sizeof(dataout));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2729,12 +2729,12 @@ void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain) {
|
||||||
isOK = mifare_desfire_des_auth2(cuid, key, dataout);
|
isOK = mifare_desfire_des_auth2(cuid, key, dataout);
|
||||||
|
|
||||||
if (isOK) {
|
if (isOK) {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("Authentication part2: Failed");
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("Authentication part2: Failed");
|
||||||
OnError(4);
|
OnError(4);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) DbpString("AUTH 2 FINISHED");
|
if (g_dbglevel >= DBG_EXTENDED) DbpString("AUTH 2 FINISHED");
|
||||||
|
|
||||||
reply_old(CMD_ACK, isOK, 0, 0, dataout, sizeof(dataout));
|
reply_old(CMD_ACK, isOK, 0, 0, dataout, sizeof(dataout));
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
|
@ -2748,12 +2748,12 @@ void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain) {
|
||||||
void MifareU_Otp_Tearoff(uint8_t blno, uint32_t tearoff_time, uint8_t *data_testwrite) {
|
void MifareU_Otp_Tearoff(uint8_t blno, uint32_t tearoff_time, uint8_t *data_testwrite) {
|
||||||
uint8_t blockNo = blno;
|
uint8_t blockNo = blno;
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_DEBUG) DbpString("Preparing OTP tear-off");
|
if (g_dbglevel >= DBG_DEBUG) DbpString("Preparing OTP tear-off");
|
||||||
|
|
||||||
if (tearoff_time > 43000)
|
if (tearoff_time > 43000)
|
||||||
tearoff_time = 43000;
|
tearoff_time = 43000;
|
||||||
tearoff_delay_us = tearoff_time;
|
g_tearoff_delay_us = tearoff_time;
|
||||||
tearoff_enabled = true;
|
g_tearoff_enabled = true;
|
||||||
|
|
||||||
LEDsoff();
|
LEDsoff();
|
||||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
||||||
|
@ -2771,7 +2771,7 @@ void MifareU_Otp_Tearoff(uint8_t blno, uint32_t tearoff_time, uint8_t *data_test
|
||||||
|
|
||||||
// anticollision / select card
|
// anticollision / select card
|
||||||
if (!iso14443a_select_card(NULL, NULL, NULL, true, 0, true)) {
|
if (!iso14443a_select_card(NULL, NULL, NULL, true, 0, true)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Can't select card");
|
||||||
OnError(1);
|
OnError(1);
|
||||||
reply_ng(CMD_HF_MFU_OTP_TEAROFF, PM3_EFAILED, NULL, 0);
|
reply_ng(CMD_HF_MFU_OTP_TEAROFF, PM3_EFAILED, NULL, 0);
|
||||||
return;
|
return;
|
||||||
|
@ -2810,7 +2810,7 @@ void MifareU_Counter_Tearoff(uint8_t counter, uint32_t tearoff_time, uint8_t *da
|
||||||
|
|
||||||
// anticollision / select card
|
// anticollision / select card
|
||||||
if (!iso14443a_select_card(NULL, NULL, NULL, true, 0, true)) {
|
if (!iso14443a_select_card(NULL, NULL, NULL, true, 0, true)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Can't select card");
|
||||||
OnError(1);
|
OnError(1);
|
||||||
switch_off();
|
switch_off();
|
||||||
LEDsoff();
|
LEDsoff();
|
||||||
|
|
|
@ -46,7 +46,7 @@ bool InitDesfireCard(void) {
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
|
||||||
if (!iso14443a_select_card(NULL, &card, NULL, true, 0, false)) {
|
if (!iso14443a_select_card(NULL, &card, NULL, true, 0, false)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) DbpString("Can't select card");
|
if (g_dbglevel >= DBG_ERROR) DbpString("Can't select card");
|
||||||
OnError(1);
|
OnError(1);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ void MifareSendCommand(uint8_t *datain) {
|
||||||
uint8_t resp[RECEIVE_SIZE];
|
uint8_t resp[RECEIVE_SIZE];
|
||||||
memset(resp, 0, sizeof(resp));
|
memset(resp, 0, sizeof(resp));
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
Dbprintf(" flags : %02X", payload->flags);
|
Dbprintf(" flags : %02X", payload->flags);
|
||||||
Dbprintf(" len : %02X", payload->datalen);
|
Dbprintf(" len : %02X", payload->datalen);
|
||||||
print_result(" RX : ", payload->datain, payload->datalen);
|
print_result(" RX : ", payload->datain, payload->datalen);
|
||||||
|
@ -85,7 +85,7 @@ void MifareSendCommand(uint8_t *datain) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int len = DesfireAPDU(payload->datain, payload->datalen, resp);
|
int len = DesfireAPDU(payload->datain, payload->datalen, resp);
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
print_result("RESP <--: ", resp, len);
|
print_result("RESP <--: ", resp, len);
|
||||||
|
|
||||||
if (!len) {
|
if (!len) {
|
||||||
|
@ -142,7 +142,7 @@ void MifareDesfireGetInformation(void) {
|
||||||
|
|
||||||
// card select - information
|
// card select - information
|
||||||
if (!iso14443a_select_card(NULL, &card, NULL, true, 0, false)) {
|
if (!iso14443a_select_card(NULL, &card, NULL, true, 0, false)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) DbpString("Can't select card");
|
if (g_dbglevel >= DBG_ERROR) DbpString("Can't select card");
|
||||||
payload.isOK = 1; // 2 == can not select
|
payload.isOK = 1; // 2 == can not select
|
||||||
reply_ng(CMD_HF_DESFIRE_INFO, PM3_ESOFT, (uint8_t *)&payload, sizeof(payload));
|
reply_ng(CMD_HF_DESFIRE_INFO, PM3_ESOFT, (uint8_t *)&payload, sizeof(payload));
|
||||||
switch_off();
|
switch_off();
|
||||||
|
@ -317,7 +317,7 @@ void MifareDES_Auth1(uint8_t *datain) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!len) {
|
if (!len) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) {
|
if (g_dbglevel >= DBG_ERROR) {
|
||||||
DbpString("Authentication failed. Card timeout.");
|
DbpString("Authentication failed. Card timeout.");
|
||||||
}
|
}
|
||||||
OnErrorNG(CMD_HF_DESFIRE_AUTH1, 3);
|
OnErrorNG(CMD_HF_DESFIRE_AUTH1, 3);
|
||||||
|
@ -343,7 +343,7 @@ void MifareDES_Auth1(uint8_t *datain) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len != expectedlen) {
|
if (len != expectedlen) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) {
|
if (g_dbglevel >= DBG_ERROR) {
|
||||||
DbpString("Authentication failed. Length of answer doesn't match algo.");
|
DbpString("Authentication failed. Length of answer doesn't match algo.");
|
||||||
print_result("Res-Buffer: ", resp, len);
|
print_result("Res-Buffer: ", resp, len);
|
||||||
}
|
}
|
||||||
|
@ -361,7 +361,7 @@ void MifareDES_Auth1(uint8_t *datain) {
|
||||||
// Part 3
|
// Part 3
|
||||||
if (payload->algo == MFDES_ALGO_AES) {
|
if (payload->algo == MFDES_ALGO_AES) {
|
||||||
if (mbedtls_aes_setkey_dec(&ctx, key->data, 128) != 0) {
|
if (mbedtls_aes_setkey_dec(&ctx, key->data, 128) != 0) {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
DbpString("mbedtls_aes_setkey_dec failed");
|
DbpString("mbedtls_aes_setkey_dec failed");
|
||||||
}
|
}
|
||||||
OnErrorNG(CMD_HF_DESFIRE_AUTH1, 7);
|
OnErrorNG(CMD_HF_DESFIRE_AUTH1, 7);
|
||||||
|
@ -410,7 +410,7 @@ void MifareDES_Auth1(uint8_t *datain) {
|
||||||
memcpy(tmp + 16, rotRndB, rndlen);
|
memcpy(tmp + 16, rotRndB, rndlen);
|
||||||
if (payload->algo == MFDES_ALGO_AES) {
|
if (payload->algo == MFDES_ALGO_AES) {
|
||||||
if (mbedtls_aes_setkey_enc(&ctx, key->data, 128) != 0) {
|
if (mbedtls_aes_setkey_enc(&ctx, key->data, 128) != 0) {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
DbpString("mbedtls_aes_setkey_enc failed");
|
DbpString("mbedtls_aes_setkey_enc failed");
|
||||||
}
|
}
|
||||||
OnErrorNG(CMD_HF_DESFIRE_AUTH1, 7);
|
OnErrorNG(CMD_HF_DESFIRE_AUTH1, 7);
|
||||||
|
@ -440,7 +440,7 @@ void MifareDES_Auth1(uint8_t *datain) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!len) {
|
if (!len) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) {
|
if (g_dbglevel >= DBG_ERROR) {
|
||||||
DbpString("Authentication failed. Card timeout.");
|
DbpString("Authentication failed. Card timeout.");
|
||||||
}
|
}
|
||||||
OnErrorNG(CMD_HF_DESFIRE_AUTH1, 3);
|
OnErrorNG(CMD_HF_DESFIRE_AUTH1, 3);
|
||||||
|
@ -465,7 +465,7 @@ void MifareDES_Auth1(uint8_t *datain) {
|
||||||
|
|
||||||
Desfire_session_key_new(RndA, RndB, key, sessionkey);
|
Desfire_session_key_new(RndA, RndB, key, sessionkey);
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
print_result("SESSIONKEY : ", sessionkey->data, payload->keylen);
|
print_result("SESSIONKEY : ", sessionkey->data, payload->keylen);
|
||||||
|
|
||||||
if (payload->mode != MFDES_AUTH_PICC) {
|
if (payload->mode != MFDES_AUTH_PICC) {
|
||||||
|
@ -483,7 +483,7 @@ void MifareDES_Auth1(uint8_t *datain) {
|
||||||
tdes_nxp_receive(encRndA, encRndA, rndlen, key->data, IV, 3);
|
tdes_nxp_receive(encRndA, encRndA, rndlen, key->data, IV, 3);
|
||||||
} else if (payload->mode == MFDES_AUTH_AES) {
|
} else if (payload->mode == MFDES_AUTH_AES) {
|
||||||
if (mbedtls_aes_setkey_dec(&ctx, key->data, 128) != 0) {
|
if (mbedtls_aes_setkey_dec(&ctx, key->data, 128) != 0) {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
DbpString("mbedtls_aes_setkey_dec failed");
|
DbpString("mbedtls_aes_setkey_dec failed");
|
||||||
}
|
}
|
||||||
OnErrorNG(CMD_HF_DESFIRE_AUTH1, 7);
|
OnErrorNG(CMD_HF_DESFIRE_AUTH1, 7);
|
||||||
|
@ -493,7 +493,7 @@ void MifareDES_Auth1(uint8_t *datain) {
|
||||||
}
|
}
|
||||||
|
|
||||||
rol(RndA, rndlen);
|
rol(RndA, rndlen);
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
print_result("RndA : ", RndA, rndlen);
|
print_result("RndA : ", RndA, rndlen);
|
||||||
print_result("RndB: ", RndB, rndlen);
|
print_result("RndB: ", RndB, rndlen);
|
||||||
print_result("encRndA : ", encRndA, rndlen);
|
print_result("encRndA : ", encRndA, rndlen);
|
||||||
|
@ -623,14 +623,14 @@ int DesfireAPDU(uint8_t *cmd, size_t cmd_len, uint8_t *dataout) {
|
||||||
|
|
||||||
wrappedLen = CreateAPDU(cmd, cmd_len, wCmd);
|
wrappedLen = CreateAPDU(cmd, cmd_len, wCmd);
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
print_result("WCMD <--: ", wCmd, wrappedLen);
|
print_result("WCMD <--: ", wCmd, wrappedLen);
|
||||||
|
|
||||||
ReaderTransmit(wCmd, wrappedLen, NULL);
|
ReaderTransmit(wCmd, wrappedLen, NULL);
|
||||||
|
|
||||||
len = ReaderReceive(resp, par);
|
len = ReaderReceive(resp, par);
|
||||||
if (!len) {
|
if (!len) {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("fukked");
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("fukked");
|
||||||
return false; //DATA LINK ERROR
|
return false; //DATA LINK ERROR
|
||||||
}
|
}
|
||||||
// if we received an I- or R(ACK)-Block with a block number equal to the
|
// if we received an I- or R(ACK)-Block with a block number equal to the
|
||||||
|
@ -657,7 +657,7 @@ size_t CreateAPDU(uint8_t *datain, size_t len, uint8_t *dataout) {
|
||||||
cmd[0] = 0x02; // 0x0A = send cid, 0x02 = no cid.
|
cmd[0] = 0x02; // 0x0A = send cid, 0x02 = no cid.
|
||||||
cmd[0] |= pcb_blocknum; // OR the block number into the PCB
|
cmd[0] |= pcb_blocknum; // OR the block number into the PCB
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("pcb_blocknum %d == %d ", pcb_blocknum, cmd[0]);
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("pcb_blocknum %d == %d ", pcb_blocknum, cmd[0]);
|
||||||
|
|
||||||
//cmd[1] = 0x90; // CID: 0x00 //TODO: allow multiple selected cards
|
//cmd[1] = 0x90; // CID: 0x00 //TODO: allow multiple selected cards
|
||||||
|
|
||||||
|
@ -682,7 +682,7 @@ void OnSuccess(void) {
|
||||||
pcb_blocknum = 0;
|
pcb_blocknum = 0;
|
||||||
ReaderTransmit(deselect_cmd, 3, NULL);
|
ReaderTransmit(deselect_cmd, 3, NULL);
|
||||||
if (mifare_ultra_halt()) {
|
if (mifare_ultra_halt()) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Halt error");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Halt error");
|
||||||
}
|
}
|
||||||
switch_off();
|
switch_off();
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,35 +47,35 @@ static bool IsTrailerAccessAllowed(uint8_t blockNo, uint8_t keytype, uint8_t act
|
||||||
| ((sector_trailer[8] >> 7) & 0x01);
|
| ((sector_trailer[8] >> 7) & 0x01);
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case AC_KEYA_READ: {
|
case AC_KEYA_READ: {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("IsTrailerAccessAllowed: AC_KEYA_READ");
|
Dbprintf("IsTrailerAccessAllowed: AC_KEYA_READ");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
case AC_KEYA_WRITE: {
|
case AC_KEYA_WRITE: {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("IsTrailerAccessAllowed: AC_KEYA_WRITE");
|
Dbprintf("IsTrailerAccessAllowed: AC_KEYA_WRITE");
|
||||||
return ((keytype == AUTHKEYA && (AC == 0x00 || AC == 0x01))
|
return ((keytype == AUTHKEYA && (AC == 0x00 || AC == 0x01))
|
||||||
|| (keytype == AUTHKEYB && (AC == 0x04 || AC == 0x03)));
|
|| (keytype == AUTHKEYB && (AC == 0x04 || AC == 0x03)));
|
||||||
}
|
}
|
||||||
case AC_KEYB_READ: {
|
case AC_KEYB_READ: {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("IsTrailerAccessAllowed: AC_KEYB_READ");
|
Dbprintf("IsTrailerAccessAllowed: AC_KEYB_READ");
|
||||||
return (keytype == AUTHKEYA && (AC == 0x00 || AC == 0x02 || AC == 0x01));
|
return (keytype == AUTHKEYA && (AC == 0x00 || AC == 0x02 || AC == 0x01));
|
||||||
}
|
}
|
||||||
case AC_KEYB_WRITE: {
|
case AC_KEYB_WRITE: {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("IsTrailerAccessAllowed: AC_KEYB_WRITE");
|
Dbprintf("IsTrailerAccessAllowed: AC_KEYB_WRITE");
|
||||||
return ((keytype == AUTHKEYA && (AC == 0x00 || AC == 0x01))
|
return ((keytype == AUTHKEYA && (AC == 0x00 || AC == 0x01))
|
||||||
|| (keytype == AUTHKEYB && (AC == 0x04 || AC == 0x03)));
|
|| (keytype == AUTHKEYB && (AC == 0x04 || AC == 0x03)));
|
||||||
}
|
}
|
||||||
case AC_AC_READ: {
|
case AC_AC_READ: {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("IsTrailerAccessAllowed: AC_AC_READ");
|
Dbprintf("IsTrailerAccessAllowed: AC_AC_READ");
|
||||||
return ((keytype == AUTHKEYA)
|
return ((keytype == AUTHKEYA)
|
||||||
|| (keytype == AUTHKEYB && !(AC == 0x00 || AC == 0x02 || AC == 0x01)));
|
|| (keytype == AUTHKEYB && !(AC == 0x00 || AC == 0x02 || AC == 0x01)));
|
||||||
}
|
}
|
||||||
case AC_AC_WRITE: {
|
case AC_AC_WRITE: {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("IsTrailerAccessAllowed: AC_AC_WRITE");
|
Dbprintf("IsTrailerAccessAllowed: AC_AC_WRITE");
|
||||||
return ((keytype == AUTHKEYA && (AC == 0x01))
|
return ((keytype == AUTHKEYA && (AC == 0x01))
|
||||||
|| (keytype == AUTHKEYB && (AC == 0x03 || AC == 0x05)));
|
|| (keytype == AUTHKEYB && (AC == 0x03 || AC == 0x05)));
|
||||||
|
@ -103,7 +103,7 @@ static bool IsDataAccessAllowed(uint8_t blockNo, uint8_t keytype, uint8_t action
|
||||||
AC = ((sector_trailer[7] >> 2) & 0x04)
|
AC = ((sector_trailer[7] >> 2) & 0x04)
|
||||||
| ((sector_trailer[8] << 1) & 0x02)
|
| ((sector_trailer[8] << 1) & 0x02)
|
||||||
| ((sector_trailer[8] >> 4) & 0x01);
|
| ((sector_trailer[8] >> 4) & 0x01);
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("IsDataAccessAllowed: case 0x00 - %02x", AC);
|
Dbprintf("IsDataAccessAllowed: case 0x00 - %02x", AC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ static bool IsDataAccessAllowed(uint8_t blockNo, uint8_t keytype, uint8_t action
|
||||||
AC = ((sector_trailer[7] >> 3) & 0x04)
|
AC = ((sector_trailer[7] >> 3) & 0x04)
|
||||||
| ((sector_trailer[8] >> 0) & 0x02)
|
| ((sector_trailer[8] >> 0) & 0x02)
|
||||||
| ((sector_trailer[8] >> 5) & 0x01);
|
| ((sector_trailer[8] >> 5) & 0x01);
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("IsDataAccessAllowed: case 0x01 - %02x", AC);
|
Dbprintf("IsDataAccessAllowed: case 0x01 - %02x", AC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -119,37 +119,37 @@ static bool IsDataAccessAllowed(uint8_t blockNo, uint8_t keytype, uint8_t action
|
||||||
AC = ((sector_trailer[7] >> 4) & 0x04)
|
AC = ((sector_trailer[7] >> 4) & 0x04)
|
||||||
| ((sector_trailer[8] >> 1) & 0x02)
|
| ((sector_trailer[8] >> 1) & 0x02)
|
||||||
| ((sector_trailer[8] >> 6) & 0x01);
|
| ((sector_trailer[8] >> 6) & 0x01);
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("IsDataAccessAllowed: case 0x02 - %02x", AC);
|
Dbprintf("IsDataAccessAllowed: case 0x02 - %02x", AC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("IsDataAccessAllowed: Error");
|
Dbprintf("IsDataAccessAllowed: Error");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case AC_DATA_READ: {
|
case AC_DATA_READ: {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("IsDataAccessAllowed - AC_DATA_READ: OK");
|
Dbprintf("IsDataAccessAllowed - AC_DATA_READ: OK");
|
||||||
return ((keytype == AUTHKEYA && !(AC == 0x03 || AC == 0x05 || AC == 0x07))
|
return ((keytype == AUTHKEYA && !(AC == 0x03 || AC == 0x05 || AC == 0x07))
|
||||||
|| (keytype == AUTHKEYB && !(AC == 0x07)));
|
|| (keytype == AUTHKEYB && !(AC == 0x07)));
|
||||||
}
|
}
|
||||||
case AC_DATA_WRITE: {
|
case AC_DATA_WRITE: {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("IsDataAccessAllowed - AC_DATA_WRITE: OK");
|
Dbprintf("IsDataAccessAllowed - AC_DATA_WRITE: OK");
|
||||||
return ((keytype == AUTHKEYA && (AC == 0x00))
|
return ((keytype == AUTHKEYA && (AC == 0x00))
|
||||||
|| (keytype == AUTHKEYB && (AC == 0x00 || AC == 0x04 || AC == 0x06 || AC == 0x03)));
|
|| (keytype == AUTHKEYB && (AC == 0x00 || AC == 0x04 || AC == 0x06 || AC == 0x03)));
|
||||||
}
|
}
|
||||||
case AC_DATA_INC: {
|
case AC_DATA_INC: {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("IsDataAccessAllowed - AC_DATA_INC: OK");
|
Dbprintf("IsDataAccessAllowed - AC_DATA_INC: OK");
|
||||||
return ((keytype == AUTHKEYA && (AC == 0x00))
|
return ((keytype == AUTHKEYA && (AC == 0x00))
|
||||||
|| (keytype == AUTHKEYB && (AC == 0x00 || AC == 0x06)));
|
|| (keytype == AUTHKEYB && (AC == 0x00 || AC == 0x06)));
|
||||||
}
|
}
|
||||||
case AC_DATA_DEC_TRANS_REST: {
|
case AC_DATA_DEC_TRANS_REST: {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("AC_DATA_DEC_TRANS_REST: OK");
|
Dbprintf("AC_DATA_DEC_TRANS_REST: OK");
|
||||||
return ((keytype == AUTHKEYA && (AC == 0x00 || AC == 0x06 || AC == 0x01))
|
return ((keytype == AUTHKEYA && (AC == 0x00 || AC == 0x06 || AC == 0x01))
|
||||||
|| (keytype == AUTHKEYB && (AC == 0x00 || AC == 0x06 || AC == 0x01)));
|
|| (keytype == AUTHKEYB && (AC == 0x00 || AC == 0x06 || AC == 0x01)));
|
||||||
|
@ -254,28 +254,28 @@ static bool MifareSimInit(uint16_t flags, uint8_t *datain, uint16_t atqa, uint8_
|
||||||
if ((flags & FLAG_MF_MINI) == FLAG_MF_MINI) {
|
if ((flags & FLAG_MF_MINI) == FLAG_MF_MINI) {
|
||||||
memcpy(rATQA, rATQA_Mini, sizeof(rATQA));
|
memcpy(rATQA, rATQA_Mini, sizeof(rATQA));
|
||||||
rSAK[0] = rSAK_Mini;
|
rSAK[0] = rSAK_Mini;
|
||||||
if (DBGLEVEL > DBG_NONE) Dbprintf("Enforcing Mifare Mini ATQA/SAK");
|
if (g_dbglevel > DBG_NONE) Dbprintf("Enforcing Mifare Mini ATQA/SAK");
|
||||||
} else if ((flags & FLAG_MF_1K) == FLAG_MF_1K) {
|
} else if ((flags & FLAG_MF_1K) == FLAG_MF_1K) {
|
||||||
memcpy(rATQA, rATQA_1k, sizeof(rATQA));
|
memcpy(rATQA, rATQA_1k, sizeof(rATQA));
|
||||||
rSAK[0] = rSAK_1k;
|
rSAK[0] = rSAK_1k;
|
||||||
if (DBGLEVEL > DBG_NONE) Dbprintf("Enforcing Mifare 1K ATQA/SAK");
|
if (g_dbglevel > DBG_NONE) Dbprintf("Enforcing Mifare 1K ATQA/SAK");
|
||||||
} else if ((flags & FLAG_MF_2K) == FLAG_MF_2K) {
|
} else if ((flags & FLAG_MF_2K) == FLAG_MF_2K) {
|
||||||
memcpy(rATQA, rATQA_2k, sizeof(rATQA));
|
memcpy(rATQA, rATQA_2k, sizeof(rATQA));
|
||||||
rSAK[0] = rSAK_2k;
|
rSAK[0] = rSAK_2k;
|
||||||
*rats = rRATS;
|
*rats = rRATS;
|
||||||
*rats_len = sizeof(rRATS);
|
*rats_len = sizeof(rRATS);
|
||||||
if (DBGLEVEL > DBG_NONE) Dbprintf("Enforcing Mifare 2K ATQA/SAK with RATS support");
|
if (g_dbglevel > DBG_NONE) Dbprintf("Enforcing Mifare 2K ATQA/SAK with RATS support");
|
||||||
} else if ((flags & FLAG_MF_4K) == FLAG_MF_4K) {
|
} else if ((flags & FLAG_MF_4K) == FLAG_MF_4K) {
|
||||||
memcpy(rATQA, rATQA_4k, sizeof(rATQA));
|
memcpy(rATQA, rATQA_4k, sizeof(rATQA));
|
||||||
rSAK[0] = rSAK_4k;
|
rSAK[0] = rSAK_4k;
|
||||||
if (DBGLEVEL > DBG_NONE) Dbprintf("Enforcing Mifare 4K ATQA/SAK");
|
if (g_dbglevel > DBG_NONE) Dbprintf("Enforcing Mifare 4K ATQA/SAK");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare UID arrays
|
// Prepare UID arrays
|
||||||
if ((flags & FLAG_4B_UID_IN_DATA) == FLAG_4B_UID_IN_DATA) { // get UID from datain
|
if ((flags & FLAG_4B_UID_IN_DATA) == FLAG_4B_UID_IN_DATA) { // get UID from datain
|
||||||
memcpy(rUIDBCC1, datain, 4);
|
memcpy(rUIDBCC1, datain, 4);
|
||||||
*uid_len = 4;
|
*uid_len = 4;
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("MifareSimInit - FLAG_4B_UID_IN_DATA => Get UID from datain: %02X - Flag: %02X - UIDBCC1: %02X", FLAG_4B_UID_IN_DATA, flags, rUIDBCC1);
|
Dbprintf("MifareSimInit - FLAG_4B_UID_IN_DATA => Get UID from datain: %02X - Flag: %02X - UIDBCC1: %02X", FLAG_4B_UID_IN_DATA, flags, rUIDBCC1);
|
||||||
|
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ static bool MifareSimInit(uint16_t flags, uint8_t *datain, uint16_t atqa, uint8_
|
||||||
*cuid = bytes_to_num(rUIDBCC1, 4);
|
*cuid = bytes_to_num(rUIDBCC1, 4);
|
||||||
// BCC
|
// BCC
|
||||||
rUIDBCC1[4] = rUIDBCC1[0] ^ rUIDBCC1[1] ^ rUIDBCC1[2] ^ rUIDBCC1[3];
|
rUIDBCC1[4] = rUIDBCC1[0] ^ rUIDBCC1[1] ^ rUIDBCC1[2] ^ rUIDBCC1[3];
|
||||||
if (DBGLEVEL > DBG_NONE) {
|
if (g_dbglevel > DBG_NONE) {
|
||||||
Dbprintf("4B UID: %02x%02x%02x%02x", rUIDBCC1[0], rUIDBCC1[1], rUIDBCC1[2], rUIDBCC1[3]);
|
Dbprintf("4B UID: %02x%02x%02x%02x", rUIDBCC1[0], rUIDBCC1[1], rUIDBCC1[2], rUIDBCC1[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,7 +294,7 @@ static bool MifareSimInit(uint16_t flags, uint8_t *datain, uint16_t atqa, uint8_
|
||||||
memcpy(&rUIDBCC1[1], datain, 3);
|
memcpy(&rUIDBCC1[1], datain, 3);
|
||||||
memcpy(rUIDBCC2, datain + 3, 4);
|
memcpy(rUIDBCC2, datain + 3, 4);
|
||||||
*uid_len = 7;
|
*uid_len = 7;
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("MifareSimInit - FLAG_7B_UID_IN_DATA => Get UID from datain: %02X - Flag: %02X - UIDBCC1: %02X", FLAG_7B_UID_IN_DATA, flags, rUIDBCC1);
|
Dbprintf("MifareSimInit - FLAG_7B_UID_IN_DATA => Get UID from datain: %02X - Flag: %02X - UIDBCC1: %02X", FLAG_7B_UID_IN_DATA, flags, rUIDBCC1);
|
||||||
|
|
||||||
// save CUID
|
// save CUID
|
||||||
|
@ -304,7 +304,7 @@ static bool MifareSimInit(uint16_t flags, uint8_t *datain, uint16_t atqa, uint8_
|
||||||
// BCC
|
// BCC
|
||||||
rUIDBCC1[4] = rUIDBCC1[0] ^ rUIDBCC1[1] ^ rUIDBCC1[2] ^ rUIDBCC1[3];
|
rUIDBCC1[4] = rUIDBCC1[0] ^ rUIDBCC1[1] ^ rUIDBCC1[2] ^ rUIDBCC1[3];
|
||||||
rUIDBCC2[4] = rUIDBCC2[0] ^ rUIDBCC2[1] ^ rUIDBCC2[2] ^ rUIDBCC2[3];
|
rUIDBCC2[4] = rUIDBCC2[0] ^ rUIDBCC2[1] ^ rUIDBCC2[2] ^ rUIDBCC2[3];
|
||||||
if (DBGLEVEL > DBG_NONE) {
|
if (g_dbglevel > DBG_NONE) {
|
||||||
Dbprintf("7B UID: %02x %02x %02x %02x %02x %02x %02x",
|
Dbprintf("7B UID: %02x %02x %02x %02x %02x %02x %02x",
|
||||||
rUIDBCC1[1], rUIDBCC1[2], rUIDBCC1[3], rUIDBCC2[0], rUIDBCC2[1], rUIDBCC2[2], rUIDBCC2[3]);
|
rUIDBCC1[1], rUIDBCC1[2], rUIDBCC1[3], rUIDBCC2[0], rUIDBCC2[1], rUIDBCC2[2], rUIDBCC2[3]);
|
||||||
}
|
}
|
||||||
|
@ -317,7 +317,7 @@ static bool MifareSimInit(uint16_t flags, uint8_t *datain, uint16_t atqa, uint8_
|
||||||
memcpy(&rUIDBCC2[1], datain + 3, 3);
|
memcpy(&rUIDBCC2[1], datain + 3, 3);
|
||||||
memcpy(rUIDBCC3, datain + 6, 4);
|
memcpy(rUIDBCC3, datain + 6, 4);
|
||||||
*uid_len = 10;
|
*uid_len = 10;
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("MifareSimInit - FLAG_10B_UID_IN_DATA => Get UID from datain: %02X - Flag: %02X - UIDBCC1: %02X", FLAG_10B_UID_IN_DATA, flags, rUIDBCC1);
|
Dbprintf("MifareSimInit - FLAG_10B_UID_IN_DATA => Get UID from datain: %02X - Flag: %02X - UIDBCC1: %02X", FLAG_10B_UID_IN_DATA, flags, rUIDBCC1);
|
||||||
|
|
||||||
// save CUID
|
// save CUID
|
||||||
|
@ -330,7 +330,7 @@ static bool MifareSimInit(uint16_t flags, uint8_t *datain, uint16_t atqa, uint8_
|
||||||
rUIDBCC2[4] = rUIDBCC2[0] ^ rUIDBCC2[1] ^ rUIDBCC2[2] ^ rUIDBCC2[3];
|
rUIDBCC2[4] = rUIDBCC2[0] ^ rUIDBCC2[1] ^ rUIDBCC2[2] ^ rUIDBCC2[3];
|
||||||
rUIDBCC3[4] = rUIDBCC3[0] ^ rUIDBCC3[1] ^ rUIDBCC3[2] ^ rUIDBCC3[3];
|
rUIDBCC3[4] = rUIDBCC3[0] ^ rUIDBCC3[1] ^ rUIDBCC3[2] ^ rUIDBCC3[3];
|
||||||
|
|
||||||
if (DBGLEVEL > DBG_NONE) {
|
if (g_dbglevel > DBG_NONE) {
|
||||||
Dbprintf("10B UID: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
|
Dbprintf("10B UID: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
|
||||||
rUIDBCC1[1], rUIDBCC1[2], rUIDBCC1[3],
|
rUIDBCC1[1], rUIDBCC1[2], rUIDBCC1[3],
|
||||||
rUIDBCC2[1], rUIDBCC2[2], rUIDBCC2[3],
|
rUIDBCC2[1], rUIDBCC2[2], rUIDBCC2[3],
|
||||||
|
@ -351,7 +351,7 @@ static bool MifareSimInit(uint16_t flags, uint8_t *datain, uint16_t atqa, uint8_
|
||||||
if (flags & FLAG_FORCED_SAK) {
|
if (flags & FLAG_FORCED_SAK) {
|
||||||
rSAK[0] = sak;
|
rSAK[0] = sak;
|
||||||
}
|
}
|
||||||
if (DBGLEVEL > DBG_NONE) {
|
if (g_dbglevel > DBG_NONE) {
|
||||||
Dbprintf("ATQA : %02X %02X", rATQA[1], rATQA[0]);
|
Dbprintf("ATQA : %02X %02X", rATQA[1], rATQA[0]);
|
||||||
Dbprintf("SAK : %02X", rSAK[0]);
|
Dbprintf("SAK : %02X", rSAK[0]);
|
||||||
}
|
}
|
||||||
|
@ -570,13 +570,13 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
}
|
}
|
||||||
LEDsoff();
|
LEDsoff();
|
||||||
cardSTATE = MFEMUL_NOFIELD;
|
cardSTATE = MFEMUL_NOFIELD;
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("cardSTATE = MFEMUL_NOFIELD");
|
Dbprintf("cardSTATE = MFEMUL_NOFIELD");
|
||||||
continue;
|
continue;
|
||||||
} else if (res == 1) { // button pressed
|
} else if (res == 1) { // button pressed
|
||||||
FpgaDisableTracing();
|
FpgaDisableTracing();
|
||||||
button_pushed = true;
|
button_pushed = true;
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("Button pressed");
|
Dbprintf("Button pressed");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -584,7 +584,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
// WUPA in HALTED state or REQA or WUPA in any other state
|
// WUPA in HALTED state or REQA or WUPA in any other state
|
||||||
if (receivedCmd_len == 1 && ((receivedCmd[0] == ISO14443A_CMD_REQA && cardSTATE != MFEMUL_HALTED) || receivedCmd[0] == ISO14443A_CMD_WUPA)) {
|
if (receivedCmd_len == 1 && ((receivedCmd[0] == ISO14443A_CMD_REQA && cardSTATE != MFEMUL_HALTED) || receivedCmd[0] == ISO14443A_CMD_WUPA)) {
|
||||||
selTimer = GetTickCount();
|
selTimer = GetTickCount();
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("EmSendPrecompiledCmd(&responses[ATQA]);");
|
Dbprintf("EmSendPrecompiledCmd(&responses[ATQA]);");
|
||||||
EmSendPrecompiledCmd(&responses[ATQA]);
|
EmSendPrecompiledCmd(&responses[ATQA]);
|
||||||
|
|
||||||
|
@ -611,18 +611,18 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
|
|
||||||
switch (cardSTATE) {
|
switch (cardSTATE) {
|
||||||
case MFEMUL_NOFIELD: {
|
case MFEMUL_NOFIELD: {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("MFEMUL_NOFIELD");
|
Dbprintf("MFEMUL_NOFIELD");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MFEMUL_HALTED: {
|
case MFEMUL_HALTED: {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("MFEMUL_HALTED");
|
Dbprintf("MFEMUL_HALTED");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MFEMUL_IDLE: {
|
case MFEMUL_IDLE: {
|
||||||
LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true);
|
LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true);
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("MFEMUL_IDLE");
|
Dbprintf("MFEMUL_IDLE");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -657,7 +657,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
if (uid_index < 0) {
|
if (uid_index < 0) {
|
||||||
LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true);
|
LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true);
|
||||||
cardSTATE_TO_IDLE();
|
cardSTATE_TO_IDLE();
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_SELECT] Incorrect cascade level received");
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_SELECT] Incorrect cascade level received");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -666,7 +666,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
EmSendPrecompiledCmd(&responses[uid_index]);
|
EmSendPrecompiledCmd(&responses[uid_index]);
|
||||||
FpgaDisableTracing();
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("SELECT ALL - EmSendPrecompiledCmd(%02x)", &responses[uid_index]);
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("SELECT ALL - EmSendPrecompiledCmd(%02x)", &responses[uid_index]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -679,17 +679,17 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
EmSendPrecompiledCmd(&responses[cl_finished ? SAK : SAKuid]);
|
EmSendPrecompiledCmd(&responses[cl_finished ? SAK : SAKuid]);
|
||||||
FpgaDisableTracing();
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("SELECT CLx %02x%02x%02x%02x received", receivedCmd[2], receivedCmd[3], receivedCmd[4], receivedCmd[5]);
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("SELECT CLx %02x%02x%02x%02x received", receivedCmd[2], receivedCmd[3], receivedCmd[4], receivedCmd[5]);
|
||||||
if (cl_finished) {
|
if (cl_finished) {
|
||||||
LED_B_ON();
|
LED_B_ON();
|
||||||
cardSTATE = MFEMUL_WORK;
|
cardSTATE = MFEMUL_WORK;
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_SELECT] cardSTATE = MFEMUL_WORK");
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_SELECT] cardSTATE = MFEMUL_WORK");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// IDLE, not our UID
|
// IDLE, not our UID
|
||||||
LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true);
|
LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true);
|
||||||
cardSTATE_TO_IDLE();
|
cardSTATE_TO_IDLE();
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_SELECT] cardSTATE = MFEMUL_IDLE");
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_SELECT] cardSTATE = MFEMUL_IDLE");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -703,12 +703,12 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
EmSendPrecompiledCmd(&responses[uid_index + receivedCmd_len - 2]);
|
EmSendPrecompiledCmd(&responses[uid_index + receivedCmd_len - 2]);
|
||||||
FpgaDisableTracing();
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("SELECT ANTICOLLISION - EmSendPrecompiledCmd(%02x)", &responses[uid_index]);
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("SELECT ANTICOLLISION - EmSendPrecompiledCmd(%02x)", &responses[uid_index]);
|
||||||
} else {
|
} else {
|
||||||
// IDLE, not our UID or split-byte frame anti-collision (not supports)
|
// IDLE, not our UID or split-byte frame anti-collision (not supports)
|
||||||
LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true);
|
LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true);
|
||||||
cardSTATE_TO_IDLE();
|
cardSTATE_TO_IDLE();
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_SELECT] cardSTATE = MFEMUL_IDLE");
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_SELECT] cardSTATE = MFEMUL_IDLE");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -716,19 +716,19 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
// Unknown selection procedure
|
// Unknown selection procedure
|
||||||
LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true);
|
LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true);
|
||||||
cardSTATE_TO_IDLE();
|
cardSTATE_TO_IDLE();
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_SELECT] Unknown selection procedure");
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_SELECT] Unknown selection procedure");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// WORK
|
// WORK
|
||||||
case MFEMUL_WORK: {
|
case MFEMUL_WORK: {
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
Dbprintf("[MFEMUL_WORK] Enter in case");
|
Dbprintf("[MFEMUL_WORK] Enter in case");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (receivedCmd_len == 0) {
|
if (receivedCmd_len == 0) {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] NO CMD received");
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] NO CMD received");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -736,7 +736,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
if (encrypted_data) {
|
if (encrypted_data) {
|
||||||
// decrypt seqence
|
// decrypt seqence
|
||||||
mf_crypto1_decryptEx(pcs, receivedCmd, receivedCmd_len, receivedCmd_dec);
|
mf_crypto1_decryptEx(pcs, receivedCmd, receivedCmd_len, receivedCmd_dec);
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Decrypt sequence");
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Decrypt sequence");
|
||||||
} else {
|
} else {
|
||||||
// Data in clear
|
// Data in clear
|
||||||
memcpy(receivedCmd_dec, receivedCmd, receivedCmd_len);
|
memcpy(receivedCmd_dec, receivedCmd, receivedCmd_len);
|
||||||
|
@ -747,7 +747,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
|
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
|
||||||
FpgaDisableTracing();
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] All commands must have a valid CRC %02X (%d)", receivedCmd_dec, receivedCmd_len);
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] All commands must have a valid CRC %02X (%d)", receivedCmd_dec, receivedCmd_len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -769,7 +769,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
// cardAUTHKEY: 61 => Auth use Key B
|
// cardAUTHKEY: 61 => Auth use Key B
|
||||||
cardAUTHKEY = receivedCmd_dec[0] & 0x01;
|
cardAUTHKEY = receivedCmd_dec[0] & 0x01;
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] KEY %c: %012" PRIx64, (cardAUTHKEY == 0) ? 'A' : 'B', emlGetKey(cardAUTHSC, cardAUTHKEY));
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] KEY %c: %012" PRIx64, (cardAUTHKEY == 0) ? 'A' : 'B', emlGetKey(cardAUTHSC, cardAUTHKEY));
|
||||||
|
|
||||||
// first authentication
|
// first authentication
|
||||||
crypto1_deinit(pcs);
|
crypto1_deinit(pcs);
|
||||||
|
@ -785,7 +785,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
EmSendCmd(rAUTH_NT, sizeof(rAUTH_NT));
|
EmSendCmd(rAUTH_NT, sizeof(rAUTH_NT));
|
||||||
FpgaDisableTracing();
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Reader authenticating for block %d (0x%02x) with key %c - nonce: %02X - ciud: %02X", receivedCmd_dec[1], receivedCmd_dec[1], (cardAUTHKEY == 0) ? 'A' : 'B', rAUTH_NT, cuid);
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Reader authenticating for block %d (0x%02x) with key %c - nonce: %02X - ciud: %02X", receivedCmd_dec[1], receivedCmd_dec[1], (cardAUTHKEY == 0) ? 'A' : 'B', rAUTH_NT, cuid);
|
||||||
} else {
|
} else {
|
||||||
// nested authentication
|
// nested authentication
|
||||||
/*
|
/*
|
||||||
|
@ -798,11 +798,11 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
EmSendCmdPar(response, 4, response_par);
|
EmSendCmdPar(response, 4, response_par);
|
||||||
FpgaDisableTracing();
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Reader doing nested authentication for block %d (0x%02x) with key %c", receivedCmd_dec[1], receivedCmd_dec[1], (cardAUTHKEY == 0) ? 'A' : 'B');
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Reader doing nested authentication for block %d (0x%02x) with key %c", receivedCmd_dec[1], receivedCmd_dec[1], (cardAUTHKEY == 0) ? 'A' : 'B');
|
||||||
}
|
}
|
||||||
|
|
||||||
cardSTATE = MFEMUL_AUTH1;
|
cardSTATE = MFEMUL_AUTH1;
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_AUTH1 - rAUTH_NT: %02X", rAUTH_NT);
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_AUTH1 - rAUTH_NT: %02X", rAUTH_NT);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -833,7 +833,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
EmSend4bit(CARD_NACK_NA);
|
EmSend4bit(CARD_NACK_NA);
|
||||||
FpgaDisableTracing();
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Commands must be encrypted (authenticated)");
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Commands must be encrypted (authenticated)");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -843,7 +843,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
if (receivedCmd_dec[1] > MIFARE_4K_MAXBLOCK) {
|
if (receivedCmd_dec[1] > MIFARE_4K_MAXBLOCK) {
|
||||||
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
||||||
FpgaDisableTracing();
|
FpgaDisableTracing();
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("[MFEMUL_WORK] Reader tried to operate (0x%02x) on out of range block: %d (0x%02x), nacking", receivedCmd_dec[0], receivedCmd_dec[1], receivedCmd_dec[1]);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("[MFEMUL_WORK] Reader tried to operate (0x%02x) on out of range block: %d (0x%02x), nacking", receivedCmd_dec[0], receivedCmd_dec[1], receivedCmd_dec[1]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
@ -852,7 +852,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
||||||
FpgaDisableTracing();
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_ERROR)
|
if (g_dbglevel >= DBG_ERROR)
|
||||||
Dbprintf("[MFEMUL_WORK] Reader tried to operate (0x%02x) on block (0x%02x) not authenticated for (0x%02x), nacking", receivedCmd_dec[0], receivedCmd_dec[1], cardAUTHSC);
|
Dbprintf("[MFEMUL_WORK] Reader tried to operate (0x%02x) on block (0x%02x) not authenticated for (0x%02x), nacking", receivedCmd_dec[0], receivedCmd_dec[1], cardAUTHSC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -861,7 +861,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
// case MFEMUL_WORK => CMD READ block
|
// case MFEMUL_WORK => CMD READ block
|
||||||
if (receivedCmd_len == 4 && receivedCmd_dec[0] == ISO14443A_CMD_READBLOCK) {
|
if (receivedCmd_len == 4 && receivedCmd_dec[0] == ISO14443A_CMD_READBLOCK) {
|
||||||
blockNo = receivedCmd_dec[1];
|
blockNo = receivedCmd_dec[1];
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("[MFEMUL_WORK] Reader reading block %d (0x%02x)", blockNo, blockNo);
|
Dbprintf("[MFEMUL_WORK] Reader reading block %d (0x%02x)", blockNo, blockNo);
|
||||||
|
|
||||||
// android CVE 2021_0430
|
// android CVE 2021_0430
|
||||||
|
@ -894,7 +894,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
|
|
||||||
emlGetMem(response, blockNo, 1);
|
emlGetMem(response, blockNo, 1);
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
Dbprintf("[MFEMUL_WORK - ISO14443A_CMD_READBLOCK] Data Block[%d]: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", blockNo,
|
Dbprintf("[MFEMUL_WORK - ISO14443A_CMD_READBLOCK] Data Block[%d]: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", blockNo,
|
||||||
response[0], response[1], response[2], response[3], response[4], response[5], response[6],
|
response[0], response[1], response[2], response[3], response[4], response[5], response[6],
|
||||||
response[7], response[8], response[9], response[10], response[11], response[12], response[13],
|
response[7], response[8], response[9], response[10], response[11], response[12], response[13],
|
||||||
|
@ -920,20 +920,20 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
|
|
||||||
if (IsAccessAllowed(blockNo, cardAUTHKEY, AC_KEYA_READ) == false) {
|
if (IsAccessAllowed(blockNo, cardAUTHKEY, AC_KEYA_READ) == false) {
|
||||||
memset(response, 0x00, 6); // keyA can never be read
|
memset(response, 0x00, 6); // keyA can never be read
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK - IsSectorTrailer] keyA can never be read - block %d (0x%02x)", blockNo, blockNo);
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK - IsSectorTrailer] keyA can never be read - block %d (0x%02x)", blockNo, blockNo);
|
||||||
}
|
}
|
||||||
if (IsAccessAllowed(blockNo, cardAUTHKEY, AC_KEYB_READ) == false) {
|
if (IsAccessAllowed(blockNo, cardAUTHKEY, AC_KEYB_READ) == false) {
|
||||||
memset(response + 10, 0x00, 6); // keyB cannot be read
|
memset(response + 10, 0x00, 6); // keyB cannot be read
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK - IsSectorTrailer] keyB cannot be read - block %d (0x%02x)", blockNo, blockNo);
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK - IsSectorTrailer] keyB cannot be read - block %d (0x%02x)", blockNo, blockNo);
|
||||||
}
|
}
|
||||||
if (IsAccessAllowed(blockNo, cardAUTHKEY, AC_AC_READ) == false) {
|
if (IsAccessAllowed(blockNo, cardAUTHKEY, AC_AC_READ) == false) {
|
||||||
memset(response + 6, 0x00, 4); // AC bits cannot be read
|
memset(response + 6, 0x00, 4); // AC bits cannot be read
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK - IsAccessAllowed] AC bits cannot be read - block %d (0x%02x)", blockNo, blockNo);
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK - IsAccessAllowed] AC bits cannot be read - block %d (0x%02x)", blockNo, blockNo);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (IsAccessAllowed(blockNo, cardAUTHKEY, AC_DATA_READ) == false) {
|
if (IsAccessAllowed(blockNo, cardAUTHKEY, AC_DATA_READ) == false) {
|
||||||
memset(response, 0x00, 16); // datablock cannot be read
|
memset(response, 0x00, 16); // datablock cannot be read
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK - IsAccessAllowed] Data block %d (0x%02x) cannot be read", blockNo, blockNo);
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK - IsAccessAllowed] Data block %d (0x%02x) cannot be read", blockNo, blockNo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AddCrc14A(response, 16);
|
AddCrc14A(response, 16);
|
||||||
|
@ -941,7 +941,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
EmSendCmdPar(response, MAX_MIFARE_FRAME_SIZE, response_par);
|
EmSendCmdPar(response, MAX_MIFARE_FRAME_SIZE, response_par);
|
||||||
FpgaDisableTracing();
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
Dbprintf("[MFEMUL_WORK - EmSendCmdPar] Data Block[%d]: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", blockNo,
|
Dbprintf("[MFEMUL_WORK - EmSendCmdPar] Data Block[%d]: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", blockNo,
|
||||||
response[0], response[1], response[2], response[3], response[4], response[5], response[6],
|
response[0], response[1], response[2], response[3], response[4], response[5], response[6],
|
||||||
response[7], response[8], response[9], response[10], response[11], response[12], response[13],
|
response[7], response[8], response[9], response[10], response[11], response[12], response[13],
|
||||||
|
@ -960,22 +960,22 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
// case MFEMUL_WORK => CMD WRITEBLOCK
|
// case MFEMUL_WORK => CMD WRITEBLOCK
|
||||||
if (receivedCmd_len == 4 && receivedCmd_dec[0] == ISO14443A_CMD_WRITEBLOCK) {
|
if (receivedCmd_len == 4 && receivedCmd_dec[0] == ISO14443A_CMD_WRITEBLOCK) {
|
||||||
blockNo = receivedCmd_dec[1];
|
blockNo = receivedCmd_dec[1];
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RECV 0xA0 write block %d (%02x)", blockNo, blockNo);
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RECV 0xA0 write block %d (%02x)", blockNo, blockNo);
|
||||||
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_ACK));
|
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_ACK));
|
||||||
FpgaDisableTracing();
|
FpgaDisableTracing();
|
||||||
|
|
||||||
cardWRBL = blockNo;
|
cardWRBL = blockNo;
|
||||||
cardSTATE = MFEMUL_WRITEBL2;
|
cardSTATE = MFEMUL_WRITEBL2;
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_WRITEBL2");
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_WRITEBL2");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// case MFEMUL_WORK => CMD INC/DEC/REST
|
// case MFEMUL_WORK => CMD INC/DEC/REST
|
||||||
if (receivedCmd_len == 4 && (receivedCmd_dec[0] == MIFARE_CMD_INC || receivedCmd_dec[0] == MIFARE_CMD_DEC || receivedCmd_dec[0] == MIFARE_CMD_RESTORE)) {
|
if (receivedCmd_len == 4 && (receivedCmd_dec[0] == MIFARE_CMD_INC || receivedCmd_dec[0] == MIFARE_CMD_DEC || receivedCmd_dec[0] == MIFARE_CMD_RESTORE)) {
|
||||||
blockNo = receivedCmd_dec[1];
|
blockNo = receivedCmd_dec[1];
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RECV 0x%02x inc(0xC1)/dec(0xC0)/restore(0xC2) block %d (%02x)", receivedCmd_dec[0], blockNo, blockNo);
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RECV 0x%02x inc(0xC1)/dec(0xC0)/restore(0xC2) block %d (%02x)", receivedCmd_dec[0], blockNo, blockNo);
|
||||||
if (emlCheckValBl(blockNo)) {
|
if (emlCheckValBl(blockNo)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("[MFEMUL_WORK] Reader tried to operate on block, but emlCheckValBl failed, nacking");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("[MFEMUL_WORK] Reader tried to operate on block, but emlCheckValBl failed, nacking");
|
||||||
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
||||||
FpgaDisableTracing();
|
FpgaDisableTracing();
|
||||||
break;
|
break;
|
||||||
|
@ -987,19 +987,19 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
// INC
|
// INC
|
||||||
if (receivedCmd_dec[0] == MIFARE_CMD_INC) {
|
if (receivedCmd_dec[0] == MIFARE_CMD_INC) {
|
||||||
cardSTATE = MFEMUL_INTREG_INC;
|
cardSTATE = MFEMUL_INTREG_INC;
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_INTREG_INC");
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_INTREG_INC");
|
||||||
}
|
}
|
||||||
|
|
||||||
// DEC
|
// DEC
|
||||||
if (receivedCmd_dec[0] == MIFARE_CMD_DEC) {
|
if (receivedCmd_dec[0] == MIFARE_CMD_DEC) {
|
||||||
cardSTATE = MFEMUL_INTREG_DEC;
|
cardSTATE = MFEMUL_INTREG_DEC;
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_INTREG_DEC");
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_INTREG_DEC");
|
||||||
}
|
}
|
||||||
|
|
||||||
// REST
|
// REST
|
||||||
if (receivedCmd_dec[0] == MIFARE_CMD_RESTORE) {
|
if (receivedCmd_dec[0] == MIFARE_CMD_RESTORE) {
|
||||||
cardSTATE = MFEMUL_INTREG_REST;
|
cardSTATE = MFEMUL_INTREG_REST;
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_INTREG_REST");
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_INTREG_REST");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1009,7 +1009,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
// case MFEMUL_WORK => CMD TRANSFER
|
// case MFEMUL_WORK => CMD TRANSFER
|
||||||
if (receivedCmd_len == 4 && receivedCmd_dec[0] == MIFARE_CMD_TRANSFER) {
|
if (receivedCmd_len == 4 && receivedCmd_dec[0] == MIFARE_CMD_TRANSFER) {
|
||||||
blockNo = receivedCmd_dec[1];
|
blockNo = receivedCmd_dec[1];
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RECV 0x%02x transfer block %d (%02x)", receivedCmd_dec[0], blockNo, blockNo);
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RECV 0x%02x transfer block %d (%02x)", receivedCmd_dec[0], blockNo, blockNo);
|
||||||
if (emlSetValBl(cardINTREG, cardINTBLOCK, receivedCmd_dec[1]))
|
if (emlSetValBl(cardINTREG, cardINTBLOCK, receivedCmd_dec[1]))
|
||||||
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
||||||
else
|
else
|
||||||
|
@ -1026,7 +1026,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
LED_C_OFF();
|
LED_C_OFF();
|
||||||
cardSTATE = MFEMUL_HALTED;
|
cardSTATE = MFEMUL_HALTED;
|
||||||
cardAUTHKEY = AUTHKEYNONE;
|
cardAUTHKEY = AUTHKEYNONE;
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_HALTED");
|
Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_HALTED");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1042,12 +1042,12 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
EmSendCmd(rats, rats_len);
|
EmSendCmd(rats, rats_len);
|
||||||
}
|
}
|
||||||
FpgaDisableTracing();
|
FpgaDisableTracing();
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("[MFEMUL_WORK] RCV RATS => ACK");
|
Dbprintf("[MFEMUL_WORK] RCV RATS => ACK");
|
||||||
} else {
|
} else {
|
||||||
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
|
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
|
||||||
FpgaDisableTracing();
|
FpgaDisableTracing();
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("[MFEMUL_WORK] RCV RATS => NACK");
|
Dbprintf("[MFEMUL_WORK] RCV RATS => NACK");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1065,20 +1065,20 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
EmSendCmd(receivedCmd_dec, receivedCmd_len);
|
EmSendCmd(receivedCmd_dec, receivedCmd_len);
|
||||||
|
|
||||||
FpgaDisableTracing();
|
FpgaDisableTracing();
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("[MFEMUL_WORK] RCV NXP DESELECT => ACK");
|
Dbprintf("[MFEMUL_WORK] RCV NXP DESELECT => ACK");
|
||||||
} else {
|
} else {
|
||||||
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
|
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
|
||||||
FpgaDisableTracing();
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("[MFEMUL_WORK] RCV NXP DESELECT => NACK");
|
Dbprintf("[MFEMUL_WORK] RCV NXP DESELECT => NACK");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// case MFEMUL_WORK => command not allowed
|
// case MFEMUL_WORK => command not allowed
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("Received command not allowed, nacking");
|
Dbprintf("Received command not allowed, nacking");
|
||||||
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
|
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
|
||||||
FpgaDisableTracing();
|
FpgaDisableTracing();
|
||||||
|
@ -1087,13 +1087,13 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
|
|
||||||
// AUTH1
|
// AUTH1
|
||||||
case MFEMUL_AUTH1: {
|
case MFEMUL_AUTH1: {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("[MFEMUL_AUTH1] Enter case");
|
Dbprintf("[MFEMUL_AUTH1] Enter case");
|
||||||
|
|
||||||
if (receivedCmd_len != 8) {
|
if (receivedCmd_len != 8) {
|
||||||
cardSTATE_TO_IDLE();
|
cardSTATE_TO_IDLE();
|
||||||
LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true);
|
LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true);
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("MFEMUL_AUTH1: receivedCmd_len != 8 (%d) => cardSTATE_TO_IDLE())", receivedCmd_len);
|
Dbprintf("MFEMUL_AUTH1: receivedCmd_len != 8 (%d) => cardSTATE_TO_IDLE())", receivedCmd_len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1168,7 +1168,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
|
|
||||||
// test if auth KO
|
// test if auth KO
|
||||||
if (cardRr != prng_successor(nonce, 64)) {
|
if (cardRr != prng_successor(nonce, 64)) {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
Dbprintf("[MFEMUL_AUTH1] AUTH FAILED for sector %d with key %c. [nr=%08x cardRr=%08x] [nt=%08x succ=%08x]"
|
Dbprintf("[MFEMUL_AUTH1] AUTH FAILED for sector %d with key %c. [nr=%08x cardRr=%08x] [nt=%08x succ=%08x]"
|
||||||
, cardAUTHSC
|
, cardAUTHSC
|
||||||
, (cardAUTHKEY == 0) ? 'A' : 'B'
|
, (cardAUTHKEY == 0) ? 'A' : 'B'
|
||||||
|
@ -1191,7 +1191,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
EmSendCmdPar(response, 4, response_par);
|
EmSendCmdPar(response, 4, response_par);
|
||||||
FpgaDisableTracing();
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
Dbprintf("[MFEMUL_AUTH1] AUTH COMPLETED for sector %d with key %c. time=%d",
|
Dbprintf("[MFEMUL_AUTH1] AUTH COMPLETED for sector %d with key %c. time=%d",
|
||||||
cardAUTHSC,
|
cardAUTHSC,
|
||||||
cardAUTHKEY == 0 ? 'A' : 'B',
|
cardAUTHKEY == 0 ? 'A' : 'B',
|
||||||
|
@ -1200,7 +1200,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
}
|
}
|
||||||
LED_C_ON();
|
LED_C_ON();
|
||||||
cardSTATE = MFEMUL_WORK;
|
cardSTATE = MFEMUL_WORK;
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_AUTH1] cardSTATE = MFEMUL_WORK");
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_AUTH1] cardSTATE = MFEMUL_WORK");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1230,12 +1230,12 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
FpgaDisableTracing();
|
FpgaDisableTracing();
|
||||||
|
|
||||||
cardSTATE = MFEMUL_WORK;
|
cardSTATE = MFEMUL_WORK;
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WRITEBL2] cardSTATE = MFEMUL_WORK");
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_WRITEBL2] cardSTATE = MFEMUL_WORK");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cardSTATE_TO_IDLE();
|
cardSTATE_TO_IDLE();
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WRITEBL2] cardSTATE = MFEMUL_IDLE");
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_WRITEBL2] cardSTATE = MFEMUL_IDLE");
|
||||||
LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true);
|
LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1255,7 +1255,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
cardINTREG = cardINTREG + ans;
|
cardINTREG = cardINTREG + ans;
|
||||||
|
|
||||||
cardSTATE = MFEMUL_WORK;
|
cardSTATE = MFEMUL_WORK;
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_INTREG_INC] cardSTATE = MFEMUL_WORK");
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_INTREG_INC] cardSTATE = MFEMUL_WORK");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1276,7 +1276,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true);
|
LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true);
|
||||||
cardINTREG = cardINTREG - ans;
|
cardINTREG = cardINTREG - ans;
|
||||||
cardSTATE = MFEMUL_WORK;
|
cardSTATE = MFEMUL_WORK;
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_INTREG_DEC] cardSTATE = MFEMUL_WORK");
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_INTREG_DEC] cardSTATE = MFEMUL_WORK");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1292,7 +1292,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
}
|
}
|
||||||
LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true);
|
LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true);
|
||||||
cardSTATE = MFEMUL_WORK;
|
cardSTATE = MFEMUL_WORK;
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_INTREG_REST] cardSTATE = MFEMUL_WORK");
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("[MFEMUL_INTREG_REST] cardSTATE = MFEMUL_WORK");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1306,7 +1306,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
|
|
||||||
// NR AR ATTACK
|
// NR AR ATTACK
|
||||||
// mfkey32
|
// mfkey32
|
||||||
if (((flags & FLAG_NR_AR_ATTACK) == FLAG_NR_AR_ATTACK) && (DBGLEVEL >= DBG_INFO)) {
|
if (((flags & FLAG_NR_AR_ATTACK) == FLAG_NR_AR_ATTACK) && (g_dbglevel >= DBG_INFO)) {
|
||||||
for (uint8_t i = 0; i < ATTACK_KEY_COUNT; i++) {
|
for (uint8_t i = 0; i < ATTACK_KEY_COUNT; i++) {
|
||||||
if (ar_nr_collected[i] == 2) {
|
if (ar_nr_collected[i] == 2) {
|
||||||
Dbprintf("Collected two pairs of AR/NR which can be used to extract %s from reader for sector %d:", (i < ATTACK_KEY_COUNT / 2) ? "keyA" : "keyB", ar_nr_resp[i].sector);
|
Dbprintf("Collected two pairs of AR/NR which can be used to extract %s from reader for sector %d:", (i < ATTACK_KEY_COUNT / 2) ? "keyA" : "keyB", ar_nr_resp[i].sector);
|
||||||
|
@ -1338,7 +1338,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_ERROR) {
|
if (g_dbglevel >= DBG_ERROR) {
|
||||||
Dbprintf("Emulator stopped. Tracing: %d trace length: %d ", get_tracing(), BigBuf_get_traceLen());
|
Dbprintf("Emulator stopped. Tracing: %d trace length: %d ", get_tracing(), BigBuf_get_traceLen());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ void RAMFUNC SniffMifare(uint8_t param) {
|
||||||
// Setup and start DMA.
|
// Setup and start DMA.
|
||||||
// set transfer address and number of bytes. Start transfer.
|
// set transfer address and number of bytes. Start transfer.
|
||||||
if (!FpgaSetupSscDma(dmaBuf, DMA_BUFFER_SIZE)) {
|
if (!FpgaSetupSscDma(dmaBuf, DMA_BUFFER_SIZE)) {
|
||||||
if (DBGLEVEL > 1) Dbprintf("[!] FpgaSetupSscDma failed. Exiting");
|
if (g_dbglevel > 1) Dbprintf("[!] FpgaSetupSscDma failed. Exiting");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ int mifare_sendcmd(uint8_t cmd, uint8_t *data, uint8_t data_size, uint8_t *answe
|
||||||
ReaderTransmit(dcmd, sizeof(dcmd), timing);
|
ReaderTransmit(dcmd, sizeof(dcmd), timing);
|
||||||
int len = ReaderReceive(answer, answer_parity);
|
int len = ReaderReceive(answer, answer_parity);
|
||||||
if (!len) {
|
if (!len) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("%02X Cmd failed. Card timeout.", cmd);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("%02X Cmd failed. Card timeout.", cmd);
|
||||||
len = ReaderReceive(answer, answer_parity);
|
len = ReaderReceive(answer, answer_parity);
|
||||||
}
|
}
|
||||||
return len;
|
return len;
|
||||||
|
@ -164,7 +164,7 @@ int mifare_classic_authex(struct Crypto1State *pcs, uint32_t uid, uint8_t blockN
|
||||||
}
|
}
|
||||||
|
|
||||||
// some statistic
|
// some statistic
|
||||||
if (!ntptr && (DBGLEVEL >= DBG_EXTENDED))
|
if (!ntptr && (g_dbglevel >= DBG_EXTENDED))
|
||||||
Dbprintf("auth uid: %08x | nr: %08x | nt: %08x", uid, nr, nt);
|
Dbprintf("auth uid: %08x | nr: %08x | nt: %08x", uid, nr, nt);
|
||||||
|
|
||||||
// save Nt
|
// save Nt
|
||||||
|
@ -204,14 +204,14 @@ int mifare_classic_authex(struct Crypto1State *pcs, uint32_t uid, uint8_t blockN
|
||||||
iso14a_set_timeout(save_timeout);
|
iso14a_set_timeout(save_timeout);
|
||||||
|
|
||||||
if (!len) {
|
if (!len) {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("Authentication failed. Card timeout");
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("Authentication failed. Card timeout");
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
ntpp = prng_successor(nt, 32) ^ crypto1_word(pcs, 0, 0);
|
ntpp = prng_successor(nt, 32) ^ crypto1_word(pcs, 0, 0);
|
||||||
|
|
||||||
if (ntpp != bytes_to_num(receivedAnswer, 4)) {
|
if (ntpp != bytes_to_num(receivedAnswer, 4)) {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("Authentication failed. Error card response");
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("Authentication failed. Error card response");
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -226,18 +226,18 @@ int mifare_classic_readblock(struct Crypto1State *pcs, uint32_t uid, uint8_t blo
|
||||||
|
|
||||||
len = mifare_sendcmd_short(pcs, 1, ISO14443A_CMD_READBLOCK, blockNo, receivedAnswer, receivedAnswerPar, NULL);
|
len = mifare_sendcmd_short(pcs, 1, ISO14443A_CMD_READBLOCK, blockNo, receivedAnswer, receivedAnswerPar, NULL);
|
||||||
if (len == 1) {
|
if (len == 1) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd Error %02x", receivedAnswer[0]);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Cmd Error %02x", receivedAnswer[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (len != 18) {
|
if (len != 18) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("wrong response len %d (expected 18)", len);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("wrong response len %d (expected 18)", len);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(bt, receivedAnswer + 16, 2);
|
memcpy(bt, receivedAnswer + 16, 2);
|
||||||
AddCrc14A(receivedAnswer, 16);
|
AddCrc14A(receivedAnswer, 16);
|
||||||
if (bt[0] != receivedAnswer[16] || bt[1] != receivedAnswer[17]) {
|
if (bt[0] != receivedAnswer[16] || bt[1] != receivedAnswer[17]) {
|
||||||
if (DBGLEVEL >= DBG_INFO) Dbprintf("CRC response error");
|
if (g_dbglevel >= DBG_INFO) Dbprintf("CRC response error");
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,17 +254,17 @@ int mifare_ul_ev1_auth(uint8_t *keybytes, uint8_t *pack) {
|
||||||
uint8_t key[4] = {0x00, 0x00, 0x00, 0x00};
|
uint8_t key[4] = {0x00, 0x00, 0x00, 0x00};
|
||||||
memcpy(key, keybytes, 4);
|
memcpy(key, keybytes, 4);
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("EV1 Auth : %02x%02x%02x%02x", key[0], key[1], key[2], key[3]);
|
Dbprintf("EV1 Auth : %02x%02x%02x%02x", key[0], key[1], key[2], key[3]);
|
||||||
|
|
||||||
len = mifare_sendcmd(MIFARE_ULEV1_AUTH, key, sizeof(key), resp, respPar, NULL);
|
len = mifare_sendcmd(MIFARE_ULEV1_AUTH, key, sizeof(key), resp, respPar, NULL);
|
||||||
|
|
||||||
if (len != 4) {
|
if (len != 4) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd Error: %02x %u", resp[0], len);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Cmd Error: %02x %u", resp[0], len);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("Auth Resp: %02x%02x%02x%02x", resp[0], resp[1], resp[2], resp[3]);
|
Dbprintf("Auth Resp: %02x%02x%02x%02x", resp[0], resp[1], resp[2], resp[3]);
|
||||||
|
|
||||||
memcpy(pack, resp, 4);
|
memcpy(pack, resp, 4);
|
||||||
|
@ -289,7 +289,7 @@ int mifare_ultra_auth(uint8_t *keybytes) {
|
||||||
// REQUEST AUTHENTICATION
|
// REQUEST AUTHENTICATION
|
||||||
len = mifare_sendcmd_short(NULL, CRYPT_NONE, MIFARE_ULC_AUTH_1, 0x00, resp, respPar, NULL);
|
len = mifare_sendcmd_short(NULL, CRYPT_NONE, MIFARE_ULC_AUTH_1, 0x00, resp, respPar, NULL);
|
||||||
if (len != 11) {
|
if (len != 11) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd Error: %02x", resp[0]);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Cmd Error: %02x", resp[0]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ int mifare_ultra_auth(uint8_t *keybytes) {
|
||||||
memcpy(rnd_ab, random_a, 8);
|
memcpy(rnd_ab, random_a, 8);
|
||||||
memcpy(rnd_ab + 8, random_b, 8);
|
memcpy(rnd_ab + 8, random_b, 8);
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
Dbprintf("enc_B: %02x %02x %02x %02x %02x %02x %02x %02x",
|
Dbprintf("enc_B: %02x %02x %02x %02x %02x %02x %02x %02x",
|
||||||
enc_random_b[0], enc_random_b[1], enc_random_b[2], enc_random_b[3], enc_random_b[4], enc_random_b[5], enc_random_b[6], enc_random_b[7]);
|
enc_random_b[0], enc_random_b[1], enc_random_b[2], enc_random_b[3], enc_random_b[4], enc_random_b[5], enc_random_b[6], enc_random_b[7]);
|
||||||
|
|
||||||
|
@ -321,7 +321,7 @@ int mifare_ultra_auth(uint8_t *keybytes) {
|
||||||
|
|
||||||
len = mifare_sendcmd(MIFARE_ULC_AUTH_2, rnd_ab, sizeof(rnd_ab), resp, respPar, NULL);
|
len = mifare_sendcmd(MIFARE_ULC_AUTH_2, rnd_ab, sizeof(rnd_ab), resp, respPar, NULL);
|
||||||
if (len != 11) {
|
if (len != 11) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd Error: %02x", resp[0]);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Cmd Error: %02x", resp[0]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,11 +332,11 @@ int mifare_ultra_auth(uint8_t *keybytes) {
|
||||||
// decrypt out, in, length, key, iv
|
// decrypt out, in, length, key, iv
|
||||||
tdes_nxp_receive(enc_resp, resp_random_a, 8, key, enc_random_b, 2);
|
tdes_nxp_receive(enc_resp, resp_random_a, 8, key, enc_random_b, 2);
|
||||||
if (memcmp(resp_random_a, random_a, 8) != 0) {
|
if (memcmp(resp_random_a, random_a, 8) != 0) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("failed authentication");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("failed authentication");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
Dbprintf("e_AB: %02x %02x %02x %02x %02x %02x %02x %02x",
|
Dbprintf("e_AB: %02x %02x %02x %02x %02x %02x %02x %02x",
|
||||||
rnd_ab[0], rnd_ab[1], rnd_ab[2], rnd_ab[3],
|
rnd_ab[0], rnd_ab[1], rnd_ab[2], rnd_ab[3],
|
||||||
rnd_ab[4], rnd_ab[5], rnd_ab[6], rnd_ab[7]);
|
rnd_ab[4], rnd_ab[5], rnd_ab[6], rnd_ab[7]);
|
||||||
|
@ -364,18 +364,18 @@ static int mifare_ultra_readblockEx(uint8_t blockNo, uint8_t *blockData) {
|
||||||
|
|
||||||
len = mifare_sendcmd_short(NULL, CRYPT_NONE, ISO14443A_CMD_READBLOCK, blockNo, receivedAnswer, receivedAnswerPar, NULL);
|
len = mifare_sendcmd_short(NULL, CRYPT_NONE, ISO14443A_CMD_READBLOCK, blockNo, receivedAnswer, receivedAnswerPar, NULL);
|
||||||
if (len == 1) {
|
if (len == 1) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd Error: %02x", receivedAnswer[0]);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Cmd Error: %02x", receivedAnswer[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (len != 18) {
|
if (len != 18) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd Error: card timeout. len: %x", len);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Cmd Error: card timeout. len: %x", len);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(bt, receivedAnswer + 16, 2);
|
memcpy(bt, receivedAnswer + 16, 2);
|
||||||
AddCrc14A(receivedAnswer, 16);
|
AddCrc14A(receivedAnswer, 16);
|
||||||
if (bt[0] != receivedAnswer[16] || bt[1] != receivedAnswer[17]) {
|
if (bt[0] != receivedAnswer[16] || bt[1] != receivedAnswer[17]) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd CRC response error.");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Cmd CRC response error.");
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,7 +416,7 @@ int mifare_classic_writeblock(struct Crypto1State *pcs, uint32_t uid, uint8_t bl
|
||||||
len = mifare_sendcmd_short(pcs, 1, ISO14443A_CMD_WRITEBLOCK, blockNo, receivedAnswer, receivedAnswerPar, NULL);
|
len = mifare_sendcmd_short(pcs, 1, ISO14443A_CMD_WRITEBLOCK, blockNo, receivedAnswer, receivedAnswerPar, NULL);
|
||||||
|
|
||||||
if ((len != 1) || (receivedAnswer[0] != 0x0A)) { // 0x0a - ACK
|
if ((len != 1) || (receivedAnswer[0] != 0x0A)) { // 0x0a - ACK
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd Error: %02x", receivedAnswer[0]);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Cmd Error: %02x", receivedAnswer[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -441,7 +441,7 @@ int mifare_classic_writeblock(struct Crypto1State *pcs, uint32_t uid, uint8_t bl
|
||||||
res |= (crypto1_bit(pcs, 0, 0) ^ BIT(receivedAnswer[0], 3)) << 3;
|
res |= (crypto1_bit(pcs, 0, 0) ^ BIT(receivedAnswer[0], 3)) << 3;
|
||||||
|
|
||||||
if ((len != 1) || (res != 0x0A)) {
|
if ((len != 1) || (res != 0x0A)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Cmd send data2 Error: %02x", res);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Cmd send data2 Error: %02x", res);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -458,7 +458,7 @@ int mifare_ultra_writeblock_compat(uint8_t blockNo, uint8_t *blockData) {
|
||||||
len = mifare_sendcmd_short(NULL, CRYPT_NONE, ISO14443A_CMD_WRITEBLOCK, blockNo, receivedAnswer, receivedAnswerPar, NULL);
|
len = mifare_sendcmd_short(NULL, CRYPT_NONE, ISO14443A_CMD_WRITEBLOCK, blockNo, receivedAnswer, receivedAnswerPar, NULL);
|
||||||
|
|
||||||
if (receivedAnswer[0] != 0x0A) { // 0x0a - ACK
|
if (receivedAnswer[0] != 0x0A) { // 0x0a - ACK
|
||||||
if (DBGLEVEL >= DBG_ERROR)
|
if (g_dbglevel >= DBG_ERROR)
|
||||||
Dbprintf("Cmd Send Error: %02x %d", receivedAnswer[0], len);
|
Dbprintf("Cmd Send Error: %02x %d", receivedAnswer[0], len);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -472,7 +472,7 @@ int mifare_ultra_writeblock_compat(uint8_t blockNo, uint8_t *blockData) {
|
||||||
len = ReaderReceive(receivedAnswer, receivedAnswerPar);
|
len = ReaderReceive(receivedAnswer, receivedAnswerPar);
|
||||||
|
|
||||||
if (receivedAnswer[0] != 0x0A) { // 0x0a - ACK
|
if (receivedAnswer[0] != 0x0A) { // 0x0a - ACK
|
||||||
if (DBGLEVEL >= DBG_ERROR)
|
if (g_dbglevel >= DBG_ERROR)
|
||||||
Dbprintf("Cmd Send Data Error: %02x %d", receivedAnswer[0], len);
|
Dbprintf("Cmd Send Data Error: %02x %d", receivedAnswer[0], len);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
@ -491,7 +491,7 @@ int mifare_ultra_writeblock(uint8_t blockNo, uint8_t *blockData) {
|
||||||
len = mifare_sendcmd(MIFARE_ULC_WRITE, block, sizeof(block), receivedAnswer, receivedAnswerPar, NULL);
|
len = mifare_sendcmd(MIFARE_ULC_WRITE, block, sizeof(block), receivedAnswer, receivedAnswerPar, NULL);
|
||||||
|
|
||||||
if (receivedAnswer[0] != 0x0A) { // 0x0a - ACK
|
if (receivedAnswer[0] != 0x0A) { // 0x0a - ACK
|
||||||
if (DBGLEVEL >= DBG_ERROR)
|
if (g_dbglevel >= DBG_ERROR)
|
||||||
Dbprintf("Cmd Send Error: %02x %d", receivedAnswer[0], len);
|
Dbprintf("Cmd Send Error: %02x %d", receivedAnswer[0], len);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -501,7 +501,7 @@ int mifare_classic_halt_ex(struct Crypto1State *pcs) {
|
||||||
uint8_t receivedAnswer[4] = {0x00, 0x00, 0x00, 0x00};
|
uint8_t receivedAnswer[4] = {0x00, 0x00, 0x00, 0x00};
|
||||||
uint16_t len = mifare_sendcmd_short(pcs, (pcs == NULL) ? CRYPT_NONE : CRYPT_ALL, ISO14443A_CMD_HALT, 0x00, receivedAnswer, NULL, NULL);
|
uint16_t len = mifare_sendcmd_short(pcs, (pcs == NULL) ? CRYPT_NONE : CRYPT_ALL, ISO14443A_CMD_HALT, 0x00, receivedAnswer, NULL, NULL);
|
||||||
if (len != 0) {
|
if (len != 0) {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("halt warning. response len: %x", len);
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("halt warning. response len: %x", len);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -515,7 +515,7 @@ int mifare_ultra_halt(void) {
|
||||||
uint8_t receivedAnswer[4] = {0x00, 0x00, 0x00, 0x00};
|
uint8_t receivedAnswer[4] = {0x00, 0x00, 0x00, 0x00};
|
||||||
len = mifare_sendcmd_short(NULL, CRYPT_NONE, ISO14443A_CMD_HALT, 0x00, receivedAnswer, NULL, NULL);
|
len = mifare_sendcmd_short(NULL, CRYPT_NONE, ISO14443A_CMD_HALT, 0x00, receivedAnswer, NULL, NULL);
|
||||||
if (len != 0) {
|
if (len != 0) {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("halt warning. response len: %x", len);
|
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("halt warning. response len: %x", len);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -624,11 +624,11 @@ void emlClearMem(void) {
|
||||||
|
|
||||||
uint8_t SectorTrailer(uint8_t blockNo) {
|
uint8_t SectorTrailer(uint8_t blockNo) {
|
||||||
if (blockNo <= MIFARE_2K_MAXBLOCK) {
|
if (blockNo <= MIFARE_2K_MAXBLOCK) {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("Sector Trailer for block %d : %d", blockNo, (blockNo | 0x03));
|
Dbprintf("Sector Trailer for block %d : %d", blockNo, (blockNo | 0x03));
|
||||||
return (blockNo | 0x03);
|
return (blockNo | 0x03);
|
||||||
} else {
|
} else {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("Sector Trailer for block %d : %d", blockNo, (blockNo | 0x0f));
|
Dbprintf("Sector Trailer for block %d : %d", blockNo, (blockNo | 0x0f));
|
||||||
return (blockNo | 0x0f);
|
return (blockNo | 0x0f);
|
||||||
}
|
}
|
||||||
|
@ -646,7 +646,7 @@ int mifare_sendcmd_special(struct Crypto1State *pcs, uint8_t crypted, uint8_t cm
|
||||||
ReaderTransmit(dcmd, sizeof(dcmd), NULL);
|
ReaderTransmit(dcmd, sizeof(dcmd), NULL);
|
||||||
int len = ReaderReceive(answer, answer_parity);
|
int len = ReaderReceive(answer, answer_parity);
|
||||||
if (!len) {
|
if (!len) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Authentication failed. Card timeout.");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Authentication failed. Card timeout.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return len;
|
return len;
|
||||||
|
@ -661,7 +661,7 @@ int mifare_sendcmd_special2(struct Crypto1State *pcs, uint8_t crypted, uint8_t c
|
||||||
ReaderTransmit(dcmd, sizeof(dcmd), NULL);
|
ReaderTransmit(dcmd, sizeof(dcmd), NULL);
|
||||||
int len = ReaderReceive(answer, answer_parity);
|
int len = ReaderReceive(answer, answer_parity);
|
||||||
if (!len) {
|
if (!len) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Authentication failed. Card timeout.");
|
if (g_dbglevel >= DBG_ERROR) Dbprintf("Authentication failed. Card timeout.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return len;
|
return len;
|
||||||
|
@ -677,13 +677,13 @@ int mifare_desfire_des_auth1(uint32_t uid, uint8_t *blockData) {
|
||||||
|
|
||||||
len = mifare_sendcmd_special(NULL, 1, 0x02, data, receivedAnswer, receivedAnswerPar, NULL);
|
len = mifare_sendcmd_special(NULL, 1, 0x02, data, receivedAnswer, receivedAnswerPar, NULL);
|
||||||
if (len == 1) {
|
if (len == 1) {
|
||||||
if (DBGLEVEL >= DBG_ERROR)
|
if (g_dbglevel >= DBG_ERROR)
|
||||||
Dbprintf("Cmd Error: %02x", receivedAnswer[0]);
|
Dbprintf("Cmd Error: %02x", receivedAnswer[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len == 12) {
|
if (len == 12) {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
Dbprintf("Auth1 Resp: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
Dbprintf("Auth1 Resp: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
||||||
receivedAnswer[0], receivedAnswer[1], receivedAnswer[2], receivedAnswer[3], receivedAnswer[4],
|
receivedAnswer[0], receivedAnswer[1], receivedAnswer[2], receivedAnswer[3], receivedAnswer[4],
|
||||||
receivedAnswer[5], receivedAnswer[6], receivedAnswer[7], receivedAnswer[8], receivedAnswer[9],
|
receivedAnswer[5], receivedAnswer[6], receivedAnswer[7], receivedAnswer[8], receivedAnswer[9],
|
||||||
|
@ -707,13 +707,13 @@ int mifare_desfire_des_auth2(uint32_t uid, uint8_t *key, uint8_t *blockData) {
|
||||||
len = mifare_sendcmd_special2(NULL, 1, 0x03, data, receivedAnswer, receivedAnswerPar, NULL);
|
len = mifare_sendcmd_special2(NULL, 1, 0x03, data, receivedAnswer, receivedAnswerPar, NULL);
|
||||||
|
|
||||||
if ((receivedAnswer[0] == 0x03) && (receivedAnswer[1] == 0xae)) {
|
if ((receivedAnswer[0] == 0x03) && (receivedAnswer[1] == 0xae)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR)
|
if (g_dbglevel >= DBG_ERROR)
|
||||||
Dbprintf("Auth Error: %02x %02x", receivedAnswer[0], receivedAnswer[1]);
|
Dbprintf("Auth Error: %02x %02x", receivedAnswer[0], receivedAnswer[1]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len == 12) {
|
if (len == 12) {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
Dbprintf("Auth2 Resp: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
Dbprintf("Auth2 Resp: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
||||||
receivedAnswer[0], receivedAnswer[1], receivedAnswer[2], receivedAnswer[3], receivedAnswer[4],
|
receivedAnswer[0], receivedAnswer[1], receivedAnswer[2], receivedAnswer[3], receivedAnswer[4],
|
||||||
receivedAnswer[5], receivedAnswer[6], receivedAnswer[7], receivedAnswer[8], receivedAnswer[9],
|
receivedAnswer[5], receivedAnswer[6], receivedAnswer[7], receivedAnswer[8], receivedAnswer[9],
|
||||||
|
|
|
@ -102,7 +102,7 @@ size_t DemodPCF7931(uint8_t **outBlocks) {
|
||||||
// Error
|
// Error
|
||||||
if (++warnings > 10) {
|
if (++warnings > 10) {
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (g_dbglevel >= DBG_EXTENDED) {
|
||||||
Dbprintf("Error: too many detection errors, aborting");
|
Dbprintf("Error: too many detection errors, aborting");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,7 +218,7 @@ void ReadPCF7931(void) {
|
||||||
// exit if no block is received
|
// exit if no block is received
|
||||||
if (errors >= 10 && found_blocks == 0 && single_blocks_cnt == 0) {
|
if (errors >= 10 && found_blocks == 0 && single_blocks_cnt == 0) {
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_INFO)
|
if (g_dbglevel >= DBG_INFO)
|
||||||
Dbprintf("[!!] Error, no tag or bad tag");
|
Dbprintf("[!!] Error, no tag or bad tag");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -226,7 +226,7 @@ void ReadPCF7931(void) {
|
||||||
// exit if too many errors during reading
|
// exit if too many errors during reading
|
||||||
if (tries > 50 && (2 * errors > tries)) {
|
if (tries > 50 && (2 * errors > tries)) {
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_INFO) {
|
if (g_dbglevel >= DBG_INFO) {
|
||||||
Dbprintf("[!!] Error reading the tag, only partial content");
|
Dbprintf("[!!] Error reading the tag, only partial content");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,7 +258,7 @@ void ReadPCF7931(void) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("(dbg) got %d blocks (%d/%d found) (%d tries, %d errors)", n, found_blocks, (max_blocks == 0 ? found_blocks : max_blocks), tries, errors);
|
Dbprintf("(dbg) got %d blocks (%d/%d found) (%d tries, %d errors)", n, found_blocks, (max_blocks == 0 ? found_blocks : max_blocks), tries, errors);
|
||||||
|
|
||||||
for (i = 0; i < n; ++i) {
|
for (i = 0; i < n; ++i) {
|
||||||
|
@ -322,7 +322,7 @@ void ReadPCF7931(void) {
|
||||||
}
|
}
|
||||||
++tries;
|
++tries;
|
||||||
if (BUTTON_PRESS()) {
|
if (BUTTON_PRESS()) {
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (g_dbglevel >= DBG_EXTENDED)
|
||||||
Dbprintf("Button pressed, stopping.");
|
Dbprintf("Button pressed, stopping.");
|
||||||
|
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -437,7 +437,7 @@ static void RealWritePCF7931(uint8_t *pass, uint16_t init_delay, int32_t l, int3
|
||||||
*/
|
*/
|
||||||
void WritePCF7931(uint8_t pass1, uint8_t pass2, uint8_t pass3, uint8_t pass4, uint8_t pass5, uint8_t pass6, uint8_t pass7, uint16_t init_delay, int32_t l, int32_t p, uint8_t address, uint8_t byte, uint8_t data) {
|
void WritePCF7931(uint8_t pass1, uint8_t pass2, uint8_t pass3, uint8_t pass4, uint8_t pass5, uint8_t pass6, uint8_t pass7, uint16_t init_delay, int32_t l, int32_t p, uint8_t address, uint8_t byte, uint8_t data) {
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_INFO) {
|
if (g_dbglevel >= DBG_INFO) {
|
||||||
Dbprintf("Initialization delay : %d us", init_delay);
|
Dbprintf("Initialization delay : %d us", init_delay);
|
||||||
Dbprintf("Offsets : %d us on the low pulses width, %d us on the low pulses positions", l, p);
|
Dbprintf("Offsets : %d us on the low pulses width, %d us on the low pulses positions", l, p);
|
||||||
}
|
}
|
||||||
|
@ -460,7 +460,7 @@ void WritePCF7931(uint8_t pass1, uint8_t pass2, uint8_t pass3, uint8_t pass4, ui
|
||||||
void SendCmdPCF7931(uint32_t *tab) {
|
void SendCmdPCF7931(uint32_t *tab) {
|
||||||
uint16_t u = 0, tempo = 0;
|
uint16_t u = 0, tempo = 0;
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_INFO) {
|
if (g_dbglevel >= DBG_INFO) {
|
||||||
Dbprintf("Sending data frame...");
|
Dbprintf("Sending data frame...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ static s32_t rdv40_spiffs_llerase(u32_t addr, u32_t size) {
|
||||||
return 130;
|
return 130;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_DEBUG) Dbprintf("LLERASEDBG : Orig addr : %d\n", addr);
|
if (g_dbglevel >= DBG_DEBUG) Dbprintf("LLERASEDBG : Orig addr : %d\n", addr);
|
||||||
|
|
||||||
uint8_t block, sector = 0;
|
uint8_t block, sector = 0;
|
||||||
block = addr / RDV40_LLERASE_BLOCKSIZE;
|
block = addr / RDV40_LLERASE_BLOCKSIZE;
|
||||||
|
@ -81,13 +81,13 @@ static s32_t rdv40_spiffs_llerase(u32_t addr, u32_t size) {
|
||||||
addr = addr - (block * RDV40_LLERASE_BLOCKSIZE);
|
addr = addr - (block * RDV40_LLERASE_BLOCKSIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_DEBUG) Dbprintf("LLERASEDBG : Result addr : %d\n", addr);
|
if (g_dbglevel >= DBG_DEBUG) Dbprintf("LLERASEDBG : Result addr : %d\n", addr);
|
||||||
|
|
||||||
sector = addr / SPIFFS_CFG_LOG_BLOCK_SZ;
|
sector = addr / SPIFFS_CFG_LOG_BLOCK_SZ;
|
||||||
Flash_CheckBusy(BUSY_TIMEOUT);
|
Flash_CheckBusy(BUSY_TIMEOUT);
|
||||||
Flash_WriteEnable();
|
Flash_WriteEnable();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_DEBUG) Dbprintf("LLERASEDBG : block : %d, sector : %d \n", block, sector);
|
if (g_dbglevel >= DBG_DEBUG) Dbprintf("LLERASEDBG : block : %d, sector : %d \n", block, sector);
|
||||||
|
|
||||||
erased = Flash_Erase4k(block, sector);
|
erased = Flash_Erase4k(block, sector);
|
||||||
Flash_CheckBusy(BUSY_TIMEOUT);
|
Flash_CheckBusy(BUSY_TIMEOUT);
|
||||||
|
@ -252,7 +252,7 @@ static RDV40SpiFFSFileType filetype_in_spiffs(const char *filename) {
|
||||||
filetype = RDV40_SPIFFS_FILETYPE_SYMLINK;
|
filetype = RDV40_SPIFFS_FILETYPE_SYMLINK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (DBGLEVEL >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
switch (filetype) {
|
switch (filetype) {
|
||||||
case RDV40_SPIFFS_FILETYPE_REAL:
|
case RDV40_SPIFFS_FILETYPE_REAL:
|
||||||
Dbprintf("Filetype is : RDV40_SPIFFS_FILETYPE_REAL");
|
Dbprintf("Filetype is : RDV40_SPIFFS_FILETYPE_REAL");
|
||||||
|
@ -478,12 +478,12 @@ int rdv40_spiffs_read_as_symlink(char *filename, uint8_t *dst, uint32_t size, RD
|
||||||
char linkfilename[SPIFFS_OBJ_NAME_LEN];
|
char linkfilename[SPIFFS_OBJ_NAME_LEN];
|
||||||
sprintf(linkfilename, "%s.lnk", filename);
|
sprintf(linkfilename, "%s.lnk", filename);
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_DEBUG)
|
if (g_dbglevel >= DBG_DEBUG)
|
||||||
Dbprintf("Linkk real filename is : " _YELLOW_("%s"), linkfilename);
|
Dbprintf("Linkk real filename is : " _YELLOW_("%s"), linkfilename);
|
||||||
|
|
||||||
read_from_spiffs((char *)linkfilename, (uint8_t *)linkdest, SPIFFS_OBJ_NAME_LEN);
|
read_from_spiffs((char *)linkfilename, (uint8_t *)linkdest, SPIFFS_OBJ_NAME_LEN);
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_DEBUG)
|
if (g_dbglevel >= DBG_DEBUG)
|
||||||
Dbprintf("Symlink destination is : " _YELLOW_("%s"), linkdest);
|
Dbprintf("Symlink destination is : " _YELLOW_("%s"), linkdest);
|
||||||
|
|
||||||
read_from_spiffs((char *)linkdest, (uint8_t *)dst, size);
|
read_from_spiffs((char *)linkdest, (uint8_t *)dst, size);
|
||||||
|
|
|
@ -65,7 +65,7 @@ void SpinDelayUs(int us) {
|
||||||
// WARNING: timer can't measure more than 1.39s (21.3us * 0xffff)
|
// WARNING: timer can't measure more than 1.39s (21.3us * 0xffff)
|
||||||
void SpinDelay(int ms) {
|
void SpinDelay(int ms) {
|
||||||
if (ms > 1390) {
|
if (ms > 1390) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf(_RED_("Error, SpinDelay called with %i > 1390"), ms);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf(_RED_("Error, SpinDelay called with %i > 1390"), ms);
|
||||||
ms = 1390;
|
ms = 1390;
|
||||||
}
|
}
|
||||||
// convert to us and call microsecond delay function
|
// convert to us and call microsecond delay function
|
||||||
|
|
|
@ -189,7 +189,7 @@ int BUTTON_CLICKED(int ms) {
|
||||||
// timer counts in 21.3us increments (1024/48MHz)
|
// timer counts in 21.3us increments (1024/48MHz)
|
||||||
// WARNING: timer can't measure more than 1.39s (21.3us * 0xffff)
|
// WARNING: timer can't measure more than 1.39s (21.3us * 0xffff)
|
||||||
if (ms > 1390) {
|
if (ms > 1390) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf(_RED_("Error, BUTTON_CLICKED called with %i > 1390"), ms);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf(_RED_("Error, BUTTON_CLICKED called with %i > 1390"), ms);
|
||||||
ms = 1390;
|
ms = 1390;
|
||||||
}
|
}
|
||||||
int ticks = ((MCK / 1000) * (ms ? ms : 1000)) >> 10;
|
int ticks = ((MCK / 1000) * (ms ? ms : 1000)) >> 10;
|
||||||
|
@ -252,7 +252,7 @@ int BUTTON_HELD(int ms) {
|
||||||
// timer counts in 21.3us increments (1024/48MHz)
|
// timer counts in 21.3us increments (1024/48MHz)
|
||||||
// WARNING: timer can't measure more than 1.39s (21.3us * 0xffff)
|
// WARNING: timer can't measure more than 1.39s (21.3us * 0xffff)
|
||||||
if (ms > 1390) {
|
if (ms > 1390) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf(_RED_("Error, BUTTON_HELD called with %i > 1390"), ms);
|
if (g_dbglevel >= DBG_ERROR) Dbprintf(_RED_("Error, BUTTON_HELD called with %i > 1390"), ms);
|
||||||
ms = 1390;
|
ms = 1390;
|
||||||
}
|
}
|
||||||
// If button is held for one second
|
// If button is held for one second
|
||||||
|
|
|
@ -54,11 +54,11 @@ struct version_information_t {
|
||||||
#define DBG_INFO 2 // errors + info messages
|
#define DBG_INFO 2 // errors + info messages
|
||||||
#define DBG_DEBUG 3 // errors + info + debug messages
|
#define DBG_DEBUG 3 // errors + info + debug messages
|
||||||
#define DBG_EXTENDED 4 // errors + info + debug + breaking debug messages
|
#define DBG_EXTENDED 4 // errors + info + debug + breaking debug messages
|
||||||
extern int DBGLEVEL;
|
extern int g_dbglevel;
|
||||||
|
|
||||||
// tear-off
|
// tear-off
|
||||||
extern uint16_t tearoff_delay_us;
|
extern uint16_t g_tearoff_delay_us;
|
||||||
extern bool tearoff_enabled;
|
extern bool g_tearoff_enabled;
|
||||||
|
|
||||||
// reader voltage field detector
|
// reader voltage field detector
|
||||||
#define MF_MINFIELDV 4000
|
#define MF_MINFIELDV 4000
|
||||||
|
|
|
@ -60,8 +60,8 @@ typedef struct {
|
||||||
uint8_t byte[4];
|
uint8_t byte[4];
|
||||||
} PACKED em4x50_word_t;
|
} PACKED em4x50_word_t;
|
||||||
|
|
||||||
extern bool gLogin;
|
extern bool g_Login;
|
||||||
extern bool gWritePasswordProcess;
|
extern bool g_WritePasswordProcess;
|
||||||
extern uint32_t gPassword;
|
extern uint32_t g_Password;
|
||||||
|
|
||||||
#endif /* EM4X50_H__ */
|
#endif /* EM4X50_H__ */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue