mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-07-16 10:03:04 -07:00
make style
This commit is contained in:
parent
8a602ed99d
commit
4ed57c7c4d
57 changed files with 878 additions and 878 deletions
|
@ -159,8 +159,8 @@ void BigBuf_print_status(void) {
|
|||
Dbprintf(" traceLen ...............%d", trace_len);
|
||||
|
||||
Dbprintf(" dma8 memory.............%d", dma_8.buf - BigBuf_get_addr());
|
||||
Dbprintf(" dma16 memory............%d", (uint8_t*)dma_16.buf - BigBuf_get_addr());
|
||||
Dbprintf(" toSend memory...........%d", toSend.buf - BigBuf_get_addr() );
|
||||
Dbprintf(" dma16 memory............%d", (uint8_t *)dma_16.buf - BigBuf_get_addr());
|
||||
Dbprintf(" toSend memory...........%d", toSend.buf - BigBuf_get_addr());
|
||||
}
|
||||
|
||||
// return the maximum trace length (i.e. the unallocated size of BigBuf)
|
||||
|
@ -229,7 +229,7 @@ bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_
|
|||
*/
|
||||
duration = 0;
|
||||
}
|
||||
|
||||
|
||||
hdr->timestamp = timestamp_start;
|
||||
hdr->duration = duration & 0xFFFF;
|
||||
hdr->data_len = iLen;
|
||||
|
@ -309,7 +309,7 @@ void tosend_stuffbit(int b) {
|
|||
|
||||
dmabuf16_t *get_dma16(void) {
|
||||
if (dma_16.buf == NULL)
|
||||
dma_16.buf = (uint16_t*)BigBuf_malloc(DMA_BUFFER_SIZE * sizeof(uint16_t));
|
||||
dma_16.buf = (uint16_t *)BigBuf_malloc(DMA_BUFFER_SIZE * sizeof(uint16_t));
|
||||
|
||||
return &dma_16;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#define DMA_BUFFER_SIZE 256
|
||||
|
||||
// 8 data bits and 1 parity bit per payload byte, 1 correction bit, 1 SOC bit, 2 EOC bits
|
||||
#define TOSEND_BUFFER_SIZE (9 * MAX_FRAME_SIZE + 1 + 1 + 2)
|
||||
#define TOSEND_BUFFER_SIZE (9 * MAX_FRAME_SIZE + 1 + 1 + 2)
|
||||
|
||||
uint8_t *BigBuf_get_addr(void);
|
||||
uint32_t BigBuf_get_size(void);
|
||||
|
|
|
@ -30,7 +30,7 @@ SRC_ISO14443b = iso14443b.c
|
|||
SRC_FELICA = felica.c
|
||||
SRC_CRAPTO1 = crypto1.c des.c desfire_crypto.c mifaredesfire.c aes.c platform_util.c
|
||||
SRC_CRC = crc.c crc16.c crc32.c
|
||||
SRC_ICLASS = iclass.c optimized_cipherutils.c optimized_ikeys.c optimized_elite.c optimized_cipher.c
|
||||
SRC_ICLASS = iclass.c optimized_cipherutils.c optimized_ikeys.c optimized_elite.c optimized_cipher.c
|
||||
SRC_LEGIC = legicrf.c legicrfsim.c legic_prng.c
|
||||
SRC_NFCBARCODE = thinfilm.c
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
|
||||
#define HF_ICLASS_CC_A "iceclass_cc_a.bin"
|
||||
#define HF_ICLASS_CC_B "iceclass_cc_b.bin"
|
||||
char* cc_files[] = { HF_ICLASS_CC_A, HF_ICLASS_CC_B };
|
||||
char *cc_files[] = { HF_ICLASS_CC_A, HF_ICLASS_CC_B };
|
||||
|
||||
|
||||
|
||||
|
@ -65,7 +65,7 @@ char* cc_files[] = { HF_ICLASS_CC_A, HF_ICLASS_CC_B };
|
|||
#endif
|
||||
|
||||
// iclass card descriptors
|
||||
char * card_types[] = {
|
||||
char *card_types[] = {
|
||||
"PicoPass 16K / 16", // 000
|
||||
"PicoPass 32K with current book 16K / 16", // 001
|
||||
"Unknown Card Type!", // 010
|
||||
|
@ -112,13 +112,13 @@ static uint8_t csns[8 * NUM_CSNS] = {
|
|||
|
||||
static void download_instructions(uint8_t t) {
|
||||
DbpString("");
|
||||
switch (t) {
|
||||
switch (t) {
|
||||
case ICE_STATE_FULLSIM: {
|
||||
DbpString("The emulator memory was saved to SPIFFS");
|
||||
DbpString("1. " _YELLOW_("mem spiffs dump o " HF_ICLASS_FULLSIM_MOD_BIN " f " HF_ICLASS_FULLSIM_MOD" e"));
|
||||
DbpString("2. " _YELLOW_("hf iclass view f " HF_ICLASS_FULLSIM_MOD_BIN));
|
||||
break;
|
||||
}
|
||||
}
|
||||
case ICE_STATE_ATTACK: {
|
||||
DbpString("The collected data was saved to SPIFFS. The file names below may differ");
|
||||
DbpString("1. " _YELLOW_("mem spiffs tree"));
|
||||
|
@ -143,9 +143,9 @@ static void save_to_flash(uint8_t *data, uint16_t datalen) {
|
|||
|
||||
char fn[SPIFFS_OBJ_NAME_LEN];
|
||||
sprintf(fn, "iclass-%02X%02X%02X%02X%02X%02X%02X%02X.bin",
|
||||
data[0], data[1], data[2], data[3],
|
||||
data[4], data[5], data[6], data[7]
|
||||
);
|
||||
data[0], data[1], data[2], data[3],
|
||||
data[4], data[5], data[6], data[7]
|
||||
);
|
||||
|
||||
int res;
|
||||
if (exists_in_spiffs(fn) == false) {
|
||||
|
@ -185,7 +185,7 @@ static int fullsim_mode(void) {
|
|||
Dbprintf("loaded " _GREEN_(HF_ICLASS_FULLSIM_ORIG_BIN) " (%u bytes)", fsize);
|
||||
}
|
||||
|
||||
iclass_simulate(ICLASS_SIM_MODE_FULL, 0 , false, NULL, NULL, NULL);
|
||||
iclass_simulate(ICLASS_SIM_MODE_FULL, 0, false, NULL, NULL, NULL);
|
||||
|
||||
LED_B_ON();
|
||||
rdv40_spiffs_lazy_mount();
|
||||
|
@ -252,7 +252,7 @@ static int reader_attack_mode(void) {
|
|||
rdv40_spiffs_lazy_unmount();
|
||||
LED_B_OFF();
|
||||
if (res == SPIFFS_OK) {
|
||||
Dbprintf("saved to " _GREEN_("%s"), fn);
|
||||
Dbprintf("saved to " _GREEN_("%s"), fn);
|
||||
} else {
|
||||
Dbprintf(_RED_("error") " writing %s to flash ( %d )", fn, res);
|
||||
}
|
||||
|
@ -280,7 +280,7 @@ static int reader_dump_mode(void) {
|
|||
break;
|
||||
}
|
||||
|
||||
// setup authenticate AA1
|
||||
// setup authenticate AA1
|
||||
iclass_auth_req_t auth = {
|
||||
.use_raw = false,
|
||||
.use_elite = false,
|
||||
|
@ -334,7 +334,7 @@ static int reader_dump_mode(void) {
|
|||
res = authenticate_iclass_tag(&auth, hdr, &start_time, &eof_time, NULL);
|
||||
if (res == false) {
|
||||
switch_off();
|
||||
Dbprintf( _RED_("failed AA1 auth") ", skipping ");
|
||||
Dbprintf(_RED_("failed AA1 auth") ", skipping ");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -389,7 +389,7 @@ static int reader_dump_mode(void) {
|
|||
}
|
||||
}
|
||||
switch_off();
|
||||
save_to_flash(card_data, (start_block + dumped) * 8 );
|
||||
save_to_flash(card_data, (start_block + dumped) * 8);
|
||||
Dbprintf("%u bytes saved", (start_block + dumped) * 8);
|
||||
}
|
||||
DbpString("-=[ exiting " _CYAN_("`read & dump`") " mode ]=-");
|
||||
|
@ -409,7 +409,7 @@ static int config_sim_mode(void) {
|
|||
|
||||
if (res == SPIFFS_OK) {
|
||||
Dbprintf("loaded " _GREEN_("%s") " (%u bytes) to emulator memory", cc_files[i], fsize);
|
||||
iclass_simulate(ICLASS_SIM_MODE_FULL, 0 , false, NULL, NULL, NULL);
|
||||
iclass_simulate(ICLASS_SIM_MODE_FULL, 0, false, NULL, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -490,7 +490,7 @@ void RunMod(void) {
|
|||
|
||||
// Look for config cards
|
||||
rdv40_spiffs_lazy_mount();
|
||||
for (uint8_t i =0; i < 2; i++) {
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
if (exists_in_spiffs(cc_files[i]) == false) {
|
||||
Dbprintf(_RED_("error") ", " _YELLOW_("%s") " file missing", cc_files[i]);
|
||||
mode = ICE_STATE_NONE;
|
||||
|
|
|
@ -64,12 +64,12 @@ static void fillbuff(uint8_t bit) {
|
|||
}
|
||||
|
||||
static void construct_EM410x_emul(uint64_t id) {
|
||||
|
||||
|
||||
int i, j;
|
||||
int binary[4] = {0};
|
||||
int parity[4] = {0};
|
||||
buflen = 0;
|
||||
|
||||
|
||||
for (i = 0; i < 9; i++)
|
||||
fillbuff(1);
|
||||
|
||||
|
|
|
@ -295,7 +295,7 @@ static void TimingIntervalAcquisition(void) {
|
|||
|
||||
static void print_debug_level(void) {
|
||||
char dbglvlstr[20] = {0};
|
||||
switch(DBGLEVEL) {
|
||||
switch (DBGLEVEL) {
|
||||
case DBG_NONE:
|
||||
sprintf(dbglvlstr, "NONE");
|
||||
break;
|
||||
|
@ -308,7 +308,7 @@ static void print_debug_level(void) {
|
|||
case DBG_DEBUG:
|
||||
sprintf(dbglvlstr, "DEBUG");
|
||||
break;
|
||||
case DBG_EXTENDED:
|
||||
case DBG_EXTENDED:
|
||||
sprintf(dbglvlstr, "EXTENDED");
|
||||
break;
|
||||
}
|
||||
|
@ -362,9 +362,9 @@ static void SendStatus(void) {
|
|||
|
||||
print_stack_usage();
|
||||
print_debug_level();
|
||||
|
||||
|
||||
tosend_t *ts = get_tosend();
|
||||
Dbprintf(" ToSendMax...............%d", ts->max );
|
||||
Dbprintf(" ToSendMax...............%d", ts->max);
|
||||
Dbprintf(" ToSend BUFFERSIZE.......%d", TOSEND_BUFFER_SIZE);
|
||||
while ((AT91C_BASE_PMC->PMC_MCFR & AT91C_CKGR_MAINRDY) == 0); // Wait for MAINF value to become available...
|
||||
uint16_t mainf = AT91C_BASE_PMC->PMC_MCFR & AT91C_CKGR_MAINF; // Get # main clocks within 16 slow clocks
|
||||
|
|
278
armsrc/em4x50.c
278
armsrc/em4x50.c
|
@ -113,7 +113,7 @@ static uint8_t bits2byte(uint8_t *bits, int length) {
|
|||
|
||||
byte |= bits[i];
|
||||
|
||||
if (i != length-1)
|
||||
if (i != length - 1)
|
||||
byte <<= 1;
|
||||
}
|
||||
|
||||
|
@ -145,17 +145,17 @@ static void save_word(int pos, uint8_t bits[EM4X50_TAG_WORD]) {
|
|||
|
||||
// data and row parities
|
||||
for (int i = 0; i < 4; i++) {
|
||||
tag.sectors[pos][i] = bits2byte(&bits[9*i],8);
|
||||
row_parity[i] = bits[9*i+8];
|
||||
tag.sectors[pos][i] = bits2byte(&bits[9 * i], 8);
|
||||
row_parity[i] = bits[9 * i + 8];
|
||||
}
|
||||
|
||||
tag.sectors[pos][4] = bits2byte(row_parity,4);
|
||||
tag.sectors[pos][4] = bits2byte(row_parity, 4);
|
||||
|
||||
// column parities
|
||||
for (int i = 0; i < 8; i++)
|
||||
col_parity[i] = bits[36+i];
|
||||
col_parity[i] = bits[36 + i];
|
||||
|
||||
tag.sectors[pos][5] = bits2byte(col_parity,8);
|
||||
tag.sectors[pos][5] = bits2byte(col_parity, 8);
|
||||
|
||||
// stop bit
|
||||
tag.sectors[pos][6] = bits[44];
|
||||
|
@ -311,13 +311,13 @@ static int get_next_bit(void) {
|
|||
}
|
||||
|
||||
static uint32_t get_pulse_length(void) {
|
||||
|
||||
|
||||
// iterates pulse length (low -> high -> low)
|
||||
|
||||
|
||||
uint8_t sample = 0;
|
||||
|
||||
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
|
||||
|
||||
while (sample > gLow)
|
||||
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
|
||||
|
@ -333,20 +333,20 @@ static uint32_t get_pulse_length(void) {
|
|||
}
|
||||
|
||||
static bool check_pulse_length(uint32_t pl, int length) {
|
||||
|
||||
|
||||
// check if pulse length <pl> corresponds to given length <length>
|
||||
|
||||
|
||||
if ((pl >= T0 * (length - EM4X50_TAG_TOLERANCE)) &
|
||||
(pl <= T0 * (length + EM4X50_TAG_TOLERANCE)))
|
||||
(pl <= T0 * (length + EM4X50_TAG_TOLERANCE)))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
static void em4x50_send_bit(int bit) {
|
||||
|
||||
|
||||
// send single bit according to EM4x50 application note and datasheet
|
||||
|
||||
|
||||
// reset clock for the next bit
|
||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
|
||||
|
||||
|
@ -361,13 +361,13 @@ static void em4x50_send_bit(int bit) {
|
|||
// half of bit period
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * EM4X50_T_TAG_HALF_PERIOD);
|
||||
|
||||
|
||||
// disable modulation for second half of bit period
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * EM4X50_T_TAG_FULL_PERIOD);
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
// bit = "1" means disable modulation for full bit period
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * EM4X50_T_TAG_FULL_PERIOD);
|
||||
|
@ -377,20 +377,20 @@ static void em4x50_send_bit(int bit) {
|
|||
static void em4x50_send_byte(uint8_t byte) {
|
||||
|
||||
// send byte (without parity)
|
||||
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
em4x50_send_bit((byte >> (7-i)) & 1);
|
||||
em4x50_send_bit((byte >> (7 - i)) & 1);
|
||||
|
||||
}
|
||||
|
||||
static void em4x50_send_byte_with_parity(uint8_t byte) {
|
||||
|
||||
// send byte followed by its (equal) parity bit
|
||||
|
||||
|
||||
int parity = 0, bit = 0;
|
||||
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
bit = (byte >> (7-i)) & 1;
|
||||
bit = (byte >> (7 - i)) & 1;
|
||||
em4x50_send_bit(bit);
|
||||
parity ^= bit;
|
||||
}
|
||||
|
@ -399,12 +399,12 @@ static void em4x50_send_byte_with_parity(uint8_t byte) {
|
|||
}
|
||||
|
||||
static void em4x50_send_word(const uint8_t bytes[4]) {
|
||||
|
||||
|
||||
// send 32 bit word with parity bits according to EM4x50 datasheet
|
||||
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
em4x50_send_byte_with_parity(bytes[i]);
|
||||
|
||||
|
||||
// send column parities
|
||||
em4x50_send_byte(bytes[0] ^ bytes[1] ^ bytes[2] ^ bytes[3]);
|
||||
|
||||
|
@ -413,70 +413,70 @@ static void em4x50_send_word(const uint8_t bytes[4]) {
|
|||
}
|
||||
|
||||
static bool find_single_listen_window(void) {
|
||||
|
||||
|
||||
// find single listen window
|
||||
|
||||
|
||||
int cnt_pulses = 0;
|
||||
|
||||
|
||||
while (cnt_pulses < EM4X50_T_WAITING_FOR_SNGLLIW) {
|
||||
|
||||
|
||||
// identification of listen window is done via evaluation of
|
||||
// pulse lengths
|
||||
if (check_pulse_length(get_pulse_length(), 3 * EM4X50_T_TAG_FULL_PERIOD)) {
|
||||
|
||||
|
||||
if (check_pulse_length(get_pulse_length(), 2 * EM4X50_T_TAG_FULL_PERIOD)) {
|
||||
|
||||
|
||||
// listen window found
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
|
||||
cnt_pulses++;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool find_double_listen_window(bool bcommand) {
|
||||
|
||||
|
||||
// find two successive listen windows that indicate the beginning of
|
||||
// data transmission
|
||||
// double listen window to be detected within 1600 pulses -> worst case
|
||||
// reason: first detectable double listen window after 34 words
|
||||
// -> 34 words + 34 single listen windows -> about 1600 pulses
|
||||
|
||||
|
||||
int cnt_pulses = 0;
|
||||
|
||||
|
||||
while (cnt_pulses < EM4X50_T_WAITING_FOR_DBLLIW) {
|
||||
|
||||
|
||||
// identification of listen window is done via evaluation of
|
||||
// pulse lengths
|
||||
if (check_pulse_length(get_pulse_length(), 3 * EM4X50_T_TAG_FULL_PERIOD)) {
|
||||
|
||||
|
||||
if (check_pulse_length(get_pulse_length(), 2 * EM4X50_T_TAG_FULL_PERIOD)) {
|
||||
|
||||
|
||||
// first listen window found
|
||||
|
||||
|
||||
if (bcommand) {
|
||||
|
||||
// data transmission from card has to be stopped, because
|
||||
// a commamd shall be issued
|
||||
|
||||
|
||||
// unfortunately the posititon in listen window (where
|
||||
// command request has to be sent) has gone, so if a
|
||||
// second window follows - sync on this to issue a command
|
||||
|
||||
|
||||
// skip the next bit...
|
||||
wait_timer(FPGA_TIMER_0, T0 * EM4X50_T_TAG_FULL_PERIOD);
|
||||
|
||||
|
||||
// ...and check if the following bit does make sense
|
||||
// (if not it is the correct position within the second
|
||||
// listen window)
|
||||
if (get_next_bit() == EM4X50_BIT_OTHER) {
|
||||
|
||||
|
||||
// send RM for request mode
|
||||
em4x50_send_bit(0);
|
||||
em4x50_send_bit(0);
|
||||
|
@ -498,47 +498,47 @@ static bool find_double_listen_window(bool bcommand) {
|
|||
cnt_pulses++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool find_em4x50_tag(void) {
|
||||
|
||||
|
||||
// function is used to check wether a tag on the proxmark is an
|
||||
// EM4x50 tag or not -> speed up "lf search" process
|
||||
|
||||
|
||||
return (find_single_listen_window());
|
||||
|
||||
|
||||
}
|
||||
|
||||
static bool request_receive_mode(void) {
|
||||
|
||||
|
||||
// To issue a command we have to find a listen window first.
|
||||
// Because identification and sychronization at the same time is not
|
||||
// possible when using pulse lengths a double listen window is used.
|
||||
|
||||
bool bcommand = true;
|
||||
|
||||
|
||||
return find_double_listen_window(bcommand);
|
||||
}
|
||||
|
||||
static bool check_ack(bool bliw) {
|
||||
|
||||
|
||||
// returns true if signal structue corresponds to ACK, anything else is
|
||||
// counted as NAK (-> false)
|
||||
// Only relevant for pasword writing function:
|
||||
// If <bliw> is true then within the single listen window right after the
|
||||
// ack signal a RM request has to be sent.
|
||||
|
||||
|
||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * 4 * EM4X50_T_TAG_FULL_PERIOD) {
|
||||
|
||||
|
||||
if (check_pulse_length(get_pulse_length(), 2 * EM4X50_T_TAG_FULL_PERIOD)) {
|
||||
|
||||
|
||||
// The received signal is either ACK or NAK.
|
||||
|
||||
|
||||
if (check_pulse_length(get_pulse_length(), 2 * EM4X50_T_TAG_FULL_PERIOD)) {
|
||||
|
||||
|
||||
// Now the signal must be ACK.
|
||||
|
||||
if (!bliw) {
|
||||
|
@ -546,17 +546,17 @@ static bool check_ack(bool bliw) {
|
|||
return true;
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
// send RM request after ack signal
|
||||
|
||||
// wait for 2 bits (remaining "bit" of ACK signal + first
|
||||
// "bit" of listen window)
|
||||
wait_timer(FPGA_TIMER_0, T0 * 2 * EM4X50_T_TAG_FULL_PERIOD);
|
||||
|
||||
|
||||
// check for listen window (if first bit cannot be inerpreted
|
||||
// as a valid bit it must belong to a listen window)
|
||||
if (get_next_bit() == EM4X50_BIT_OTHER) {
|
||||
|
||||
|
||||
// send RM for request mode
|
||||
em4x50_send_bit(0);
|
||||
em4x50_send_bit(0);
|
||||
|
@ -565,7 +565,7 @@ static bool check_ack(bool bliw) {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
|
||||
// It's NAK -> stop searching
|
||||
break;
|
||||
}
|
||||
|
@ -580,7 +580,7 @@ static int get_word_from_bitstream(uint8_t bits[EM4X50_TAG_WORD]) {
|
|||
// decodes one word by evaluating pulse lengths and previous bit;
|
||||
// word must have 45 bits in total:
|
||||
// 32 data bits + 4 row parity bits + 8 column parity bits + 1 stop bit
|
||||
|
||||
|
||||
bool bbitchange = false;
|
||||
int i = 0;
|
||||
uint32_t pl = 0;
|
||||
|
@ -599,7 +599,7 @@ static int get_word_from_bitstream(uint8_t bits[EM4X50_TAG_WORD]) {
|
|||
bbitchange = true;
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
// pulse length = 2.5
|
||||
bits[0] = 0;
|
||||
bits[1] = 1;
|
||||
|
@ -609,35 +609,35 @@ static int get_word_from_bitstream(uint8_t bits[EM4X50_TAG_WORD]) {
|
|||
// identify remaining bits based on pulse lengths
|
||||
// between two listen windows only pulse lengths of 1, 1.5 and 2 are possible
|
||||
while (true) {
|
||||
|
||||
|
||||
i++;
|
||||
pl = get_pulse_length();
|
||||
|
||||
|
||||
if (check_pulse_length(pl, EM4X50_T_TAG_FULL_PERIOD)) {
|
||||
|
||||
// pulse length = 1 -> keep former bit value
|
||||
bits[i] = bits[i-1];
|
||||
bits[i] = bits[i - 1];
|
||||
|
||||
} else if (check_pulse_length(pl, 3 * EM4X50_T_TAG_HALF_PERIOD)) {
|
||||
|
||||
// pulse length = 1.5 -> decision on bit change
|
||||
|
||||
|
||||
if (bbitchange) {
|
||||
|
||||
// if number of pulse lengths with 1.5 periods is even -> add bit
|
||||
bits[i] = (bits[i-1] == 1) ? 1 : 0;
|
||||
bits[i] = (bits[i - 1] == 1) ? 1 : 0;
|
||||
|
||||
// pulse length of 1.5 changes bit value
|
||||
bits[i+1] = (bits[i] == 1) ? 0 : 1;
|
||||
bits[i + 1] = (bits[i] == 1) ? 0 : 1;
|
||||
i++;
|
||||
|
||||
|
||||
// next time add only one bit
|
||||
bbitchange = false;
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
bits[i] = (bits[i-1] == 1) ? 0 : 1;
|
||||
|
||||
bits[i] = (bits[i - 1] == 1) ? 0 : 1;
|
||||
|
||||
// next time two bits have to be added
|
||||
bbitchange = true;
|
||||
}
|
||||
|
@ -646,7 +646,7 @@ static int get_word_from_bitstream(uint8_t bits[EM4X50_TAG_WORD]) {
|
|||
|
||||
// pulse length of 2 means: adding 2 bits "01"
|
||||
bits[i] = 0;
|
||||
bits[i+1] = 1;
|
||||
bits[i + 1] = 1;
|
||||
i++;
|
||||
|
||||
} else if (check_pulse_length(pl, 3 * EM4X50_T_TAG_FULL_PERIOD)) {
|
||||
|
@ -654,7 +654,7 @@ static int get_word_from_bitstream(uint8_t bits[EM4X50_TAG_WORD]) {
|
|||
// pulse length of 3 indicates listen window -> clear last
|
||||
// bit (= 0) and return
|
||||
return --i;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -667,8 +667,8 @@ static bool login(uint8_t password[4]) {
|
|||
|
||||
// simple login to EM4x50,
|
||||
// used in operations that require authentication
|
||||
|
||||
if (request_receive_mode ()) {
|
||||
|
||||
if (request_receive_mode()) {
|
||||
|
||||
// send login command
|
||||
em4x50_send_byte_with_parity(EM4X50_COMMAND_LOGIN);
|
||||
|
@ -679,12 +679,12 @@ static bool login(uint8_t password[4]) {
|
|||
// check if ACK is returned
|
||||
if (check_ack(false))
|
||||
return true;
|
||||
|
||||
|
||||
} else {
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("error in command request");
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("error in command request");
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -695,18 +695,18 @@ static bool login(uint8_t password[4]) {
|
|||
static bool reset(void) {
|
||||
|
||||
// resets EM4x50 tag (used by write function)
|
||||
|
||||
if (request_receive_mode ()) {
|
||||
|
||||
if (request_receive_mode()) {
|
||||
|
||||
// send login command
|
||||
em4x50_send_byte_with_parity(EM4X50_COMMAND_RESET);
|
||||
|
||||
|
||||
if (check_ack(false))
|
||||
return true;
|
||||
|
||||
} else {
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("error in command request");
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("error in command request");
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -717,10 +717,10 @@ static bool reset(void) {
|
|||
//==============================================================================
|
||||
|
||||
static bool standard_read(int *now) {
|
||||
|
||||
|
||||
// reads data that tag transmits when exposed to reader field
|
||||
// (standard read mode); number of read words is saved in <now>
|
||||
|
||||
|
||||
int fwr = *now;
|
||||
uint8_t bits[EM4X50_TAG_WORD] = {0};
|
||||
|
||||
|
@ -733,23 +733,23 @@ static bool standard_read(int *now) {
|
|||
|
||||
// number of detected words
|
||||
*now -= fwr;
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
} else {
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("didn't find a listen window");
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("didn't find a listen window");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool selective_read(uint8_t addresses[4]) {
|
||||
|
||||
|
||||
// reads from "first word read" (fwr = addresses[3]) to "last word read"
|
||||
// (lwr = addresses[2])
|
||||
// result is verified by "standard read mode"
|
||||
|
||||
|
||||
int fwr = addresses[3]; // first word read
|
||||
int lwr = addresses[2]; // last word read
|
||||
int now = fwr; // number of words
|
||||
|
@ -764,26 +764,26 @@ static bool selective_read(uint8_t addresses[4]) {
|
|||
|
||||
// look for ACK sequence
|
||||
if (check_ack(false))
|
||||
|
||||
|
||||
// save and verify via standard read mode (compare number of words)
|
||||
if (standard_read(&now))
|
||||
if (now == (lwr - fwr + 1))
|
||||
return true;
|
||||
|
||||
|
||||
} else {
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("error in command request");
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("error in command request");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void em4x50_info(em4x50_data_t *etd) {
|
||||
|
||||
|
||||
// collects as much information as possible via selective read mode
|
||||
// if no password is given -> try with standard password "0x00000000"
|
||||
// otherwise continue without login
|
||||
|
||||
|
||||
bool bsuccess = false, blogin = false;
|
||||
uint8_t status = 0;
|
||||
uint8_t addresses[] = {0x00, 0x00, 0x21, 0x00}; // fwr = 0, lwr = 33
|
||||
|
@ -801,28 +801,28 @@ void em4x50_info(em4x50_data_t *etd) {
|
|||
blogin = login(etd->password);
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
// if no password is given, try to login with "0x00000000"
|
||||
blogin = login(password);
|
||||
|
||||
}
|
||||
|
||||
|
||||
bsuccess = selective_read(addresses);
|
||||
}
|
||||
|
||||
status = (bsuccess << 1) + blogin;
|
||||
|
||||
|
||||
lf_finalize();
|
||||
reply_ng(CMD_ACK, status, (uint8_t *)tag.sectors, 238);
|
||||
}
|
||||
|
||||
void em4x50_read(em4x50_data_t *etd) {
|
||||
|
||||
|
||||
// reads in two different ways:
|
||||
// - using "selective read mode" -> bidirectional communication
|
||||
// - using "standard read mode" -> unidirectional communication (read
|
||||
// data that tag transmits "voluntarily")
|
||||
|
||||
|
||||
bool bsuccess = false, blogin = false;
|
||||
int now = 0;
|
||||
uint8_t status = 0;
|
||||
|
@ -830,32 +830,32 @@ void em4x50_read(em4x50_data_t *etd) {
|
|||
|
||||
init_tag();
|
||||
em4x50_setup_read();
|
||||
|
||||
|
||||
// set gHigh and gLow
|
||||
if (get_signalproperties() && find_em4x50_tag()) {
|
||||
|
||||
|
||||
if (etd->addr_given) {
|
||||
|
||||
// selective read mode
|
||||
|
||||
|
||||
// try to login with given password
|
||||
if (etd->pwd_given)
|
||||
blogin = login(etd->password);
|
||||
|
||||
|
||||
// only one word has to be read -> first word read = last word read
|
||||
addresses[2] = addresses[3] = etd->address;
|
||||
bsuccess = selective_read(addresses);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
// standard read mode
|
||||
bsuccess = standard_read(&now);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
status = (now << 2) + (bsuccess << 1) + blogin;
|
||||
|
||||
|
||||
lf_finalize();
|
||||
reply_ng(CMD_ACK, status, (uint8_t *)tag.sectors, 238);
|
||||
}
|
||||
|
@ -867,7 +867,7 @@ void em4x50_read(em4x50_data_t *etd) {
|
|||
static bool write(uint8_t word[4], uint8_t address) {
|
||||
|
||||
// writes <word> to specified <address>
|
||||
|
||||
|
||||
if (request_receive_mode()) {
|
||||
|
||||
// send write command
|
||||
|
@ -893,8 +893,8 @@ static bool write(uint8_t word[4], uint8_t address) {
|
|||
}
|
||||
|
||||
} else {
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("error in command request");
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("error in command request");
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -903,7 +903,7 @@ static bool write(uint8_t word[4], uint8_t address) {
|
|||
static bool write_password(uint8_t password[4], uint8_t new_password[4]) {
|
||||
|
||||
// changes password from <password> to <new_password>
|
||||
|
||||
|
||||
if (request_receive_mode()) {
|
||||
|
||||
// send write password command
|
||||
|
@ -932,36 +932,36 @@ static bool write_password(uint8_t password[4], uint8_t new_password[4]) {
|
|||
}
|
||||
|
||||
} else {
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("error in command request");
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("error in command request");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void em4x50_write(em4x50_data_t *etd) {
|
||||
|
||||
|
||||
// write operation process for EM4x50 tag,
|
||||
// single word is written to given address, verified by selective read operation
|
||||
|
||||
|
||||
bool bsuccess = false, blogin = false;
|
||||
uint8_t status = 0;
|
||||
uint8_t word[4] = {0x00, 0x00, 0x00, 0x00};
|
||||
uint8_t addresses[4] = {0x00, 0x00, 0x00, 0x00};
|
||||
|
||||
|
||||
init_tag();
|
||||
em4x50_setup_read();
|
||||
|
||||
|
||||
// set gHigh and gLow
|
||||
if (get_signalproperties() && find_em4x50_tag()) {
|
||||
|
||||
|
||||
// reorder word according to datasheet
|
||||
msb2lsb_word(etd->word);
|
||||
|
||||
|
||||
// if password is given try to login first
|
||||
if (etd->pwd_given)
|
||||
blogin = login(etd->password);
|
||||
|
||||
|
||||
// write word to given address
|
||||
if (write(etd->word, etd->address)) {
|
||||
|
||||
|
@ -982,7 +982,7 @@ void em4x50_write(em4x50_data_t *etd) {
|
|||
word[2] = tag.sectors[etd->address][2];
|
||||
word[3] = tag.sectors[etd->address][3];
|
||||
msb2lsb_word(word);
|
||||
|
||||
|
||||
bsuccess = true;
|
||||
for (int i = 0; i < 4; i++)
|
||||
bsuccess &= (word[i] == etd->word[i]) ? true : false;
|
||||
|
@ -993,20 +993,20 @@ void em4x50_write(em4x50_data_t *etd) {
|
|||
}
|
||||
|
||||
status = (bsuccess << 1) + blogin;
|
||||
|
||||
|
||||
lf_finalize();
|
||||
reply_ng(CMD_ACK, status, (uint8_t *)tag.sectors, 238);
|
||||
}
|
||||
|
||||
void em4x50_write_password(em4x50_data_t *etd) {
|
||||
|
||||
|
||||
// sinmple change of password
|
||||
|
||||
|
||||
bool bsuccess = false;
|
||||
|
||||
|
||||
init_tag();
|
||||
em4x50_setup_read();
|
||||
|
||||
|
||||
// set gHigh and gLow
|
||||
if (get_signalproperties() && find_em4x50_tag()) {
|
||||
|
||||
|
@ -1021,19 +1021,19 @@ void em4x50_write_password(em4x50_data_t *etd) {
|
|||
}
|
||||
|
||||
void em4x50_wipe(em4x50_data_t *etd) {
|
||||
|
||||
|
||||
// set all data of EM4x50 tag to 0x0 including password
|
||||
|
||||
|
||||
bool bsuccess = false;
|
||||
uint8_t zero[4] = {0, 0, 0, 0};
|
||||
uint8_t addresses[4] = {0, 0, EM4X50_NO_WORDS - 3, 1};
|
||||
|
||||
|
||||
init_tag();
|
||||
em4x50_setup_read();
|
||||
|
||||
|
||||
// set gHigh and gLow
|
||||
if (get_signalproperties() && find_em4x50_tag()) {
|
||||
|
||||
|
||||
// login first
|
||||
if (login(etd->password)) {
|
||||
|
||||
|
@ -1058,9 +1058,9 @@ void em4x50_wipe(em4x50_data_t *etd) {
|
|||
bsuccess &= (tag.sectors[i][j] == 0) ? true : false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (bsuccess) {
|
||||
|
||||
|
||||
// so far everything is fine
|
||||
// last task: reset password
|
||||
if (login(etd->password))
|
||||
|
|
|
@ -152,16 +152,16 @@ void FpgaSetupSsc(uint16_t fpga_mode) {
|
|||
// data and frame signal is sampled on falling edge of RK
|
||||
AT91C_BASE_SSC->SSC_RCMR = SSC_CLOCK_MODE_SELECT(1) | SSC_CLOCK_MODE_START(1);
|
||||
|
||||
// 8, 16 or 32 bits per transfer, no loopback, MSB first, 1 transfer per sync
|
||||
// 8, 16 or 32 bits per transfer, no loopback, MSB first, 1 transfer per sync
|
||||
// pulse, no output sync
|
||||
if ((fpga_mode & FPGA_MAJOR_MODE_MASK) == FPGA_MAJOR_MODE_HF_READER && FpgaGetCurrent() == FPGA_BITSTREAM_HF) {
|
||||
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(16) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0);
|
||||
} else {
|
||||
if ((fpga_mode & FPGA_MAJOR_MODE_MASK) == FPGA_MAJOR_MODE_HF_READER && FpgaGetCurrent() == FPGA_BITSTREAM_HF) {
|
||||
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(16) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0);
|
||||
} else {
|
||||
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(8) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0);
|
||||
}
|
||||
}
|
||||
|
||||
// TX clock comes from TK pin, no clock output, outputs change on rising edge of TK,
|
||||
// TF (frame sync) is sampled on falling edge of TK, start TX on rising edge of TF
|
||||
// TX clock comes from TK pin, no clock output, outputs change on rising edge of TK,
|
||||
// TF (frame sync) is sampled on falling edge of TK, start TX on rising edge of TF
|
||||
AT91C_BASE_SSC->SSC_TCMR = SSC_CLOCK_MODE_SELECT(2) | SSC_CLOCK_MODE_START(5);
|
||||
|
||||
// tx framing is the same as the rx framing
|
||||
|
|
|
@ -52,7 +52,7 @@ int HfSniff(uint32_t samplesToSkip, uint32_t triggersToSkip, uint16_t *len) {
|
|||
*len = (BigBuf_max_traceLen() & 0xFFFE);
|
||||
uint8_t *mem = BigBuf_malloc(*len);
|
||||
|
||||
uint32_t trigger_cnt = 0;
|
||||
uint32_t trigger_cnt = 0;
|
||||
uint16_t r = 0, interval = 0;
|
||||
|
||||
bool pressed = false;
|
||||
|
@ -77,7 +77,7 @@ int HfSniff(uint32_t samplesToSkip, uint32_t triggersToSkip, uint16_t *len) {
|
|||
|
||||
// 180 (0xB4) arbitary value to see if a strong RF field is near.
|
||||
if (r > 180) {
|
||||
|
||||
|
||||
if (++trigger_cnt > triggersToSkip) {
|
||||
break;
|
||||
}
|
||||
|
@ -97,7 +97,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) {
|
||||
Dbprintf("Trigger kicked in (%d >= 180)", r);
|
||||
|
|
|
@ -1002,7 +1002,7 @@ void SniffHitag2(void) {
|
|||
size_t periods = 0;
|
||||
uint8_t periods_bytes[4];
|
||||
|
||||
// int16_t checked = 0;
|
||||
// int16_t checked = 0;
|
||||
|
||||
/*bool waiting_for_first_edge = true;*/
|
||||
LED_C_ON();
|
||||
|
@ -1015,18 +1015,18 @@ void SniffHitag2(void) {
|
|||
|
||||
WDT_HIT();
|
||||
|
||||
/*
|
||||
// only every 1000th times, in order to save time when collecting samples.
|
||||
if (checked == 1000) {
|
||||
if (data_available()) {
|
||||
checked = -1;
|
||||
break;
|
||||
} else {
|
||||
checked = 0;
|
||||
}
|
||||
}
|
||||
++checked;
|
||||
*/
|
||||
/*
|
||||
// only every 1000th times, in order to save time when collecting samples.
|
||||
if (checked == 1000) {
|
||||
if (data_available()) {
|
||||
checked = -1;
|
||||
break;
|
||||
} else {
|
||||
checked = 0;
|
||||
}
|
||||
}
|
||||
++checked;
|
||||
*/
|
||||
|
||||
|
||||
// Receive frame, watch for at most T0*EOF periods
|
||||
|
|
|
@ -736,7 +736,7 @@ void SmartCardRaw(uint64_t arg0, uint64_t arg1, uint8_t *data) {
|
|||
|
||||
if ((flags & SC_LOG) == SC_LOG)
|
||||
set_tracing(true);
|
||||
else
|
||||
else
|
||||
set_tracing(false);
|
||||
|
||||
if ((flags & SC_CONNECT)) {
|
||||
|
|
278
armsrc/iclass.c
278
armsrc/iclass.c
|
@ -162,9 +162,9 @@ void iclass_simulate(uint8_t sim_type, uint8_t num_csns, bool send_reply, uint8_
|
|||
LEDsoff();
|
||||
|
||||
Iso15693InitTag();
|
||||
|
||||
|
||||
clear_trace();
|
||||
|
||||
|
||||
// only logg if we are called from the client.
|
||||
set_tracing(send_reply);
|
||||
|
||||
|
@ -190,15 +190,15 @@ void iclass_simulate(uint8_t sim_type, uint8_t num_csns, bool send_reply, uint8_
|
|||
// In this mode, a number of csns are within datain. We'll simulate each one, one at a time
|
||||
// in order to collect MAC's from the reader. This can later be used in an offlne-attack
|
||||
// in order to obtain the keys, as in the "dismantling iclass"-paper.
|
||||
#define EPURSE_MAC_SIZE 16
|
||||
#define EPURSE_MAC_SIZE 16
|
||||
int i = 0;
|
||||
for (; i < num_csns && i * EPURSE_MAC_SIZE + 8 < PM3_CMD_DATA_SIZE; i++) {
|
||||
|
||||
memcpy(emulator, datain + (i * 8), 8);
|
||||
|
||||
if (do_iclass_simulation(ICLASS_SIM_MODE_EXIT_AFTER_MAC, mac_responses + i * EPURSE_MAC_SIZE)) {
|
||||
|
||||
if (dataoutlen)
|
||||
|
||||
if (dataoutlen)
|
||||
*dataoutlen = i * EPURSE_MAC_SIZE;
|
||||
|
||||
// Button pressed
|
||||
|
@ -207,7 +207,7 @@ void iclass_simulate(uint8_t sim_type, uint8_t num_csns, bool send_reply, uint8_
|
|||
goto out;
|
||||
}
|
||||
}
|
||||
if (dataoutlen)
|
||||
if (dataoutlen)
|
||||
*dataoutlen = i * EPURSE_MAC_SIZE;
|
||||
|
||||
if (send_reply)
|
||||
|
@ -227,7 +227,7 @@ void iclass_simulate(uint8_t sim_type, uint8_t num_csns, bool send_reply, uint8_
|
|||
|
||||
} else if (sim_type == ICLASS_SIM_MODE_CONFIG_CARD) {
|
||||
|
||||
// config card
|
||||
// config card
|
||||
do_iclass_simulation(ICLASS_SIM_MODE_FULL, NULL);
|
||||
// swap bin
|
||||
|
||||
|
@ -252,11 +252,11 @@ void iclass_simulate(uint8_t sim_type, uint8_t num_csns, bool send_reply, uint8_
|
|||
|
||||
// keyroll 1
|
||||
if (do_iclass_simulation(ICLASS_SIM_MODE_EXIT_AFTER_MAC, mac_responses + i * EPURSE_MAC_SIZE)) {
|
||||
|
||||
if (dataoutlen)
|
||||
|
||||
if (dataoutlen)
|
||||
*dataoutlen = i * EPURSE_MAC_SIZE * 2;
|
||||
|
||||
if (send_reply)
|
||||
if (send_reply)
|
||||
reply_old(CMD_ACK, CMD_HF_ICLASS_SIMULATE, i * 2, 0, mac_responses, i * EPURSE_MAC_SIZE * 2);
|
||||
|
||||
// Button pressed
|
||||
|
@ -266,10 +266,10 @@ void iclass_simulate(uint8_t sim_type, uint8_t num_csns, bool send_reply, uint8_
|
|||
// keyroll 2
|
||||
if (do_iclass_simulation(ICLASS_SIM_MODE_EXIT_AFTER_MAC, mac_responses + (i + num_csns) * EPURSE_MAC_SIZE)) {
|
||||
|
||||
if (dataoutlen)
|
||||
if (dataoutlen)
|
||||
*dataoutlen = i * EPURSE_MAC_SIZE * 2;
|
||||
|
||||
if (send_reply)
|
||||
if (send_reply)
|
||||
reply_old(CMD_ACK, CMD_HF_ICLASS_SIMULATE, i * 2, 0, mac_responses, i * EPURSE_MAC_SIZE * 2);
|
||||
|
||||
// Button pressed
|
||||
|
@ -277,13 +277,13 @@ void iclass_simulate(uint8_t sim_type, uint8_t num_csns, bool send_reply, uint8_
|
|||
}
|
||||
}
|
||||
|
||||
if (dataoutlen)
|
||||
if (dataoutlen)
|
||||
*dataoutlen = i * EPURSE_MAC_SIZE * 2;
|
||||
|
||||
// double the amount of collected data.
|
||||
if (send_reply)
|
||||
reply_old(CMD_ACK, CMD_HF_ICLASS_SIMULATE, i * 2, 0, mac_responses, i * EPURSE_MAC_SIZE * 2);
|
||||
|
||||
|
||||
} else {
|
||||
// We may want a mode here where we hardcode the csns to use (from proxclone).
|
||||
// That will speed things up a little, but not required just yet.
|
||||
|
@ -300,7 +300,7 @@ out:
|
|||
|
||||
/**
|
||||
* Simulation assumes a SECURE PAGE simulation with authentication and application areas.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @brief Does the actual simulation
|
||||
* @param csn - csn to use
|
||||
|
@ -318,7 +318,7 @@ int do_iclass_simulation(int simulationMode, uint8_t *reader_mac_buf) {
|
|||
State cipher_state_KD[8];
|
||||
State cipher_state_KC[8];
|
||||
State *cipher_state = &cipher_state_KD[0];
|
||||
|
||||
|
||||
uint8_t *emulator = BigBuf_get_EM_addr();
|
||||
uint8_t *csn = emulator;
|
||||
|
||||
|
@ -346,14 +346,14 @@ int do_iclass_simulation(int simulationMode, uint8_t *reader_mac_buf) {
|
|||
|
||||
// AIA
|
||||
uint8_t aia_data[10] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00};
|
||||
|
||||
|
||||
if (simulationMode == ICLASS_SIM_MODE_FULL) {
|
||||
|
||||
memcpy(conf_block, emulator + (8 * 1), 8); // blk 1
|
||||
memcpy(card_challenge_data, emulator + (8 * 2), 8); // e-purse, blk 2
|
||||
memcpy(diversified_kd, emulator + (8 * 3), 8); // Kd, blk 3
|
||||
memcpy(diversified_kc, emulator + (8 * 4), 8); // Kc, blk 4
|
||||
|
||||
|
||||
// (iceman) this only works for 2KS / 16KS tags.
|
||||
// Use application data from block 5
|
||||
memcpy(aia_data, emulator + (8 * 5), 8);
|
||||
|
@ -378,7 +378,7 @@ int do_iclass_simulation(int simulationMode, uint8_t *reader_mac_buf) {
|
|||
bool personalization_mode = conf_block[7] & 0x80;
|
||||
|
||||
uint8_t block_wr_lock = conf_block[3];
|
||||
|
||||
|
||||
// chip memory may be divided in 8 pages
|
||||
uint8_t max_page = ((conf_block[4] & 0x10) == 0x10) ? 0 : 7;
|
||||
|
||||
|
@ -512,7 +512,7 @@ int do_iclass_simulation(int simulationMode, uint8_t *reader_mac_buf) {
|
|||
modulated_response_size = 0;
|
||||
trace_data = NULL;
|
||||
trace_data_size = 0;
|
||||
|
||||
|
||||
uint32_t reader_eof_time = 0;
|
||||
len = GetIso15693CommandFromReader(receivedCmd, MAX_FRAME_SIZE, &reader_eof_time);
|
||||
if (len < 0) {
|
||||
|
@ -520,7 +520,7 @@ int do_iclass_simulation(int simulationMode, uint8_t *reader_mac_buf) {
|
|||
exit_loop = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// extra response data
|
||||
cmd = receivedCmd[0] & 0xF;
|
||||
options = (receivedCmd[0] >> 4) & 0xFF;
|
||||
|
@ -532,7 +532,7 @@ int do_iclass_simulation(int simulationMode, uint8_t *reader_mac_buf) {
|
|||
modulated_response_size = resp_sof_len;
|
||||
chip_state = ACTIVATED;
|
||||
goto send;
|
||||
|
||||
|
||||
} else if (cmd == ICLASS_CMD_READ_OR_IDENTIFY && len == 1) { // 0x0C
|
||||
// Reader asks for anti collision CSN
|
||||
if (chip_state == SELECTED || chip_state == ACTIVATED) {
|
||||
|
@ -576,7 +576,7 @@ int do_iclass_simulation(int simulationMode, uint8_t *reader_mac_buf) {
|
|||
}
|
||||
if (simulationMode == ICLASS_SIM_MODE_EXIT_AFTER_MAC) {
|
||||
// provide defaults for blocks 0 ... 5
|
||||
|
||||
|
||||
// block0,1,2,5 is always readable.
|
||||
switch (block) {
|
||||
case 0: { // csn (0c 00)
|
||||
|
@ -646,7 +646,7 @@ int do_iclass_simulation(int simulationMode, uint8_t *reader_mac_buf) {
|
|||
}
|
||||
|
||||
// debit key
|
||||
if (receivedCmd[0] == 0x88 ){
|
||||
if (receivedCmd[0] == 0x88) {
|
||||
cipher_state = &cipher_state_KD[current_page];
|
||||
diversified_key = diversified_kd;
|
||||
using_kc = false;
|
||||
|
@ -662,7 +662,7 @@ int do_iclass_simulation(int simulationMode, uint8_t *reader_mac_buf) {
|
|||
trace_data_size = sizeof(card_challenge_data);
|
||||
goto send;
|
||||
|
||||
} else if (cmd == ICLASS_CMD_CHECK && len == 9) { // 0x05
|
||||
} else if (cmd == ICLASS_CMD_CHECK && len == 9) { // 0x05
|
||||
|
||||
// Reader random and reader MAC!!!
|
||||
if (chip_state != SELECTED) {
|
||||
|
@ -677,14 +677,14 @@ int do_iclass_simulation(int simulationMode, uint8_t *reader_mac_buf) {
|
|||
opt_doReaderMAC_2(*cipher_state, receivedCmd + 1, _mac, diversified_key);
|
||||
|
||||
if (_mac[0] != receivedCmd[5] || _mac[1] != receivedCmd[6] || _mac[2] != receivedCmd[7] || _mac[3] != receivedCmd[8]) {
|
||||
Dbprintf("reader auth " _RED_("failed"));
|
||||
Dbprintf("reader auth " _RED_("failed"));
|
||||
Dbprintf("hf iclass lookup u %02x%02x%02x%02x%02x%02x%02x%02x p %02x%02x%02x%02x%02x%02x%02x%02x m %02x%02x%02x%02x%02x%02x%02x%02x f iclass_default_keys.dic",
|
||||
csn_data[0],csn_data[1],csn_data[2],csn_data[3],csn_data[4],csn_data[5],csn_data[6],csn_data[7],
|
||||
card_challenge_data[0],card_challenge_data[1],card_challenge_data[2],card_challenge_data[3],
|
||||
card_challenge_data[4],card_challenge_data[5],card_challenge_data[6],card_challenge_data[7],
|
||||
receivedCmd[1],receivedCmd[2],receivedCmd[3],receivedCmd[4],
|
||||
receivedCmd[5],receivedCmd[6],receivedCmd[7],receivedCmd[8]
|
||||
);
|
||||
csn_data[0], csn_data[1], csn_data[2], csn_data[3], csn_data[4], csn_data[5], csn_data[6], csn_data[7],
|
||||
card_challenge_data[0], card_challenge_data[1], card_challenge_data[2], card_challenge_data[3],
|
||||
card_challenge_data[4], card_challenge_data[5], card_challenge_data[6], card_challenge_data[7],
|
||||
receivedCmd[1], receivedCmd[2], receivedCmd[3], receivedCmd[4],
|
||||
receivedCmd[5], receivedCmd[6], receivedCmd[7], receivedCmd[8]
|
||||
);
|
||||
|
||||
goto send;
|
||||
}
|
||||
|
@ -760,13 +760,13 @@ int do_iclass_simulation(int simulationMode, uint8_t *reader_mac_buf) {
|
|||
// is chip in ReadOnly (RO)
|
||||
if ((block_wr_lock & 0x80) == 0) goto send;
|
||||
|
||||
if ( block == 12 && (block_wr_lock & 0x40) == 0) goto send;
|
||||
if ( block == 11 && (block_wr_lock & 0x20) == 0) goto send;
|
||||
if ( block == 10 && (block_wr_lock & 0x10) == 0) goto send;
|
||||
if ( block == 9 && (block_wr_lock & 0x08) == 0) goto send;
|
||||
if ( block == 8 && (block_wr_lock & 0x04) == 0) goto send;
|
||||
if ( block == 7 && (block_wr_lock & 0x02) == 0) goto send;
|
||||
if ( block == 6 && (block_wr_lock & 0x01) == 0) goto send;
|
||||
if (block == 12 && (block_wr_lock & 0x40) == 0) goto send;
|
||||
if (block == 11 && (block_wr_lock & 0x20) == 0) goto send;
|
||||
if (block == 10 && (block_wr_lock & 0x10) == 0) goto send;
|
||||
if (block == 9 && (block_wr_lock & 0x08) == 0) goto send;
|
||||
if (block == 8 && (block_wr_lock & 0x04) == 0) goto send;
|
||||
if (block == 7 && (block_wr_lock & 0x02) == 0) goto send;
|
||||
if (block == 6 && (block_wr_lock & 0x01) == 0) goto send;
|
||||
|
||||
if (block == 2) { // update e-purse
|
||||
memcpy(card_challenge_data, receivedCmd + 2, 8);
|
||||
|
@ -777,7 +777,7 @@ int do_iclass_simulation(int simulationMode, uint8_t *reader_mac_buf) {
|
|||
cipher_state_KC[current_page] = opt_doTagMAC_1(card_challenge_data, diversified_kc);
|
||||
if (simulationMode == ICLASS_SIM_MODE_FULL) {
|
||||
memcpy(emulator + (current_page * page_size) + (8 * 2), card_challenge_data, 8);
|
||||
}
|
||||
}
|
||||
} else if (block == 3) { // update Kd
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (personalization_mode) {
|
||||
|
@ -830,7 +830,7 @@ int do_iclass_simulation(int simulationMode, uint8_t *reader_mac_buf) {
|
|||
|
||||
// if on 2k, always ignore 3msb, & 0x1F)
|
||||
uint8_t page = receivedCmd[1] & 0x1F;
|
||||
if ( page > max_page) {
|
||||
if (page > max_page) {
|
||||
goto send;
|
||||
}
|
||||
|
||||
|
@ -844,7 +844,7 @@ int do_iclass_simulation(int simulationMode, uint8_t *reader_mac_buf) {
|
|||
|
||||
personalization_mode = data_generic_trace[7] & 0x80;
|
||||
block_wr_lock = data_generic_trace[3];
|
||||
|
||||
|
||||
AddCrc(data_generic_trace, 8);
|
||||
|
||||
trace_data = data_generic_trace;
|
||||
|
@ -856,8 +856,8 @@ int do_iclass_simulation(int simulationMode, uint8_t *reader_mac_buf) {
|
|||
modulated_response_size = ts->max;
|
||||
}
|
||||
goto send;
|
||||
|
||||
} else if(cmd == ICLASS_CMD_DETECT) { // 0x0F
|
||||
|
||||
} else if (cmd == ICLASS_CMD_DETECT) { // 0x0F
|
||||
// not supported yet, ignore
|
||||
} else if (cmd == 0x26 && len == 5) {
|
||||
// standard ISO15693 INVENTORY command. Ignore.
|
||||
|
@ -876,7 +876,7 @@ send:
|
|||
TransmitTo15693Reader(modulated_response, modulated_response_size, &response_time, 0, false);
|
||||
LogTrace_ISO15693(trace_data, trace_data_size, response_time * 32, (response_time * 32) + (modulated_response_size * 32 * 64), NULL, false);
|
||||
}
|
||||
|
||||
|
||||
if (chip_state == HALTED) {
|
||||
uint32_t wait_time = GetCountSspClk() + ICLASS_READER_TIMEOUT_ACTALL;
|
||||
while (GetCountSspClk() < wait_time) {};
|
||||
|
@ -927,8 +927,8 @@ int do_iclass_simulation_nonsec(void) {
|
|||
|
||||
// AIA
|
||||
uint8_t aia_data[10] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00};
|
||||
|
||||
memcpy(conf_block, emulator + (8 * 1), 8);
|
||||
|
||||
memcpy(conf_block, emulator + (8 * 1), 8);
|
||||
memcpy(aia_data, emulator + (8 * 2), 8);
|
||||
|
||||
AddCrc(conf_block, 8);
|
||||
|
@ -1025,7 +1025,7 @@ int do_iclass_simulation_nonsec(void) {
|
|||
bool exit_loop = false;
|
||||
while (exit_loop == false) {
|
||||
WDT_HIT();
|
||||
|
||||
|
||||
uint32_t reader_eof_time = 0;
|
||||
len = GetIso15693CommandFromReader(receivedCmd, MAX_FRAME_SIZE, &reader_eof_time);
|
||||
if (len < 0) {
|
||||
|
@ -1048,13 +1048,13 @@ int do_iclass_simulation_nonsec(void) {
|
|||
|
||||
if (cmd == ICLASS_CMD_ACTALL && len == 1) { // 0x0A
|
||||
// Reader in anti collision phase
|
||||
if (chip_state != HALTED) {
|
||||
if (chip_state != HALTED) {
|
||||
modulated_response = resp_sof;
|
||||
modulated_response_size = resp_sof_len;
|
||||
chip_state = ACTIVATED;
|
||||
}
|
||||
goto send;
|
||||
|
||||
|
||||
} else if (cmd == ICLASS_CMD_READ_OR_IDENTIFY && len == 1) { // 0x0C
|
||||
// Reader asks for anti collision CSN
|
||||
if (chip_state == SELECTED || chip_state == ACTIVATED) {
|
||||
|
@ -1135,7 +1135,7 @@ int do_iclass_simulation_nonsec(void) {
|
|||
} else if (cmd == ICLASS_CMD_READCHECK) { // 0x88
|
||||
goto send;
|
||||
|
||||
} else if (cmd == ICLASS_CMD_CHECK && len == 9) { // 0x05
|
||||
} else if (cmd == ICLASS_CMD_CHECK && len == 9) { // 0x05
|
||||
goto send;
|
||||
|
||||
} else if (cmd == ICLASS_CMD_HALT && options == 0 && len == 1) {
|
||||
|
@ -1210,7 +1210,7 @@ int do_iclass_simulation_nonsec(void) {
|
|||
modulated_response_size = ts->max;
|
||||
}
|
||||
goto send;
|
||||
|
||||
|
||||
// } else if(cmd == ICLASS_CMD_DETECT) { // 0x0F
|
||||
} else if (cmd == 0x26 && len == 5) {
|
||||
// standard ISO15693 INVENTORY command. Ignore.
|
||||
|
@ -1249,15 +1249,15 @@ static void iclass_send_as_reader(uint8_t *frame, int len, uint32_t *start_time,
|
|||
LogTrace_ISO15693(frame, len, (*start_time * 4), (*end_time * 4), NULL, true);
|
||||
}
|
||||
|
||||
static bool iclass_send_cmd_with_retries(uint8_t* cmd, size_t cmdsize, uint8_t* resp, size_t max_resp_size,
|
||||
uint8_t expected_size, uint8_t tries, uint32_t *start_time,
|
||||
uint16_t timeout, uint32_t *eof_time) {
|
||||
static bool iclass_send_cmd_with_retries(uint8_t *cmd, size_t cmdsize, uint8_t *resp, size_t max_resp_size,
|
||||
uint8_t expected_size, uint8_t tries, uint32_t *start_time,
|
||||
uint16_t timeout, uint32_t *eof_time) {
|
||||
while (tries-- > 0) {
|
||||
|
||||
iclass_send_as_reader(cmd, cmdsize, start_time, eof_time);
|
||||
|
||||
|
||||
if (resp == NULL) {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (expected_size == GetIso15693AnswerFromTag(resp, max_resp_size, timeout, eof_time)) {
|
||||
|
@ -1285,7 +1285,7 @@ static bool select_iclass_tag_ex(uint8_t *card_data, bool use_credit_key, uint32
|
|||
uint8_t resp[ICLASS_BUFFER_SIZE] = {0};
|
||||
|
||||
picopass_hdr *hdr = (picopass_hdr *)card_data;
|
||||
|
||||
|
||||
// Bit 4: K.If this bit equals to one, the READCHECK will use the Credit Key (Kc); if equals to zero, Debit Key (Kd) will be used
|
||||
// bit 7: parity.
|
||||
if (use_credit_key)
|
||||
|
@ -1297,14 +1297,14 @@ static bool select_iclass_tag_ex(uint8_t *card_data, bool use_credit_key, uint32
|
|||
int len = GetIso15693AnswerFromTag(resp, sizeof(resp), ICLASS_READER_TIMEOUT_ACTALL, eof_time);
|
||||
if (len < 0)
|
||||
return false;
|
||||
|
||||
|
||||
// send Identify
|
||||
start_time = *eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
|
||||
iclass_send_as_reader(identify, 1, &start_time, eof_time);
|
||||
|
||||
// expect a 10-byte response here, 8 byte anticollision-CSN and 2 byte CRC
|
||||
len = GetIso15693AnswerFromTag(resp, sizeof(resp), ICLASS_READER_TIMEOUT_OTHERS, eof_time);
|
||||
if (len != 10)
|
||||
if (len != 10)
|
||||
return false;
|
||||
|
||||
// copy the Anti-collision CSN to our select-packet
|
||||
|
@ -1325,17 +1325,17 @@ static bool select_iclass_tag_ex(uint8_t *card_data, bool use_credit_key, uint32
|
|||
// card selected, now read config (block1) (only 8 bytes no CRC)
|
||||
start_time = *eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
|
||||
iclass_send_as_reader(read_conf, sizeof(read_conf), &start_time, eof_time);
|
||||
|
||||
|
||||
// expect a 8-byte response here
|
||||
len = GetIso15693AnswerFromTag(resp, sizeof(resp), ICLASS_READER_TIMEOUT_OTHERS, eof_time);
|
||||
if (len != 10)
|
||||
return false;
|
||||
|
||||
// save CONF
|
||||
memcpy( (uint8_t*)&hdr->conf, resp, sizeof(hdr->conf));
|
||||
|
||||
if (status)
|
||||
*status |= (FLAG_ICLASS_CSN | FLAG_ICLASS_CONF);
|
||||
memcpy((uint8_t *)&hdr->conf, resp, sizeof(hdr->conf));
|
||||
|
||||
if (status)
|
||||
*status |= (FLAG_ICLASS_CSN | FLAG_ICLASS_CONF);
|
||||
|
||||
uint8_t pagemap = get_pagemap(hdr);
|
||||
if (pagemap != PICOPASS_NON_SECURE_PAGEMODE) {
|
||||
|
@ -1343,12 +1343,12 @@ static bool select_iclass_tag_ex(uint8_t *card_data, bool use_credit_key, uint32
|
|||
// read App Issuer Area block 5
|
||||
start_time = *eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
|
||||
iclass_send_as_reader(read_aia, sizeof(read_aia), &start_time, eof_time);
|
||||
|
||||
// expect a 10-byte response here
|
||||
|
||||
// expect a 10-byte response here
|
||||
len = GetIso15693AnswerFromTag(resp, sizeof(resp), ICLASS_READER_TIMEOUT_OTHERS, eof_time);
|
||||
if (len != 10)
|
||||
return false;
|
||||
|
||||
|
||||
if (status) {
|
||||
*status |= FLAG_ICLASS_AIA;
|
||||
memcpy(hdr->app_issuer_area, resp, sizeof(hdr->app_issuer_area));
|
||||
|
@ -1357,7 +1357,7 @@ static bool select_iclass_tag_ex(uint8_t *card_data, bool use_credit_key, uint32
|
|||
// card selected, now read e-purse (cc) (block2) (only 8 bytes no CRC)
|
||||
start_time = *eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
|
||||
iclass_send_as_reader(read_check_cc, sizeof(read_check_cc), &start_time, eof_time);
|
||||
|
||||
|
||||
// expect a 8-byte response here
|
||||
len = GetIso15693AnswerFromTag(resp, sizeof(resp), ICLASS_READER_TIMEOUT_OTHERS, eof_time);
|
||||
if (len != 8)
|
||||
|
@ -1365,7 +1365,7 @@ static bool select_iclass_tag_ex(uint8_t *card_data, bool use_credit_key, uint32
|
|||
|
||||
memcpy(hdr->epurse, resp, sizeof(hdr->epurse));
|
||||
*status |= FLAG_ICLASS_CC;
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
// read App Issuer Area block 2
|
||||
|
@ -1375,18 +1375,18 @@ static bool select_iclass_tag_ex(uint8_t *card_data, bool use_credit_key, uint32
|
|||
|
||||
start_time = *eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
|
||||
iclass_send_as_reader(read_aia, sizeof(read_aia), &start_time, eof_time);
|
||||
|
||||
|
||||
// expect a 10-byte response here
|
||||
len = GetIso15693AnswerFromTag(resp, sizeof(resp), ICLASS_READER_TIMEOUT_OTHERS, eof_time);
|
||||
if (len != 10)
|
||||
return false;
|
||||
|
||||
if (status) {
|
||||
if (status) {
|
||||
*status |= FLAG_ICLASS_AIA;
|
||||
memcpy(card_data + (8 * 2), resp, 8);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1424,8 +1424,8 @@ void ReaderIClass(uint8_t flags) {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
// Page mapping for secure mode
|
||||
|
||||
// Page mapping for secure mode
|
||||
// 0 : CSN
|
||||
// 1 : Configuration
|
||||
// 2 : e-purse
|
||||
|
@ -1433,22 +1433,22 @@ void ReaderIClass(uint8_t flags) {
|
|||
// 4 : kc / credit / aa1 (write-only)
|
||||
// 5 : AIA, Application issuer area
|
||||
//
|
||||
// Page mapping for non secure mode
|
||||
// Page mapping for non secure mode
|
||||
// 0 : CSN
|
||||
// 1 : Configuration
|
||||
// 2 : AIA, Application issuer area
|
||||
|
||||
// Return to client, e 6 * 8 bytes of data.
|
||||
// with 0xFF:s in block 3 and 4.
|
||||
|
||||
|
||||
LED_B_ON();
|
||||
reply_mix(CMD_ACK, result_status, 0, 0, card_data, sizeof(card_data));
|
||||
|
||||
|
||||
//Send back to client, but don't bother if we already sent this -
|
||||
// only useful if looping in arm (not try_once && not abort_after_read)
|
||||
/*
|
||||
if (memcmp(last_csn, card_data, 8) != 0) {
|
||||
|
||||
|
||||
reply_mix(CMD_ACK, result_status, 0, 0, card_data, sizeof(card_data));
|
||||
if (flag_readonce) {
|
||||
LED_B_OFF();
|
||||
|
@ -1465,12 +1465,12 @@ void ReaderIClass(uint8_t flags) {
|
|||
// reply_mix(CMD_ACK, result_status, 0, 0, card_data, 0);
|
||||
// }
|
||||
|
||||
switch_off();
|
||||
switch_off();
|
||||
}
|
||||
|
||||
// turn off afterwards
|
||||
void ReaderIClass_Replay(uint8_t *rnr, uint8_t *mac) {
|
||||
|
||||
|
||||
BigBuf_free();
|
||||
|
||||
uint8_t check[] = { ICLASS_CMD_CHECK, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
@ -1488,11 +1488,11 @@ void ReaderIClass_Replay(uint8_t *rnr, uint8_t *mac) {
|
|||
|
||||
uint32_t start_time = 0;
|
||||
uint32_t eof_time = 0;
|
||||
|
||||
|
||||
Iso15693InitReader();
|
||||
|
||||
picopass_hdr hdr = {0};
|
||||
bool res = select_iclass_tag( (uint8_t *)&hdr, false, &eof_time);
|
||||
bool res = select_iclass_tag((uint8_t *)&hdr, false, &eof_time);
|
||||
if (res == false) {
|
||||
reply_ng(CMD_HF_ICLASS_REPLAY, PM3_ETIMEOUT, NULL, 0);
|
||||
switch_off();
|
||||
|
@ -1513,22 +1513,22 @@ void ReaderIClass_Replay(uint8_t *rnr, uint8_t *mac) {
|
|||
uint8_t mem = hdr.conf.mem_config;
|
||||
uint8_t cardsize = ((mem & 0x80) == 0x80) ? 255 : 32;
|
||||
|
||||
/*
|
||||
static struct memory_t {
|
||||
int k16;
|
||||
int book;
|
||||
int k2;
|
||||
int lockauth;
|
||||
int keyaccess;
|
||||
} memory;
|
||||
/*
|
||||
static struct memory_t {
|
||||
int k16;
|
||||
int book;
|
||||
int k2;
|
||||
int lockauth;
|
||||
int keyaccess;
|
||||
} memory;
|
||||
|
||||
// memory.k16 = ((mem & 0x80) == 0x80);
|
||||
// memory.book = ((mem & 0x20) == 0x20);
|
||||
// memory.k2 = ((mem & 0x08) == 0x08);
|
||||
// memory.lockauth = ((mem & 0x02) == 0x02);
|
||||
// memory.keyaccess = ((mem & 0x01) == 0x01);
|
||||
// uint8_t cardsize = memory.k16 ? 255 : 32;
|
||||
*/
|
||||
// memory.k16 = ((mem & 0x80) == 0x80);
|
||||
// memory.book = ((mem & 0x20) == 0x20);
|
||||
// memory.k2 = ((mem & 0x08) == 0x08);
|
||||
// memory.lockauth = ((mem & 0x02) == 0x02);
|
||||
// memory.keyaccess = ((mem & 0x01) == 0x01);
|
||||
// uint8_t cardsize = memory.k16 ? 255 : 32;
|
||||
*/
|
||||
|
||||
bool dumpsuccess = true;
|
||||
|
||||
|
@ -1576,11 +1576,11 @@ bool authenticate_iclass_tag(iclass_auth_req_t *payload, picopass_hdr *hdr, uint
|
|||
uint8_t mac[4] = {0};
|
||||
uint8_t resp_auth[4] = {0};
|
||||
uint8_t ccnr[12] = {0};
|
||||
|
||||
|
||||
uint8_t *pmac = mac;
|
||||
if (mac_out)
|
||||
pmac = mac_out;
|
||||
|
||||
|
||||
memcpy(ccnr, hdr->epurse, sizeof(hdr->epurse));
|
||||
|
||||
if (payload->use_raw)
|
||||
|
@ -1639,14 +1639,14 @@ void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain) {
|
|||
// fresh start
|
||||
switch_off();
|
||||
SpinDelay(20);
|
||||
|
||||
|
||||
Iso15693InitReader();
|
||||
|
||||
uint32_t start_time = 0, eof_time = 0;
|
||||
|
||||
if (select_iclass_tag(card_data, use_credit_key, &eof_time) == false)
|
||||
goto out;
|
||||
|
||||
|
||||
start_time = eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
|
||||
|
||||
// since select_iclass_tag call sends s readcheck, we start with sending first response.
|
||||
|
@ -1715,13 +1715,13 @@ void iClass_ReadBlock(uint8_t *msg) {
|
|||
|
||||
uint8_t cmd_read[] = {ICLASS_CMD_READ_OR_IDENTIFY, payload->blockno, 0x00, 0x00};
|
||||
AddCrc(cmd_read + 1, 1);
|
||||
|
||||
|
||||
Iso15693InitReader();
|
||||
|
||||
|
||||
// select tag.
|
||||
uint32_t eof_time = 0;
|
||||
picopass_hdr hdr = {0};
|
||||
bool res = select_iclass_tag( (uint8_t *)&hdr, payload->use_credit_key, &eof_time);
|
||||
bool res = select_iclass_tag((uint8_t *)&hdr, payload->use_credit_key, &eof_time);
|
||||
if (res == false) {
|
||||
if (payload->send_reply) {
|
||||
response.isOK = res;
|
||||
|
@ -1731,10 +1731,10 @@ void iClass_ReadBlock(uint8_t *msg) {
|
|||
}
|
||||
|
||||
uint32_t start_time = eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
|
||||
|
||||
// authenticate
|
||||
|
||||
// authenticate
|
||||
if (payload->do_auth) {
|
||||
|
||||
|
||||
res = authenticate_iclass_tag(payload, &hdr, &start_time, &eof_time, NULL);
|
||||
if (res == false) {
|
||||
if (payload->send_reply) {
|
||||
|
@ -1751,8 +1751,8 @@ void iClass_ReadBlock(uint8_t *msg) {
|
|||
uint8_t resp[10];
|
||||
res = iclass_send_cmd_with_retries(cmd_read, sizeof(cmd_read), resp, sizeof(resp), 10, 3, &start_time, ICLASS_READER_TIMEOUT_OTHERS, &eof_time);
|
||||
if (res) {
|
||||
memcpy(response.data, resp, sizeof(response.data));
|
||||
if (payload->send_reply) {
|
||||
memcpy(response.data, resp, sizeof(response.data));
|
||||
if (payload->send_reply) {
|
||||
reply_ng(CMD_HF_ICLASS_READBL, PM3_SUCCESS, (uint8_t *)&response, sizeof(response));
|
||||
}
|
||||
} else {
|
||||
|
@ -1763,16 +1763,16 @@ void iClass_ReadBlock(uint8_t *msg) {
|
|||
}
|
||||
|
||||
out:
|
||||
switch_off();
|
||||
switch_off();
|
||||
}
|
||||
|
||||
|
||||
// Dump command seems to dump a block related portion of card memory.
|
||||
// I suppose it will need to do an authentatication to AA1, read its blocks by calling this.
|
||||
// then authenticate AA2, and read those blocks by calling this.
|
||||
// By the looks at it only 2K cards is supported, or first page dumps on larger cards.
|
||||
// turn off afterwards
|
||||
// turn off afterwards
|
||||
void iClass_Dump(uint8_t *msg) {
|
||||
|
||||
|
||||
BigBuf_free();
|
||||
|
||||
iclass_dump_req_t *cmd = (iclass_dump_req_t *)msg;
|
||||
|
@ -1790,11 +1790,11 @@ void iClass_Dump(uint8_t *msg) {
|
|||
memset(dataout, 0xFF, ICLASS_16KS_SIZE);
|
||||
|
||||
Iso15693InitReader();
|
||||
|
||||
|
||||
// select tag.
|
||||
uint32_t eof_time = 0;
|
||||
picopass_hdr hdr = {0};
|
||||
bool res = select_iclass_tag( (uint8_t *)&hdr, req->use_credit_key, &eof_time);
|
||||
bool res = select_iclass_tag((uint8_t *)&hdr, req->use_credit_key, &eof_time);
|
||||
if (res == false) {
|
||||
if (req->send_reply) {
|
||||
reply_ng(CMD_HF_ICLASS_DUMP, PM3_ETIMEOUT, NULL, 0);
|
||||
|
@ -1802,10 +1802,10 @@ void iClass_Dump(uint8_t *msg) {
|
|||
switch_off();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
uint32_t start_time = eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
|
||||
|
||||
// authenticate
|
||||
|
||||
// authenticate
|
||||
if (req->do_auth) {
|
||||
res = authenticate_iclass_tag(req, &hdr, &start_time, &eof_time, NULL);
|
||||
if (res == false) {
|
||||
|
@ -1838,7 +1838,7 @@ void iClass_Dump(uint8_t *msg) {
|
|||
}
|
||||
}
|
||||
|
||||
switch_off();
|
||||
switch_off();
|
||||
|
||||
// copy diversified key back.
|
||||
if (req->do_auth) {
|
||||
|
@ -1870,27 +1870,27 @@ static bool iclass_writeblock_ext(uint8_t blockno, uint8_t *data) {
|
|||
memcpy(write + 2, data, 12); // data + mac
|
||||
AddCrc(write + 1, 13);
|
||||
|
||||
uint8_t resp[10] = {0};
|
||||
uint8_t resp[10] = {0};
|
||||
uint32_t eof_time = 0, start_time = 0;
|
||||
bool isOK = iclass_send_cmd_with_retries(write, sizeof(write), resp, sizeof(resp), 10, 3, &start_time, ICLASS_READER_TIMEOUT_UPDATE, &eof_time);
|
||||
if (isOK == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
uint8_t all_ff[8] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
|
||||
if (blockno == 2) {
|
||||
// check response. e-purse update swaps first and second half
|
||||
if (memcmp(data + 4, resp, 4) || memcmp(data, resp + 4, 4)) {
|
||||
if (memcmp(data + 4, resp, 4) || memcmp(data, resp + 4, 4)) {
|
||||
return false;
|
||||
}
|
||||
} else if (blockno == 3 || blockno == 4) {
|
||||
// check response. Key updates always return 0xffffffffffffffff
|
||||
if (memcmp(all_ff, resp, 8)) {
|
||||
if (memcmp(all_ff, resp, 8)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// check response. All other updates return unchanged data
|
||||
if (memcmp(data, resp, 8)) {
|
||||
if (memcmp(data, resp, 8)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1900,19 +1900,19 @@ static bool iclass_writeblock_ext(uint8_t blockno, uint8_t *data) {
|
|||
|
||||
// turn off afterwards
|
||||
void iClass_WriteBlock(uint8_t *msg) {
|
||||
|
||||
|
||||
LED_A_ON();
|
||||
|
||||
|
||||
iclass_writeblock_req_t *payload = (iclass_writeblock_req_t *)msg;
|
||||
|
||||
uint8_t write[16] = { 0x80 | ICLASS_CMD_UPDATE, payload->req.blockno };
|
||||
|
||||
|
||||
Iso15693InitReader();
|
||||
|
||||
|
||||
// select tag.
|
||||
uint32_t eof_time = 0;
|
||||
picopass_hdr hdr = {0};
|
||||
bool res = select_iclass_tag( (uint8_t *)&hdr, payload->req.use_credit_key, &eof_time);
|
||||
bool res = select_iclass_tag((uint8_t *)&hdr, payload->req.use_credit_key, &eof_time);
|
||||
if (res == false) {
|
||||
goto out;
|
||||
}
|
||||
|
@ -1921,7 +1921,7 @@ void iClass_WriteBlock(uint8_t *msg) {
|
|||
|
||||
uint8_t mac[4] = {0};
|
||||
|
||||
// authenticate
|
||||
// authenticate
|
||||
if (payload->req.do_auth) {
|
||||
|
||||
res = authenticate_iclass_tag(&payload->req, &hdr, &start_time, &eof_time, mac);
|
||||
|
@ -1939,13 +1939,13 @@ void iClass_WriteBlock(uint8_t *msg) {
|
|||
doMAC_N(wb, sizeof(wb), hdr.key_c, mac);
|
||||
else
|
||||
doMAC_N(wb, sizeof(wb), hdr.key_d, mac);
|
||||
|
||||
|
||||
memcpy(write + 2, payload->data, 8); // data
|
||||
memcpy(write + 10, mac, sizeof(mac)); // mac
|
||||
AddCrc(write + 1, 13);
|
||||
|
||||
start_time = eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
|
||||
|
||||
|
||||
uint8_t resp[10] = {0};
|
||||
res = iclass_send_cmd_with_retries(write, sizeof(write), resp, sizeof(resp), 10, 3, &start_time, ICLASS_READER_TIMEOUT_UPDATE, &eof_time);
|
||||
if (res == false) {
|
||||
|
@ -1956,19 +1956,19 @@ void iClass_WriteBlock(uint8_t *msg) {
|
|||
uint8_t all_ff[8] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
|
||||
if (payload->req.blockno == 2) {
|
||||
// check response. e-purse update swaps first and second half
|
||||
if (memcmp(payload->data + 4, resp, 4) || memcmp(payload->data, resp + 4, 4)) {
|
||||
if (memcmp(payload->data + 4, resp, 4) || memcmp(payload->data, resp + 4, 4)) {
|
||||
res = false;
|
||||
goto out;
|
||||
}
|
||||
} else if (payload->req.blockno == 3 || payload->req.blockno == 4) {
|
||||
// check response. Key updates always return 0xffffffffffffffff
|
||||
if (memcmp(all_ff, resp, 8)) {
|
||||
if (memcmp(all_ff, resp, 8)) {
|
||||
res = false;
|
||||
goto out;
|
||||
}
|
||||
} else {
|
||||
// check response. All other updates return unchanged data
|
||||
if (memcmp(payload->data, resp, 8)) {
|
||||
if (memcmp(payload->data, resp, 8)) {
|
||||
res = false;
|
||||
goto out;
|
||||
}
|
||||
|
@ -1986,10 +1986,10 @@ void iClass_Clone(uint8_t startblock, uint8_t endblock, uint8_t *data) {
|
|||
}
|
||||
|
||||
void iClass_Restore(uint8_t *msg) {
|
||||
|
||||
|
||||
iclass_restore_req_t *cmd = (iclass_restore_req_t *)msg;
|
||||
// iclass_auth_req_t *req = &cmd->req;
|
||||
|
||||
|
||||
LED_A_ON();
|
||||
uint16_t written = 0;
|
||||
uint16_t total_blocks = (cmd->end_block - cmd->start_block) + 1;
|
||||
|
|
|
@ -729,7 +729,7 @@ void RAMFUNC SniffIso14443a(uint8_t param) {
|
|||
static void CodeIso14443aAsTagPar(const uint8_t *cmd, uint16_t len, uint8_t *par, bool collision) {
|
||||
|
||||
tosend_reset();
|
||||
|
||||
|
||||
tosend_t *ts = get_tosend();
|
||||
|
||||
// Correction bit, might be removed when not needed
|
||||
|
@ -798,7 +798,7 @@ static void Code4bitAnswerAsTag(uint8_t cmd) {
|
|||
uint8_t b = cmd;
|
||||
|
||||
tosend_reset();
|
||||
|
||||
|
||||
tosend_t *ts = get_tosend();
|
||||
|
||||
// Correction bit, might be removed when not needed
|
||||
|
@ -888,7 +888,7 @@ bool prepare_tag_modulation(tag_response_info_t *response_info, size_t max_buffe
|
|||
CodeIso14443aAsTag(response_info->response, response_info->response_n);
|
||||
|
||||
tosend_t *ts = get_tosend();
|
||||
|
||||
|
||||
// Make sure we do not exceed the free buffer space
|
||||
if (ts->max > max_buffer_size) {
|
||||
Dbprintf("ToSend buffer, Out-of-bound, when modulating bits for tag answer:");
|
||||
|
@ -908,7 +908,7 @@ bool prepare_tag_modulation(tag_response_info_t *response_info, size_t max_buffe
|
|||
bool prepare_allocated_tag_modulation(tag_response_info_t *response_info, uint8_t **buffer, size_t *max_buffer_size) {
|
||||
|
||||
tosend_t *ts = get_tosend();
|
||||
|
||||
|
||||
// Retrieve and store the current buffer index
|
||||
response_info->modulation = *buffer;
|
||||
|
||||
|
@ -1977,7 +1977,7 @@ int EmSendCmd14443aRaw(uint8_t *resp, uint16_t respLen) {
|
|||
|
||||
int EmSend4bit(uint8_t resp) {
|
||||
Code4bitAnswerAsTag(resp);
|
||||
tosend_t *ts = get_tosend();
|
||||
tosend_t *ts = get_tosend();
|
||||
int res = EmSendCmd14443aRaw(ts->buf, ts->max);
|
||||
// do the tracing for the previous reader request and this tag answer:
|
||||
uint8_t par[1] = {0x00};
|
||||
|
@ -1999,7 +1999,7 @@ int EmSendCmdPar(uint8_t *resp, uint16_t respLen, uint8_t *par) {
|
|||
}
|
||||
int EmSendCmdParEx(uint8_t *resp, uint16_t respLen, uint8_t *par, bool collision) {
|
||||
CodeIso14443aAsTagPar(resp, respLen, par, collision);
|
||||
tosend_t *ts = get_tosend();
|
||||
tosend_t *ts = get_tosend();
|
||||
int res = EmSendCmd14443aRaw(ts->buf, ts->max);
|
||||
|
||||
// do the tracing for the previous reader request and this tag answer:
|
||||
|
@ -2162,7 +2162,7 @@ void ReaderTransmitBitsPar(uint8_t *frame, uint16_t bits, uint8_t *par, uint32_t
|
|||
|
||||
CodeIso14443aBitsAsReaderPar(frame, bits, par);
|
||||
// Send command to tag
|
||||
tosend_t *ts = get_tosend();
|
||||
tosend_t *ts = get_tosend();
|
||||
TransmitFor14443a(ts->buf, ts->max, timing);
|
||||
if (g_trigger) LED_A_ON();
|
||||
|
||||
|
|
|
@ -187,12 +187,12 @@ static void CodeIso14443bAsTag(const uint8_t *cmd, int len) {
|
|||
|
||||
// Send EOF.
|
||||
// 10-11 ETU * 4 sample rate = ZEROS
|
||||
for(i = 0; i < 10; i++) {
|
||||
for (i = 0; i < 10; i++) {
|
||||
SEND4STUFFBIT(0);
|
||||
}
|
||||
|
||||
|
||||
// why this?
|
||||
for(i = 0; i < 2; i++) {
|
||||
for (i = 0; i < 2; i++) {
|
||||
SEND4STUFFBIT(1);
|
||||
}
|
||||
|
||||
|
@ -448,7 +448,7 @@ static int GetIso14443bCommandFromReader(uint8_t *received, uint16_t *len) {
|
|||
while (BUTTON_PRESS() == false) {
|
||||
WDT_HIT();
|
||||
|
||||
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
for (uint8_t mask = 0x80; mask != 0x00; mask >>= 1) {
|
||||
if (Handle14443bReaderUartBit(b & mask)) {
|
||||
|
@ -501,11 +501,11 @@ void SimulateIso14443bTag(uint32_t pupi) {
|
|||
// supports only 106kBit/s in both directions, max frame size = 32Bytes,
|
||||
// supports ISO14443-4, FWI=8 (77ms), NAD supported, CID not supported:
|
||||
uint8_t respATQB[] = {
|
||||
0x50,
|
||||
0x82, 0x0d, 0xe1, 0x74,
|
||||
0x20, 0x38, 0x19,
|
||||
0x22, 0x00, 0x21, 0x85,
|
||||
0x5e, 0xd7
|
||||
0x50,
|
||||
0x82, 0x0d, 0xe1, 0x74,
|
||||
0x20, 0x38, 0x19,
|
||||
0x22, 0x00, 0x21, 0x85,
|
||||
0x5e, 0xd7
|
||||
};
|
||||
|
||||
// response to HLTB and ATTRIB
|
||||
|
@ -516,7 +516,7 @@ void SimulateIso14443bTag(uint32_t pupi) {
|
|||
num_to_bytes(pupi, 4, respATQB + 1);
|
||||
AddCrc14B(respATQB, 12);
|
||||
}
|
||||
|
||||
|
||||
// setup device.
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
|
||||
|
@ -537,7 +537,7 @@ void SimulateIso14443bTag(uint32_t pupi) {
|
|||
int vHf = 0; // in mV
|
||||
|
||||
tosend_t *ts = get_tosend();
|
||||
|
||||
|
||||
uint8_t *receivedCmd = BigBuf_malloc(MAX_FRAME_SIZE);
|
||||
|
||||
// prepare "ATQB" tag answer (encoded):
|
||||
|
@ -556,7 +556,7 @@ void SimulateIso14443bTag(uint32_t pupi) {
|
|||
// Simulation loop
|
||||
while (BUTTON_PRESS() == false) {
|
||||
WDT_HIT();
|
||||
|
||||
|
||||
//iceman: limit with 2000 times..
|
||||
if (data_available()) {
|
||||
break;
|
||||
|
@ -588,7 +588,7 @@ void SimulateIso14443bTag(uint32_t pupi) {
|
|||
// WUP in HALTED state
|
||||
if (len == 5) {
|
||||
if ((receivedCmd[0] == ISO14443B_REQB && (receivedCmd[2] & 0x8) == 0x8 && cardSTATE == SIM_HALTED) ||
|
||||
receivedCmd[0] == ISO14443B_REQB) {
|
||||
receivedCmd[0] == ISO14443B_REQB) {
|
||||
LogTrace(receivedCmd, len, 0, 0, NULL, true);
|
||||
cardSTATE = SIM_SELECTING;
|
||||
}
|
||||
|
@ -668,7 +668,7 @@ void SimulateIso14443bTag(uint32_t pupi) {
|
|||
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("Emulator stopped. Trace length: %d ", BigBuf_get_traceLen());
|
||||
|
||||
|
||||
switch_off(); //simulate
|
||||
}
|
||||
|
||||
|
@ -733,7 +733,7 @@ static RAMFUNC int Handle14443bTagSamplesDemod(uint16_t amplitude) {
|
|||
Demod.posCount = 0; // start of SOF sequence
|
||||
} else {
|
||||
// maximum length of TR1 = 200 1/fs
|
||||
if (Demod.posCount > 200 / 4){
|
||||
if (Demod.posCount > 200 / 4) {
|
||||
Demod.state = DEMOD_UNSYNCD;
|
||||
}
|
||||
}
|
||||
|
@ -851,9 +851,9 @@ static int GetTagSamplesFor14443bDemod(int timeout) {
|
|||
// wait for last transfer to complete
|
||||
while (!(AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXEMPTY))
|
||||
|
||||
// Setup and start DMA.
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER);
|
||||
|
||||
// Setup and start DMA.
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER);
|
||||
|
||||
// The DMA buffer, used to stream samples from the FPGA
|
||||
dmabuf16_t *dma = get_dma16();
|
||||
if (FpgaSetupSscDma((uint8_t *) dma->buf, DMA_BUFFER_SIZE) == false) {
|
||||
|
@ -870,8 +870,8 @@ static int GetTagSamplesFor14443bDemod(int timeout) {
|
|||
// uint32_t dma_start_time;
|
||||
uint16_t *upTo = dma->buf;
|
||||
|
||||
for(;;) {
|
||||
uint16_t behindBy = ((uint16_t*)AT91C_BASE_PDC_SSC->PDC_RPR - upTo) & (DMA_BUFFER_SIZE - 1);
|
||||
for (;;) {
|
||||
uint16_t behindBy = ((uint16_t *)AT91C_BASE_PDC_SSC->PDC_RPR - upTo) & (DMA_BUFFER_SIZE - 1);
|
||||
|
||||
if (behindBy == 0) continue;
|
||||
|
||||
|
@ -884,7 +884,7 @@ static int GetTagSamplesFor14443bDemod(int timeout) {
|
|||
*/
|
||||
|
||||
volatile uint16_t tagdata = *upTo++;
|
||||
|
||||
|
||||
if (upTo >= dma->buf + DMA_BUFFER_SIZE) { // we have read all of the DMA buffer content.
|
||||
upTo = dma->buf; // start reading the circular buffer from the beginning
|
||||
if (behindBy > (9 * DMA_BUFFER_SIZE / 10)) {
|
||||
|
@ -893,7 +893,7 @@ static int GetTagSamplesFor14443bDemod(int timeout) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_ENDRX)) { // DMA Counter Register had reached 0, already rotated.
|
||||
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dma->buf; // refresh the DMA Next Buffer and
|
||||
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE; // DMA Next Counter registers
|
||||
|
@ -904,7 +904,7 @@ static int GetTagSamplesFor14443bDemod(int timeout) {
|
|||
break;
|
||||
}
|
||||
|
||||
if(samples > timeout && Demod.state < DEMOD_PHASE_REF_TRAINING) {
|
||||
if (samples > timeout && Demod.state < DEMOD_PHASE_REF_TRAINING) {
|
||||
ret = -1;
|
||||
LED_C_OFF();
|
||||
break;
|
||||
|
@ -918,7 +918,7 @@ static int GetTagSamplesFor14443bDemod(int timeout) {
|
|||
}
|
||||
|
||||
if (Demod.len > 0) {
|
||||
LogTrace(Demod.output, Demod.len, 0, 0, NULL, false);
|
||||
LogTrace(Demod.output, Demod.len, 0, 0, NULL, false);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -933,23 +933,23 @@ static void TransmitFor14443b_AsReader(void) {
|
|||
|
||||
LED_B_ON();
|
||||
tosend_t *ts = get_tosend();
|
||||
|
||||
|
||||
for (int c = 0; c < ts->max; c++) {
|
||||
uint8_t data = ts->buf[c];
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
uint16_t send_word = (data & 0x80) ? 0x0000 : 0xffff;
|
||||
|
||||
|
||||
while (!(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY))) ;
|
||||
|
||||
AT91C_BASE_SSC->SSC_THR = send_word;
|
||||
|
||||
AT91C_BASE_SSC->SSC_THR = send_word;
|
||||
|
||||
while (!(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY))) ;
|
||||
AT91C_BASE_SSC->SSC_THR = send_word;
|
||||
|
||||
data <<= 1;
|
||||
}
|
||||
WDT_HIT();
|
||||
WDT_HIT();
|
||||
}
|
||||
LED_B_OFF();
|
||||
}
|
||||
|
@ -978,7 +978,7 @@ static void CodeIso14443bAsReader(const uint8_t *cmd, int len) {
|
|||
|
||||
// Send SOF
|
||||
// 10-11 ETUs of ZERO
|
||||
for (int i = 0; i < 10; i++)
|
||||
for (int i = 0; i < 10; i++)
|
||||
tosend_stuffbit(0);
|
||||
|
||||
|
||||
|
@ -1021,7 +1021,7 @@ static void CodeIso14443bAsReader(const uint8_t *cmd, int len) {
|
|||
// 8ETUS minum?
|
||||
// Per specification, Subcarrier must be stopped no later than 2 ETUs after EOF.
|
||||
// I'm guessing this is for the FPGA to be able to send all bits before we switch to listening mode
|
||||
|
||||
|
||||
// ensure that last byte is filled up
|
||||
for (int i = 0; i < 8 ; ++i)
|
||||
tosend_stuffbit(1);
|
||||
|
@ -1068,7 +1068,7 @@ uint8_t iso14443b_apdu(uint8_t const *message, size_t message_length, uint8_t *r
|
|||
|
||||
if (ret < 3) {
|
||||
LED_A_OFF();
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// VALIDATE CRC
|
||||
|
@ -1081,7 +1081,7 @@ uint8_t iso14443b_apdu(uint8_t const *message, size_t message_length, uint8_t *r
|
|||
memcpy(response, Demod.output, Demod.len);
|
||||
|
||||
return Demod.len;
|
||||
LED_A_OFF();
|
||||
LED_A_OFF();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1322,7 +1322,7 @@ void ReadSTMemoryIso14443b(uint8_t numofblocks) {
|
|||
if (i == 0xff) break;
|
||||
++i;
|
||||
}
|
||||
|
||||
|
||||
// Todo: iceman: send back read data to client.
|
||||
// reply_ng(..., );
|
||||
|
||||
|
@ -1419,7 +1419,7 @@ void RAMFUNC SniffIso14443b(void) {
|
|||
time_0 = GetCountSspClk();
|
||||
|
||||
// loop and listen
|
||||
for(;;) {
|
||||
for (;;) {
|
||||
|
||||
int behindBy = (lastRxCounter - AT91C_BASE_PDC_SSC->PDC_RCR) & (DMA_BUFFER_SIZE - 1);
|
||||
if (behindBy > maxBehindBy) {
|
||||
|
@ -1437,7 +1437,7 @@ void RAMFUNC SniffIso14443b(void) {
|
|||
if (upTo >= dma->buf + DMA_BUFFER_SIZE) { // we have read all of the DMA buffer content.
|
||||
upTo = dma->buf; // start reading the circular buffer from the beginning again
|
||||
lastRxCounter += DMA_BUFFER_SIZE;
|
||||
if (behindBy > (9 * DMA_BUFFER_SIZE / 10)) {
|
||||
if (behindBy > (9 * DMA_BUFFER_SIZE / 10)) {
|
||||
Dbprintf("About to blow circular buffer - aborted! behindBy=%d", behindBy);
|
||||
break;
|
||||
}
|
||||
|
@ -1462,7 +1462,7 @@ void RAMFUNC SniffIso14443b(void) {
|
|||
LED_A_INV();
|
||||
|
||||
if (Handle14443bReaderUartBit(ci & 0x01)) {
|
||||
|
||||
|
||||
time_stop = GetCountSspClk() - time_0;
|
||||
LogTrace(Uart.output, Uart.byteCnt, time_start, time_stop, NULL, true);
|
||||
Uart14bReset();
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
#include "ticks.h"
|
||||
#include "BigBuf.h"
|
||||
#include "crc16.h"
|
||||
|
||||
|
||||
// Delays in SSP_CLK ticks.
|
||||
// SSP_CLK runs at 13,56MHz / 32 = 423.75kHz when simulating a tag
|
||||
#define DELAY_READER_TO_ARM 8
|
||||
|
@ -106,7 +106,7 @@
|
|||
|
||||
static void BuildIdentifyRequest(uint8_t *cmd);
|
||||
|
||||
// ---------------------------
|
||||
// ---------------------------
|
||||
|
||||
// Signal Processing
|
||||
// ---------------------------
|
||||
|
@ -114,12 +114,12 @@ static void BuildIdentifyRequest(uint8_t *cmd);
|
|||
// prepare data using "1 out of 4" code for later transmission
|
||||
// resulting data rate is 26.48 kbit/s (fc/512)
|
||||
// cmd ... data
|
||||
// n ... length of data
|
||||
static uint8_t encode15_lut[] = {
|
||||
0x40, // 01000000
|
||||
0x10, // 00010000
|
||||
0x04, // 00000100
|
||||
0x01 // 00000001
|
||||
// n ... length of data
|
||||
static uint8_t encode15_lut[] = {
|
||||
0x40, // 01000000
|
||||
0x10, // 00010000
|
||||
0x04, // 00000100
|
||||
0x01 // 00000001
|
||||
};
|
||||
|
||||
void CodeIso15693AsReader(uint8_t *cmd, int n) {
|
||||
|
@ -132,16 +132,16 @@ void CodeIso15693AsReader(uint8_t *cmd, int n) {
|
|||
|
||||
// data
|
||||
for (int i = 0; i < n; i++) {
|
||||
|
||||
|
||||
volatile uint8_t b = (cmd[i] >> 0) & 0x03;
|
||||
ts->buf[++ts->max] = encode15_lut[b];
|
||||
|
||||
|
||||
b = (cmd[i] >> 2) & 0x03;
|
||||
ts->buf[++ts->max] = encode15_lut[b];
|
||||
|
||||
b = (cmd[i] >> 4) & 0x03;
|
||||
ts->buf[++ts->max] = encode15_lut[b];
|
||||
|
||||
|
||||
b = (cmd[i] >> 6) & 0x03;
|
||||
ts->buf[++ts->max] = encode15_lut[b];
|
||||
}
|
||||
|
@ -167,12 +167,12 @@ static void CodeIso15693AsReader256(uint8_t *cmd, int n) {
|
|||
|
||||
tosend_reset();
|
||||
tosend_t *ts = get_tosend();
|
||||
|
||||
|
||||
// SOF for 1of256
|
||||
ts->buf[++ts->max] = 0x81; //10000001
|
||||
|
||||
// data
|
||||
for(int i = 0; i < n; i++) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j <= 255; j++) {
|
||||
if (cmd[i] == j) {
|
||||
tosend_stuffbit(0);
|
||||
|
@ -189,7 +189,7 @@ static void CodeIso15693AsReader256(uint8_t *cmd, int n) {
|
|||
ts->max++;
|
||||
}
|
||||
|
||||
static const uint8_t encode_4bits[16] = {
|
||||
static const uint8_t encode_4bits[16] = {
|
||||
// 0 1 2 3
|
||||
0xaa, 0x6a, 0x9a, 0x5a,
|
||||
// 4 5 6 7
|
||||
|
@ -292,7 +292,7 @@ void TransmitTo15693Reader(const uint8_t *cmd, size_t len, uint32_t *start_time,
|
|||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SIMULATOR | FPGA_HF_SIMULATOR_MODULATE_424K);
|
||||
|
||||
uint32_t modulation_start_time = *start_time - DELAY_ARM_TO_READER + 3 * 8; // no need to transfer the unmodulated start of SOF
|
||||
|
||||
|
||||
while (GetCountSspClk() > (modulation_start_time & 0xfffffff8) + 3) { // we will miss the intended time
|
||||
if (slot_time) {
|
||||
modulation_start_time += slot_time; // use next available slot
|
||||
|
@ -310,14 +310,14 @@ void TransmitTo15693Reader(const uint8_t *cmd, size_t len, uint32_t *start_time,
|
|||
|
||||
LED_C_ON();
|
||||
uint8_t bits_to_shift = 0x00;
|
||||
uint8_t bits_to_send = 0x00;
|
||||
|
||||
uint8_t bits_to_send = 0x00;
|
||||
|
||||
for (size_t c = 0; c < len; c++) {
|
||||
for (int i = (c == 0 ? 4 : 7); i >= 0; i--) {
|
||||
|
||||
uint8_t cmd_bits = ((cmd[c] >> i) & 0x01) ? 0xff : 0x00;
|
||||
|
||||
for (int j = 0; j < (slow ? 4 : 1); ) {
|
||||
for (int j = 0; j < (slow ? 4 : 1);) {
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
|
||||
bits_to_send = bits_to_shift << (8 - shift_delay) | cmd_bits >> shift_delay;
|
||||
AT91C_BASE_SSC->SSC_THR = bits_to_send;
|
||||
|
@ -332,7 +332,7 @@ void TransmitTo15693Reader(const uint8_t *cmd, size_t len, uint32_t *start_time,
|
|||
// send the remaining bits, padded with 0:
|
||||
bits_to_send = bits_to_shift << (8 - shift_delay);
|
||||
if (bits_to_send) {
|
||||
for ( ; ; ) {
|
||||
for (; ;) {
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
|
||||
AT91C_BASE_SSC->SSC_THR = bits_to_send;
|
||||
break;
|
||||
|
@ -631,7 +631,7 @@ static void DecodeTagInit(DecodeTag_t *tag, uint8_t *data, uint16_t max_len) {
|
|||
/*
|
||||
* Receive and decode the tag response, also log to tracebuffer
|
||||
*/
|
||||
int GetIso15693AnswerFromTag(uint8_t* response, uint16_t max_len, uint16_t timeout, uint32_t *eof_time) {
|
||||
int GetIso15693AnswerFromTag(uint8_t *response, uint16_t max_len, uint16_t timeout, uint32_t *eof_time) {
|
||||
|
||||
int samples = 0, ret = 0;
|
||||
|
||||
|
@ -661,10 +661,10 @@ int GetIso15693AnswerFromTag(uint8_t* response, uint16_t max_len, uint16_t timeo
|
|||
uint32_t dma_start_time = 0;
|
||||
uint16_t *upTo = dma->buf;
|
||||
|
||||
for(;;) {
|
||||
for (;;) {
|
||||
|
||||
volatile uint16_t behindBy = ((uint16_t*)AT91C_BASE_PDC_SSC->PDC_RPR - upTo) & (DMA_BUFFER_SIZE - 1);
|
||||
if (behindBy == 0)
|
||||
volatile uint16_t behindBy = ((uint16_t *)AT91C_BASE_PDC_SSC->PDC_RPR - upTo) & (DMA_BUFFER_SIZE - 1);
|
||||
if (behindBy == 0)
|
||||
continue;
|
||||
|
||||
samples++;
|
||||
|
@ -715,14 +715,14 @@ int GetIso15693AnswerFromTag(uint8_t* response, uint16_t max_len, uint16_t timeo
|
|||
|
||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
||||
Dbprintf("samples = %d, ret = %d, Decoder: state = %d, lastBit = %d, len = %d, bitCount = %d, posCount = %d, maxlen = %u",
|
||||
samples,
|
||||
ret,
|
||||
dt->state,
|
||||
dt->lastBit,
|
||||
dt->len,
|
||||
dt->bitCount,
|
||||
dt->posCount,
|
||||
dt->max_len
|
||||
samples,
|
||||
ret,
|
||||
dt->state,
|
||||
dt->lastBit,
|
||||
dt->len,
|
||||
dt->bitCount,
|
||||
dt->posCount,
|
||||
dt->max_len
|
||||
);
|
||||
Dbprintf("timing: sof_time = %d, eof_time = %d", (sof_time * 4), (*eof_time * 4));
|
||||
}
|
||||
|
@ -776,7 +776,7 @@ typedef struct {
|
|||
uint8_t *jam_search_string;
|
||||
} DecodeReader_t;
|
||||
|
||||
static void DecodeReaderInit(DecodeReader_t* reader, uint8_t *data, uint16_t max_len, uint8_t jam_search_len, uint8_t *jam_search_string) {
|
||||
static void DecodeReaderInit(DecodeReader_t *reader, uint8_t *data, uint16_t max_len, uint8_t jam_search_len, uint8_t *jam_search_string) {
|
||||
reader->output = data;
|
||||
reader->byteCountMax = max_len;
|
||||
reader->state = STATE_READER_UNSYNCD;
|
||||
|
@ -788,12 +788,12 @@ static void DecodeReaderInit(DecodeReader_t* reader, uint8_t *data, uint16_t max
|
|||
reader->jam_search_string = jam_search_string;
|
||||
}
|
||||
|
||||
static void DecodeReaderReset(DecodeReader_t* reader) {
|
||||
static void DecodeReaderReset(DecodeReader_t *reader) {
|
||||
reader->state = STATE_READER_UNSYNCD;
|
||||
}
|
||||
|
||||
//static inline __attribute__((always_inline))
|
||||
static int RAMFUNC Handle15693SampleFromReader(bool bit, DecodeReader_t *reader) {
|
||||
static int RAMFUNC Handle15693SampleFromReader(bool bit, DecodeReader_t *reader) {
|
||||
switch (reader->state) {
|
||||
case STATE_READER_UNSYNCD:
|
||||
// wait for unmodulated carrier
|
||||
|
@ -832,7 +832,7 @@ static void DecodeReaderReset(DecodeReader_t* reader) {
|
|||
reader->posCount++;
|
||||
|
||||
if (bit == false) { // detected a falling edge
|
||||
|
||||
|
||||
if (reader->posCount < 20) { // falling edge too early (nominally expected at 21 earliest)
|
||||
DecodeReaderReset(reader);
|
||||
} else if (reader->posCount < 23) { // SOF for 1 out of 4 coding
|
||||
|
@ -911,7 +911,7 @@ static void DecodeReaderReset(DecodeReader_t* reader) {
|
|||
// do nothing, keep waiting
|
||||
}
|
||||
} else { // unexpected falling edge
|
||||
DecodeReaderReset(reader);
|
||||
DecodeReaderReset(reader);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -924,14 +924,14 @@ static void DecodeReaderReset(DecodeReader_t* reader) {
|
|||
reader->sum1 = bit ? 1 : 0;
|
||||
|
||||
} else if (reader->posCount <= 4) {
|
||||
|
||||
|
||||
if (bit)
|
||||
reader->sum1++;
|
||||
|
||||
|
||||
} else if (reader->posCount == 5) {
|
||||
|
||||
|
||||
reader->sum2 = bit ? 1 : 0;
|
||||
|
||||
|
||||
} else {
|
||||
if (bit)
|
||||
reader->sum2++;
|
||||
|
@ -1098,9 +1098,9 @@ int GetIso15693CommandFromReader(uint8_t *received, size_t max_len, uint32_t *eo
|
|||
uint32_t dma_start_time = GetCountSspClk() & 0xfffffff8;
|
||||
|
||||
for (;;) {
|
||||
volatile uint16_t behindBy = ((uint8_t*)AT91C_BASE_PDC_SSC->PDC_RPR - upTo) & (DMA_BUFFER_SIZE - 1);
|
||||
volatile uint16_t behindBy = ((uint8_t *)AT91C_BASE_PDC_SSC->PDC_RPR - upTo) & (DMA_BUFFER_SIZE - 1);
|
||||
if (behindBy == 0) continue;
|
||||
|
||||
|
||||
if (samples == 0) {
|
||||
// DMA has transferred the very first data
|
||||
dma_start_time = GetCountSspClk() & 0xfffffff0;
|
||||
|
@ -1144,15 +1144,15 @@ int GetIso15693CommandFromReader(uint8_t *received, size_t max_len, uint32_t *eo
|
|||
|
||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
||||
Dbprintf("samples = %d, gotFrame = %d, Decoder: state = %d, len = %d, bitCount = %d, posCount = %d",
|
||||
samples, gotFrame, dr->state, dr->byteCount,
|
||||
dr->bitCount, dr->posCount);
|
||||
samples, gotFrame, dr->state, dr->byteCount,
|
||||
dr->bitCount, dr->posCount);
|
||||
}
|
||||
|
||||
if (dr->byteCount >= 0) {
|
||||
uint32_t sof_time = *eof_time
|
||||
- dr->byteCount * (dr->Coding == CODING_1_OUT_OF_4 ? 128 : 2048) // time for byte transfers
|
||||
- 32 // time for SOF transfer
|
||||
- 16; // time for EOF transfer
|
||||
- dr->byteCount * (dr->Coding == CODING_1_OUT_OF_4 ? 128 : 2048) // time for byte transfers
|
||||
- 32 // time for SOF transfer
|
||||
- 16; // time for EOF transfer
|
||||
LogTrace_ISO15693(dr->output, dr->byteCount, (sof_time * 32), (*eof_time * 32), NULL, true);
|
||||
}
|
||||
|
||||
|
@ -1192,8 +1192,8 @@ void AcquireRawAdcSamplesIso15693(void) {
|
|||
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER | FPGA_HF_READER_SUBCARRIER_424_KHZ | FPGA_HF_READER_MODE_RECEIVE_AMPLITUDE);
|
||||
|
||||
for(int c = 0; c < 4000; ) {
|
||||
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
for (int c = 0; c < 4000;) {
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
uint16_t r = AT91C_BASE_SSC->SSC_RHR;
|
||||
dest[c++] = r >> 5;
|
||||
}
|
||||
|
@ -1212,7 +1212,7 @@ void SniffIso15693(uint8_t jam_search_len, uint8_t *jam_search_string) {
|
|||
BigBuf_free();
|
||||
clear_trace();
|
||||
set_tracing(true);
|
||||
|
||||
|
||||
DecodeTag_t dtag = {0};
|
||||
uint8_t response[ISO15693_MAX_RESPONSE_LENGTH] = {0};
|
||||
DecodeTagInit(&dtag, response, sizeof(response));
|
||||
|
@ -1228,7 +1228,7 @@ void SniffIso15693(uint8_t jam_search_len, uint8_t *jam_search_string) {
|
|||
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER | FPGA_HF_READER_MODE_SNIFF_AMPLITUDE);
|
||||
LED_D_OFF();
|
||||
|
||||
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER);
|
||||
StartCountSspClk();
|
||||
|
@ -1247,12 +1247,12 @@ void SniffIso15693(uint8_t jam_search_len, uint8_t *jam_search_string) {
|
|||
|
||||
// Count of samples received so far, so that we can include timing
|
||||
int samples = 0;
|
||||
|
||||
|
||||
uint16_t *upTo = dma->buf;
|
||||
|
||||
for (;;) {
|
||||
|
||||
volatile int behind_by = ((uint16_t*)AT91C_BASE_PDC_SSC->PDC_RPR - upTo) & (DMA_BUFFER_SIZE - 1);
|
||||
volatile int behind_by = ((uint16_t *)AT91C_BASE_PDC_SSC->PDC_RPR - upTo) & (DMA_BUFFER_SIZE - 1);
|
||||
if (behind_by < 1) continue;
|
||||
|
||||
samples++;
|
||||
|
@ -1264,10 +1264,10 @@ void SniffIso15693(uint8_t jam_search_len, uint8_t *jam_search_string) {
|
|||
volatile uint16_t sniffdata = *upTo++;
|
||||
|
||||
// we have read all of the DMA buffer content
|
||||
if (upTo >= dma->buf + DMA_BUFFER_SIZE) {
|
||||
if (upTo >= dma->buf + DMA_BUFFER_SIZE) {
|
||||
|
||||
// start reading the circular buffer from the beginning
|
||||
upTo = dma->buf;
|
||||
upTo = dma->buf;
|
||||
|
||||
// DMA Counter Register had reached 0, already rotated.
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_ENDRX)) {
|
||||
|
@ -1282,7 +1282,7 @@ void SniffIso15693(uint8_t jam_search_len, uint8_t *jam_search_string) {
|
|||
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dma->buf;
|
||||
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
|
||||
WDT_HIT();
|
||||
if (BUTTON_PRESS()) {
|
||||
DbpString("Sniff stopped");
|
||||
|
@ -1299,9 +1299,9 @@ void SniffIso15693(uint8_t jam_search_len, uint8_t *jam_search_string) {
|
|||
uint32_t eof_time = dma_start_time + (samples * 16) + 8 - DELAY_READER_TO_ARM_SNIFF; // end of EOF
|
||||
if (dreader.byteCount > 0) {
|
||||
uint32_t sof_time = eof_time
|
||||
- dreader.byteCount * (dreader.Coding == CODING_1_OUT_OF_4 ? 128 * 16 : 2048 * 16) // time for byte transfers
|
||||
- 32 * 16 // time for SOF transfer
|
||||
- 16 * 16; // time for EOF transfer
|
||||
- dreader.byteCount * (dreader.Coding == CODING_1_OUT_OF_4 ? 128 * 16 : 2048 * 16) // time for byte transfers
|
||||
- 32 * 16 // time for SOF transfer
|
||||
- 16 * 16; // time for EOF transfer
|
||||
LogTrace_ISO15693(dreader.output, dreader.byteCount, (sof_time * 4), (eof_time * 4), NULL, true);
|
||||
}
|
||||
// And ready to receive another command.
|
||||
|
@ -1315,9 +1315,9 @@ void SniffIso15693(uint8_t jam_search_len, uint8_t *jam_search_string) {
|
|||
uint32_t eof_time = dma_start_time + (samples * 16) + 16 - DELAY_READER_TO_ARM_SNIFF; // end of EOF
|
||||
if (dreader.byteCount > 0) {
|
||||
uint32_t sof_time = eof_time
|
||||
- dreader.byteCount * (dreader.Coding == CODING_1_OUT_OF_4 ? 128 * 16 : 2048 * 16) // time for byte transfers
|
||||
- 32 * 16 // time for SOF transfer
|
||||
- 16 * 16; // time for EOF transfer
|
||||
- dreader.byteCount * (dreader.Coding == CODING_1_OUT_OF_4 ? 128 * 16 : 2048 * 16) // time for byte transfers
|
||||
- 32 * 16 // time for SOF transfer
|
||||
- 16 * 16; // time for EOF transfer
|
||||
LogTrace_ISO15693(dreader.output, dreader.byteCount, (sof_time * 4), (eof_time * 4), NULL, true);
|
||||
}
|
||||
// And ready to receive another command
|
||||
|
@ -1370,14 +1370,14 @@ void SniffIso15693(uint8_t jam_search_len, uint8_t *jam_search_string) {
|
|||
Dbprintf(" DecodeReader byteCnt...%d", dreader.byteCount);
|
||||
Dbprintf(" DecodeReader posCount..%d", dreader.posCount);
|
||||
Dbprintf(" Trace length..........." _YELLOW_("%d"), BigBuf_get_traceLen());
|
||||
DbpString("");
|
||||
DbpString("");
|
||||
|
||||
}
|
||||
|
||||
// Initialize Proxmark3 as ISO15693 reader
|
||||
void Iso15693InitReader(void) {
|
||||
|
||||
LEDsoff();
|
||||
LEDsoff();
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
|
||||
// Start from off (no field generated)
|
||||
|
@ -1387,7 +1387,7 @@ void Iso15693InitReader(void) {
|
|||
// switch field on
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER);
|
||||
LED_D_ON();
|
||||
|
||||
|
||||
// initialize SSC and select proper AD input
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER);
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
|
@ -1427,7 +1427,7 @@ static void BuildIdentifyRequest(uint8_t *cmd) {
|
|||
// If you do not need the answer use NULL for *recv[]
|
||||
// return: length of received data
|
||||
// logging enabled
|
||||
int SendDataTag(uint8_t *send, int sendlen, bool init, bool speed_fast, uint8_t *recv,
|
||||
int SendDataTag(uint8_t *send, int sendlen, bool init, bool speed_fast, uint8_t *recv,
|
||||
uint16_t max_recv_len, uint32_t start_time, uint16_t timeout, uint32_t *eof_time) {
|
||||
|
||||
if (init) {
|
||||
|
@ -1599,7 +1599,7 @@ void ReaderIso15693(uint32_t parameter) {
|
|||
|
||||
// When SIM: initialize the Proxmark3 as ISO15693 tag
|
||||
void Iso15693InitTag(void) {
|
||||
|
||||
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
|
||||
// Start from off (no field generated)
|
||||
|
@ -1658,10 +1658,10 @@ void SimTagIso15693(uint8_t *uid) {
|
|||
tosend_t *ts = get_tosend();
|
||||
|
||||
enum { NO_FIELD, IDLE, ACTIVATED, SELECTED, HALTED } chip_state = NO_FIELD;
|
||||
|
||||
|
||||
bool button_pressed = false;
|
||||
int vHf = 0; // in mV
|
||||
|
||||
int vHf = 0; // in mV
|
||||
|
||||
bool exit_loop = false;
|
||||
while (exit_loop == false) {
|
||||
WDT_HIT();
|
||||
|
@ -1678,7 +1678,7 @@ void SimTagIso15693(uint8_t *uid) {
|
|||
chip_state = IDLE;
|
||||
LED_A_ON();
|
||||
} else {
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1699,7 +1699,7 @@ void SimTagIso15693(uint8_t *uid) {
|
|||
uint32_t response_time = reader_eof_time + DELAY_ISO15693_VCD_TO_VICC_SIM;
|
||||
TransmitTo15693Reader(ts->buf, ts->max, &response_time, 0, slow);
|
||||
LogTrace_ISO15693(resp_inv, CMD_INV_RESP, response_time * 32, (response_time * 32) + (ts->max * 32 * 64), NULL, false);
|
||||
|
||||
|
||||
chip_state = SELECTED;
|
||||
}
|
||||
}
|
||||
|
@ -1715,7 +1715,7 @@ void SimTagIso15693(uint8_t *uid) {
|
|||
void BruteforceIso15693Afi(uint32_t speed) {
|
||||
|
||||
uint8_t data[7] = {0};
|
||||
uint8_t recv[ISO15693_MAX_RESPONSE_LENGTH];
|
||||
uint8_t recv[ISO15693_MAX_RESPONSE_LENGTH];
|
||||
Iso15693InitReader();
|
||||
|
||||
// first without AFI
|
||||
|
@ -1726,7 +1726,7 @@ void BruteforceIso15693Afi(uint32_t speed) {
|
|||
data[2] = 0; // AFI
|
||||
AddCrc15(data, 3);
|
||||
|
||||
int datalen = 5;
|
||||
int datalen = 5;
|
||||
uint32_t eof_time = 0;
|
||||
uint32_t start_time = GetCountSspClk();
|
||||
int recvlen = SendDataTag(data, datalen, true, speed, recv, sizeof(recv), 0, ISO15693_READER_TIMEOUT, &eof_time);
|
||||
|
@ -1754,7 +1754,7 @@ void BruteforceIso15693Afi(uint32_t speed) {
|
|||
|
||||
recvlen = SendDataTag(data, datalen, false, speed, recv, sizeof(recv), start_time, ISO15693_READER_TIMEOUT, &eof_time);
|
||||
start_time = eof_time + DELAY_ISO15693_VICC_TO_VCD_READER;
|
||||
|
||||
|
||||
WDT_HIT();
|
||||
|
||||
if (recvlen >= 12) {
|
||||
|
@ -1790,7 +1790,7 @@ void DirectTag15693Command(uint32_t datalen, uint32_t speed, uint32_t recv, uint
|
|||
uint32_t eof_time;
|
||||
uint16_t timeout;
|
||||
bool request_answer = false;
|
||||
|
||||
|
||||
switch (data[1]) {
|
||||
case ISO15_CMD_WRITE:
|
||||
case ISO15_CMD_LOCK:
|
||||
|
@ -1804,7 +1804,7 @@ void DirectTag15693Command(uint32_t datalen, uint32_t speed, uint32_t recv, uint
|
|||
break;
|
||||
default:
|
||||
timeout = ISO15693_READER_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
||||
Dbprintf("SEND:");
|
||||
|
@ -1814,10 +1814,10 @@ void DirectTag15693Command(uint32_t datalen, uint32_t speed, uint32_t recv, uint
|
|||
recvlen = SendDataTag(data, datalen, true, speed, (recv ? recvbuf : NULL), sizeof(recvbuf), 0, timeout, &eof_time);
|
||||
|
||||
// send a single EOF to get the tag response
|
||||
if (request_answer) {
|
||||
if (request_answer) {
|
||||
recvlen = SendDataTagEOF((recv ? recvbuf : NULL), sizeof(recvbuf), 0, ISO15693_READER_TIMEOUT, &eof_time);
|
||||
}
|
||||
|
||||
|
||||
// for the time being, switch field off to protect rdv4.0
|
||||
// note: this prevents using hf 15 cmd with s option - which isn't implemented yet anyway
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
|
@ -1882,9 +1882,9 @@ void SetTag15693Uid(uint8_t *uid) {
|
|||
AddCrc15(cmd[3], 7);
|
||||
|
||||
uint32_t start_time = 0;
|
||||
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
||||
|
||||
recvlen = SendDataTag(cmd[i], sizeof(cmd[i]), i == 0 ? true : false, true, recvbuf, sizeof(recvbuf), start_time, ISO15693_READER_TIMEOUT_WRITE, &eof_time);
|
||||
start_time = eof_time + DELAY_ISO15693_VICC_TO_VCD_READER;
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
#include "common.h"
|
||||
#include "pm3_cmd.h" // struct
|
||||
|
||||
|
||||
|
||||
// Delays in SSP_CLK ticks.
|
||||
// SSP_CLK runs at 13,56MHz / 32 = 423.75kHz when simulating a tag
|
||||
|
@ -27,11 +27,11 @@ void Iso15693InitReader(void);
|
|||
void Iso15693InitTag(void);
|
||||
void CodeIso15693AsReader(uint8_t *cmd, int n);
|
||||
void CodeIso15693AsTag(uint8_t *cmd, size_t len);
|
||||
|
||||
|
||||
void TransmitTo15693Reader(const uint8_t *cmd, size_t len, uint32_t *start_time, uint32_t slot_time, bool slow);
|
||||
int GetIso15693CommandFromReader(uint8_t *received, size_t max_len, uint32_t *eof_time);
|
||||
void TransmitTo15693Tag(const uint8_t *cmd, int len, uint32_t *start_time);
|
||||
int GetIso15693AnswerFromTag(uint8_t* response, uint16_t max_len, uint16_t timeout, uint32_t *eof_time);
|
||||
int GetIso15693AnswerFromTag(uint8_t *response, uint16_t max_len, uint16_t timeout, uint32_t *eof_time);
|
||||
|
||||
//void RecordRawAdcSamplesIso15693(void);
|
||||
void AcquireRawAdcSamplesIso15693(void);
|
||||
|
@ -43,9 +43,9 @@ void Iso15693InitReader(void);
|
|||
|
||||
void SniffIso15693(uint8_t jam_search_len, uint8_t *jam_search_string);
|
||||
|
||||
int SendDataTag(uint8_t *send, int sendlen, bool init, bool speed_fast, uint8_t *recv,
|
||||
int SendDataTag(uint8_t *send, int sendlen, bool init, bool speed_fast, uint8_t *recv,
|
||||
uint16_t max_recv_len, uint32_t start_time, uint16_t timeout, uint32_t *eof_time);
|
||||
|
||||
|
||||
int SendDataTagEOF(uint8_t *recv, uint16_t max_recv_len, uint32_t start_time, uint16_t timeout, uint32_t *eof_time);
|
||||
|
||||
void SetTag15693Uid(uint8_t *uid);
|
||||
|
|
|
@ -148,7 +148,7 @@ bool lf_get_reader_modulation(void) {
|
|||
}
|
||||
|
||||
void lf_wait_periods(size_t periods) {
|
||||
// wait detect gap
|
||||
// wait detect gap
|
||||
lf_count_edge_periods_ex(periods, true, false);
|
||||
}
|
||||
|
||||
|
@ -238,40 +238,40 @@ void lf_finalize(void) {
|
|||
}
|
||||
|
||||
size_t lf_detect_field_drop(size_t max) {
|
||||
/*
|
||||
size_t periods = 0;
|
||||
// int16_t checked = 0;
|
||||
/*
|
||||
size_t periods = 0;
|
||||
// int16_t checked = 0;
|
||||
|
||||
while (BUTTON_PRESS() == false) {
|
||||
while (BUTTON_PRESS() == false) {
|
||||
|
||||
// // only every 1000th times, in order to save time when collecting samples.
|
||||
// if (checked == 4000) {
|
||||
// if (data_available()) {
|
||||
// checked = -1;
|
||||
// break;
|
||||
// } else {
|
||||
// checked = 0;
|
||||
// // only every 1000th times, in order to save time when collecting samples.
|
||||
// if (checked == 4000) {
|
||||
// if (data_available()) {
|
||||
// checked = -1;
|
||||
// break;
|
||||
// } else {
|
||||
// checked = 0;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// ++checked;
|
||||
// ++checked;
|
||||
|
||||
WDT_HIT();
|
||||
WDT_HIT();
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
periods++;
|
||||
volatile uint8_t adc_val = AT91C_BASE_SSC->SSC_RHR;
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
periods++;
|
||||
volatile uint8_t adc_val = AT91C_BASE_SSC->SSC_RHR;
|
||||
|
||||
if (g_logging) logSampleSimple(adc_val);
|
||||
if (g_logging) logSampleSimple(adc_val);
|
||||
|
||||
if (adc_val == 0) {
|
||||
rising_edge = false;
|
||||
return periods;
|
||||
if (adc_val == 0) {
|
||||
rising_edge = false;
|
||||
return periods;
|
||||
}
|
||||
|
||||
if (periods == max) return 0;
|
||||
}
|
||||
|
||||
if (periods == max) return 0;
|
||||
}
|
||||
}
|
||||
*/
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1245,7 +1245,7 @@ int lf_hid_watch(int findone, uint32_t *high, uint32_t *low) {
|
|||
while (BUTTON_PRESS() == false) {
|
||||
|
||||
WDT_HIT();
|
||||
|
||||
|
||||
// cancel w usb command.
|
||||
if (interval == 4000) {
|
||||
if (data_available()) {
|
||||
|
@ -1262,7 +1262,7 @@ int lf_hid_watch(int findone, uint32_t *high, uint32_t *low) {
|
|||
// FSK demodulator
|
||||
// 50 * 128 * 2 - big enough to catch 2 sequences of largest format
|
||||
size = MIN(12800, BigBuf_max_traceLen());
|
||||
|
||||
|
||||
int idx = HIDdemodFSK(dest, &size, &hi2, &hi, &lo, &dummyIdx);
|
||||
if (idx < 0) continue;
|
||||
|
||||
|
@ -1354,7 +1354,7 @@ int lf_awid_watch(int findone, uint32_t *high, uint32_t *low) {
|
|||
while (BUTTON_PRESS() == false) {
|
||||
|
||||
WDT_HIT();
|
||||
|
||||
|
||||
// cancel w usb command.
|
||||
if (interval == 4000) {
|
||||
if (data_available()) {
|
||||
|
@ -1535,7 +1535,7 @@ int lf_io_watch(int findone, uint32_t *high, uint32_t *low) {
|
|||
while (BUTTON_PRESS() == false) {
|
||||
|
||||
WDT_HIT();
|
||||
|
||||
|
||||
// cancel w usb command.
|
||||
if (interval == 4000) {
|
||||
if (data_available()) {
|
||||
|
@ -2601,12 +2601,12 @@ void Cotag(uint32_t arg0) {
|
|||
BigBuf_Clear_ext(false);
|
||||
|
||||
//send COTAG start pulse
|
||||
/*
|
||||
ON(740) OFF(2035)
|
||||
ON(3330) OFF(2035)
|
||||
ON(740) OFF(2035)
|
||||
ON(1000)
|
||||
*/
|
||||
/*
|
||||
ON(740) OFF(2035)
|
||||
ON(3330) OFF(2035)
|
||||
ON(740) OFF(2035)
|
||||
ON(1000)
|
||||
*/
|
||||
|
||||
ON(800) OFF(2200)
|
||||
ON(3600) OFF(2200)
|
||||
|
|
|
@ -171,7 +171,7 @@ void logSample(uint8_t sample, uint8_t decimation, uint8_t bits_per_sample, bool
|
|||
// keep track of total gather samples regardless how many was discarded.
|
||||
if (samples.counter-- == 0) return;
|
||||
|
||||
if (bits_per_sample == 0) bits_per_sample = 1;
|
||||
if (bits_per_sample == 0) bits_per_sample = 1;
|
||||
if (bits_per_sample > 8) bits_per_sample = 8;
|
||||
if (decimation == 0) decimation = 1;
|
||||
|
||||
|
@ -323,7 +323,7 @@ uint32_t DoAcquisition(uint8_t decimation, uint8_t bits_per_sample, bool avg, in
|
|||
if (samples.total_saved >= sample_size) break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (checked == -1 && verbose) {
|
||||
Dbprintf("lf sampling aborted");
|
||||
}
|
||||
|
@ -414,14 +414,14 @@ void doT55x7Acquisition(size_t sample_size) {
|
|||
bool lowFound = false;
|
||||
|
||||
uint16_t checker = 0;
|
||||
|
||||
|
||||
if (DBGLEVEL >= DBG_DEBUG) {
|
||||
Dbprintf("doT55x7Acquisition - after init");
|
||||
print_stack_usage();
|
||||
}
|
||||
|
||||
while (skipCnt < 1000 && (i < bufsize)) {
|
||||
|
||||
|
||||
if (BUTTON_PRESS())
|
||||
break;
|
||||
|
||||
|
@ -493,17 +493,17 @@ void doCotagAcquisition() {
|
|||
dest[0] = 0;
|
||||
uint8_t firsthigh = 0, firstlow = 0;
|
||||
uint16_t i = 0, noise_counter = 0;
|
||||
|
||||
|
||||
if (DBGLEVEL >= DBG_DEBUG) {
|
||||
Dbprintf("doCotagAcquisition - after init");
|
||||
print_stack_usage();
|
||||
}
|
||||
|
||||
while ((i < bufsize) && (noise_counter < (COTAG_T1 << 1))) {
|
||||
|
||||
|
||||
if (BUTTON_PRESS())
|
||||
break;
|
||||
|
||||
|
||||
WDT_HIT();
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
||||
|
@ -557,15 +557,15 @@ uint32_t doCotagAcquisitionManchester(void) {
|
|||
uint8_t curr = 0, prev = 0;
|
||||
uint16_t sample_counter = 0, period = 0;
|
||||
uint16_t noise_counter = 0;
|
||||
|
||||
|
||||
if (DBGLEVEL >= DBG_DEBUG) {
|
||||
Dbprintf("doCotagAcquisitionManchester - after init");
|
||||
print_stack_usage();
|
||||
}
|
||||
|
||||
|
||||
while ((sample_counter < bufsize) && (noise_counter < (COTAG_T1 << 1))) {
|
||||
|
||||
if (BUTTON_PRESS())
|
||||
|
||||
if (BUTTON_PRESS())
|
||||
break;
|
||||
|
||||
WDT_HIT();
|
||||
|
|
|
@ -483,9 +483,9 @@ int rdv40_spiffs_read_as_symlink(char *filename, uint8_t *dst, uint32_t size, RD
|
|||
|
||||
if (DBGLEVEL > 1) 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);
|
||||
)
|
||||
}
|
||||
|
||||
// BEWARE ! This function is DESTRUCTIVE as it will UPDATE an existing symlink
|
||||
// Since it creates a .lnk extension file it may be minor to mistake the order of arguments
|
||||
|
@ -516,18 +516,18 @@ int rdv40_spiffs_make_symlink(char *linkdest, char *filename, RDV40SpiFFSSafetyL
|
|||
int rdv40_spiffs_read_as_filetype(char *filename, uint8_t *dst, uint32_t size, RDV40SpiFFSSafetyLevel level) {
|
||||
RDV40_SPIFFS_SAFE_FUNCTION(
|
||||
RDV40SpiFFSFileType filetype = filetype_in_spiffs((char *)filename);
|
||||
switch (filetype) {
|
||||
case RDV40_SPIFFS_FILETYPE_REAL:
|
||||
rdv40_spiffs_read((char *)filename, (uint8_t *)dst, size, level);
|
||||
break;
|
||||
case RDV40_SPIFFS_FILETYPE_SYMLINK:
|
||||
rdv40_spiffs_read_as_symlink((char *)filename, (uint8_t *)dst, size, level);
|
||||
break;
|
||||
case RDV40_SPIFFS_FILETYPE_BOTH:
|
||||
case RDV40_SPIFFS_FILETYPE_UNKNOWN:
|
||||
default:
|
||||
switch (filetype) {
|
||||
case RDV40_SPIFFS_FILETYPE_REAL:
|
||||
rdv40_spiffs_read((char *)filename, (uint8_t *)dst, size, level);
|
||||
break;
|
||||
case RDV40_SPIFFS_FILETYPE_SYMLINK:
|
||||
rdv40_spiffs_read_as_symlink((char *)filename, (uint8_t *)dst, size, level);
|
||||
break;
|
||||
case RDV40_SPIFFS_FILETYPE_BOTH:
|
||||
case RDV40_SPIFFS_FILETYPE_UNKNOWN:
|
||||
default:
|
||||
;
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -617,7 +617,7 @@ void rdv40_spiffs_safe_wipe(void) {
|
|||
while ((pe = SPIFFS_readdir(&d, pe))) {
|
||||
|
||||
if (rdv40_spiffs_is_symlink((const char *)pe->name)) {
|
||||
|
||||
|
||||
char linkdest[SPIFFS_OBJ_NAME_LEN];
|
||||
read_from_spiffs((char *)pe->name, (uint8_t *)linkdest, SPIFFS_OBJ_NAME_LEN);
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ static void CodeThinfilmAsTag(const uint8_t *cmd, uint16_t len) {
|
|||
tosend_reset();
|
||||
|
||||
tosend_t *ts = get_tosend();
|
||||
|
||||
|
||||
for (uint16_t i = 0; i < len; i++) {
|
||||
uint8_t b = cmd[i];
|
||||
for (uint8_t j = 0; j < 8; j++) {
|
||||
|
|
|
@ -157,20 +157,20 @@ void StartCountSspClk(void) {
|
|||
// synchronize the counter with the ssp_frame signal.
|
||||
// Note: FPGA must be in a FPGA mode with SSC transfer, otherwise SSC_FRAME and SSC_CLK signals would not be present
|
||||
//
|
||||
while(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_FRAME); // wait for ssp_frame to be low
|
||||
while(!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_FRAME)); // wait for ssp_frame to go high (start of frame)
|
||||
while(!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)); // wait for ssp_clk to go high; 1st ssp_clk after start of frame
|
||||
while(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK); // wait for ssp_clk to go low;
|
||||
while(!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)); // wait for ssp_clk to go high; 2nd ssp_clk after start of frame
|
||||
while (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_FRAME); // wait for ssp_frame to be low
|
||||
while (!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_FRAME)); // wait for ssp_frame to go high (start of frame)
|
||||
while (!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)); // wait for ssp_clk to go high; 1st ssp_clk after start of frame
|
||||
while (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK); // wait for ssp_clk to go low;
|
||||
while (!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)); // wait for ssp_clk to go high; 2nd ssp_clk after start of frame
|
||||
if ((AT91C_BASE_SSC->SSC_RFMR & SSC_FRAME_MODE_BITS_IN_WORD(32)) == SSC_FRAME_MODE_BITS_IN_WORD(16)) { // 16bit frame
|
||||
while(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK); // wait for ssp_clk to go low;
|
||||
while(!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)); // wait for ssp_clk to go high; 3rd ssp_clk after start of frame
|
||||
while(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK); // wait for ssp_clk to go low;
|
||||
while(!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)); // wait for ssp_clk to go high; 4th ssp_clk after start of frame
|
||||
while(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK); // wait for ssp_clk to go low;
|
||||
while(!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)); // wait for ssp_clk to go high; 5th ssp_clk after start of frame
|
||||
while(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK); // wait for ssp_clk to go low;
|
||||
while(!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)); // wait for ssp_clk to go high; 6th ssp_clk after start of frame
|
||||
while (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK); // wait for ssp_clk to go low;
|
||||
while (!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)); // wait for ssp_clk to go high; 3rd ssp_clk after start of frame
|
||||
while (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK); // wait for ssp_clk to go low;
|
||||
while (!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)); // wait for ssp_clk to go high; 4th ssp_clk after start of frame
|
||||
while (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK); // wait for ssp_clk to go low;
|
||||
while (!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)); // wait for ssp_clk to go high; 5th ssp_clk after start of frame
|
||||
while (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK); // wait for ssp_clk to go low;
|
||||
while (!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)); // wait for ssp_clk to go high; 6th ssp_clk after start of frame
|
||||
}
|
||||
|
||||
// note: up to now two ssp_clk rising edges have passed since the rising edge of ssp_frame
|
||||
|
|
|
@ -86,7 +86,7 @@ jint Console(JNIEnv *env, jobject instance, jstring cmd_) {
|
|||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
|
||||
char *cmd = (char *) ((*env)->GetStringUTFChars(env, cmd_, 0));
|
||||
char *cmd = (char *)((*env)->GetStringUTFChars(env, cmd_, 0));
|
||||
int ret = CommandReceived(cmd);
|
||||
if (ret == 99) {
|
||||
// exit / quit
|
||||
|
@ -102,7 +102,7 @@ jint Console(JNIEnv *env, jobject instance, jstring cmd_) {
|
|||
* Is client running!
|
||||
* */
|
||||
jboolean IsClientRunning(JNIEnv *env, jobject instance) {
|
||||
return (jboolean) ((jboolean) conn.run);
|
||||
return (jboolean)((jboolean) conn.run);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -114,7 +114,7 @@ jboolean TestPm3(JNIEnv *env, jobject instance) {
|
|||
return false;
|
||||
}
|
||||
bool ret = (TestProxmark() == PM3_SUCCESS);
|
||||
return (jboolean) (ret);
|
||||
return (jboolean)(ret);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -141,18 +141,18 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
|
|||
}
|
||||
jclass clz_test = (*jniEnv)->FindClass(jniEnv, "cn/rrg/devices/Proxmark3RRGRdv4");
|
||||
JNINativeMethod methods[] = {
|
||||
{"startExecute", "(Ljava/lang/String;)I", (void *) Console},
|
||||
{"stopExecute", "()V", (void *) ClosePm3},
|
||||
{"isExecuting", "()Z", (void *) IsClientRunning}
|
||||
{"startExecute", "(Ljava/lang/String;)I", (void *) Console},
|
||||
{"stopExecute", "()V", (void *) ClosePm3},
|
||||
{"isExecuting", "()Z", (void *) IsClientRunning}
|
||||
};
|
||||
|
||||
JNINativeMethod methods1[] = {
|
||||
{"testPm3", "()Z", (void *) TestPm3},
|
||||
{"closePm3", "()V", ClosePm3}
|
||||
{"testPm3", "()Z", (void *) TestPm3},
|
||||
{"closePm3", "()V", ClosePm3}
|
||||
};
|
||||
|
||||
if ((*jniEnv)->RegisterNatives(jniEnv, clazz, methods, sizeof(methods) / sizeof(methods[0])) !=
|
||||
JNI_OK) {
|
||||
JNI_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -164,4 +164,4 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
|
|||
(*jniEnv)->DeleteLocalRef(jniEnv, clazz);
|
||||
(*jniEnv)->DeleteLocalRef(jniEnv, clz_test);
|
||||
return JNI_VERSION_1_4;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2317,7 +2317,7 @@ static int CmdDataNDEF(const char *Cmd) {
|
|||
"Samples:\n"
|
||||
_YELLOW_("\tdata ndef -d 9101085402656e48656c6c6f5101085402656e576f726c64\n")
|
||||
_YELLOW_("\tdata ndef -d 0103d020240203e02c040300fe\n")
|
||||
);
|
||||
);
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
|
|
|
@ -339,7 +339,7 @@ static int CmdFlashMemSpiFFSDump(const char *Cmd) {
|
|||
saveFile(filename, ".bin", dump, len);
|
||||
if (eml) {
|
||||
uint8_t eml_len = 16;
|
||||
|
||||
|
||||
if (strstr(filename, "class") != NULL)
|
||||
eml_len = 8;
|
||||
else if (strstr(filename, "mfu") != NULL)
|
||||
|
@ -421,12 +421,12 @@ out:
|
|||
}
|
||||
|
||||
static int CmdFlashMemSpiFFSWipe(const char *Cmd) {
|
||||
|
||||
|
||||
char ctmp = tolower(param_getchar(Cmd, 0));
|
||||
if (ctmp == 'h') {
|
||||
return usage_flashmemspiffs_wipe();
|
||||
}
|
||||
|
||||
|
||||
PrintAndLogEx(INFO, "Wiping all files from SPIFFS FileSystem");
|
||||
PacketResponseNG resp;
|
||||
clearCommandBuffer();
|
||||
|
|
|
@ -285,16 +285,16 @@ int CmdHFSniff(const char *Cmd) {
|
|||
uint16_t len;
|
||||
} PACKED;
|
||||
struct r *retval = (struct r *)resp.data.asBytes;
|
||||
|
||||
|
||||
PrintAndLogEx(INFO, "HF sniff (%u samples)", retval->len);
|
||||
|
||||
PrintAndLogEx(HINT, "Use `" _YELLOW_("data hpf") "` to remove offset");
|
||||
PrintAndLogEx(HINT, "Use `" _YELLOW_("data plot") "` to view");
|
||||
PrintAndLogEx(HINT, "Use `" _YELLOW_("data save") "` to save");
|
||||
|
||||
// download bigbuf_malloc:d.
|
||||
// download bigbuf_malloc:d.
|
||||
// it reserve memory from the higher end.
|
||||
// At the moment, sniff takes all free memory in bigbuff. If this changes,
|
||||
// At the moment, sniff takes all free memory in bigbuff. If this changes,
|
||||
// we can't start from beginning idx 0 but from that hi-to-start-of-allocated.
|
||||
uint32_t start = pm3_capabilities.bigbuf_size - retval->len;
|
||||
int res = getSamplesEx(start, start, false);
|
||||
|
|
|
@ -384,8 +384,8 @@ static inline uint32_t countones(uint64_t a) {
|
|||
#endif
|
||||
|
||||
}
|
||||
|
||||
const char * card_types[] = {
|
||||
|
||||
const char *card_types[] = {
|
||||
"PicoPass 16K / 16", // 000
|
||||
"PicoPass 32K with current book 16K / 16", // 001
|
||||
"Unknown Card Type!", // 010
|
||||
|
@ -435,7 +435,7 @@ static void fuse_config(const picopass_hdr *hdr) {
|
|||
else
|
||||
PrintAndLogEx(SUCCESS, "Coding: " _YELLOW_("ISO 14443-B only"));
|
||||
}
|
||||
|
||||
|
||||
uint8_t pagemap = get_pagemap(hdr);
|
||||
switch (pagemap) {
|
||||
case 0x0:
|
||||
|
@ -458,25 +458,25 @@ static void fuse_config(const picopass_hdr *hdr) {
|
|||
PrintAndLogEx(INFO, " RA: Read access not enabled");
|
||||
|
||||
PrintAndLogEx(INFO,
|
||||
"App limit " _YELLOW_("0x%02X") ", OTP " _YELLOW_("0x%02X%02X") ", Block write lock " _YELLOW_("0x%02X")
|
||||
, hdr->conf.app_limit
|
||||
, hdr->conf.otp[1]
|
||||
, hdr->conf.otp[0]
|
||||
, hdr->conf.block_writelock
|
||||
);
|
||||
"App limit " _YELLOW_("0x%02X") ", OTP " _YELLOW_("0x%02X%02X") ", Block write lock " _YELLOW_("0x%02X")
|
||||
, hdr->conf.app_limit
|
||||
, hdr->conf.otp[1]
|
||||
, hdr->conf.otp[0]
|
||||
, hdr->conf.block_writelock
|
||||
);
|
||||
PrintAndLogEx(INFO,
|
||||
" Chip " _YELLOW_("0x%02X") ", Mem " _YELLOW_("0x%02X") ", EAS " _YELLOW_("0x%02X") ", Fuses " _YELLOW_("0x%02X")
|
||||
, hdr->conf.chip_config
|
||||
, hdr->conf.mem_config
|
||||
, hdr->conf.eas
|
||||
, hdr->conf.fuses
|
||||
);
|
||||
" Chip " _YELLOW_("0x%02X") ", Mem " _YELLOW_("0x%02X") ", EAS " _YELLOW_("0x%02X") ", Fuses " _YELLOW_("0x%02X")
|
||||
, hdr->conf.chip_config
|
||||
, hdr->conf.mem_config
|
||||
, hdr->conf.eas
|
||||
, hdr->conf.fuses
|
||||
);
|
||||
}
|
||||
|
||||
static void getMemConfig(uint8_t mem_cfg, uint8_t chip_cfg, uint8_t *app_areas, uint8_t *kb) {
|
||||
// How to determine chip type
|
||||
// How to determine chip type
|
||||
|
||||
// mem-bit 7 = 16K
|
||||
// mem-bit 7 = 16K
|
||||
// mem-bit 5 = Book
|
||||
// mem-bit 4 = 2K
|
||||
// chip-bit 4 = Multi App
|
||||
|
@ -532,7 +532,7 @@ static void mem_app_config(const picopass_hdr *hdr) {
|
|||
uint8_t pagemap = get_pagemap(hdr);
|
||||
|
||||
PrintAndLogEx(INFO, "------ " _CYAN_("Memory") " ------");
|
||||
|
||||
|
||||
if (pagemap == PICOPASS_NON_SECURE_PAGEMODE) {
|
||||
PrintAndLogEx(INFO, " %u KBits (%u bytes)", kb, app2_limit * 8);
|
||||
PrintAndLogEx(INFO, " Tag has not App Areas");
|
||||
|
@ -540,7 +540,7 @@ static void mem_app_config(const picopass_hdr *hdr) {
|
|||
}
|
||||
|
||||
PrintAndLogEx(INFO, " %u KBits/%u App Areas (%u bytes)", kb, app_areas, (app2_limit + 1) * 8);
|
||||
PrintAndLogEx(INFO, " AA1 blocks %u { 0x06 - 0x%02X (06 - %02d) }", app1_limit , app1_limit + 5, app1_limit + 5);
|
||||
PrintAndLogEx(INFO, " AA1 blocks %u { 0x06 - 0x%02X (06 - %02d) }", app1_limit, app1_limit + 5, app1_limit + 5);
|
||||
PrintAndLogEx(INFO, " AA2 blocks %u { 0x%02X - 0x%02X (%02d - %02d) }", app2_limit - app1_limit, app1_limit + 5 + 1, app2_limit, app1_limit + 5 + 1, app2_limit);
|
||||
|
||||
PrintAndLogEx(INFO, "------ " _CYAN_("KeyAccess") " ------");
|
||||
|
@ -592,18 +592,18 @@ static int CmdHFiClassSniff(const char *Cmd) {
|
|||
"Usage:\n"
|
||||
_YELLOW_("\thf iclass sniff") "\n"
|
||||
_YELLOW_("\thf iclass sniff -j") " -> jam e-purse updates\n"
|
||||
);
|
||||
|
||||
void* argtable[] = {
|
||||
);
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_lit0("j", "jam", "Jam (prevent) e-purse updates"),
|
||||
arg_param_end
|
||||
};
|
||||
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
bool jam_epurse_update = arg_get_lit(ctx, 1);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
|
||||
const uint8_t update_epurse_sequence[2] = {0x87, 0x02};
|
||||
|
||||
struct {
|
||||
|
@ -611,17 +611,17 @@ static int CmdHFiClassSniff(const char *Cmd) {
|
|||
uint8_t jam_search_string[2];
|
||||
} PACKED payload;
|
||||
|
||||
if (jam_epurse_update) {
|
||||
if (jam_epurse_update) {
|
||||
payload.jam_search_len = sizeof(update_epurse_sequence);
|
||||
memcpy(payload.jam_search_string, update_epurse_sequence, sizeof(payload.jam_search_string));
|
||||
}
|
||||
|
||||
|
||||
PacketResponseNG resp;
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_HF_ICLASS_SNIFF, (uint8_t *)&payload, sizeof(payload));
|
||||
|
||||
|
||||
WaitForResponse(CMD_HF_ICLASS_SNIFF, &resp);
|
||||
|
||||
|
||||
PrintAndLogEx(HINT, "Try `" _YELLOW_("hf iclass list") "` to look at the collected trace");
|
||||
PrintAndLogEx(HINT, "Try `" _YELLOW_("trace save h") "` to save tracelog for later analysing");
|
||||
return PM3_SUCCESS;
|
||||
|
@ -790,7 +790,7 @@ static int CmdHFiClassSim(const char *Cmd) {
|
|||
}
|
||||
saveFile("iclass_mac_attack_keyroll_B", ".bin", dump, datalen);
|
||||
free(dump);
|
||||
|
||||
|
||||
PrintAndLogEx(HINT, "Try `" _YELLOW_("hf iclass loclass h") "` to recover elite key");
|
||||
break;
|
||||
}
|
||||
|
@ -801,7 +801,7 @@ static int CmdHFiClassSim(const char *Cmd) {
|
|||
uint8_t numberOfCSNs = 0;
|
||||
clearCommandBuffer();
|
||||
SendCommandMIX(CMD_HF_ICLASS_SIMULATE, sim_type, numberOfCSNs, 1, CSN, 8);
|
||||
|
||||
|
||||
if (sim_type == ICLASS_SIM_MODE_FULL)
|
||||
PrintAndLogEx(HINT, "Try `" _YELLOW_("hf iclass esave h") "` to save the emulator memory to file");
|
||||
break;
|
||||
|
@ -819,7 +819,7 @@ int read_iclass_csn(bool loop, bool verbose) {
|
|||
uint32_t flags = (FLAG_ICLASS_READER_INIT | FLAG_ICLASS_READER_CLEARTRACE);
|
||||
int res = PM3_SUCCESS;
|
||||
|
||||
while (kbd_enter_pressed() == false) {
|
||||
while (kbd_enter_pressed() == false) {
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandMIX(CMD_HF_ICLASS_READER, flags, 0, 0, NULL, 0);
|
||||
|
@ -840,17 +840,17 @@ int read_iclass_csn(bool loop, bool verbose) {
|
|||
}
|
||||
|
||||
picopass_hdr *hdr = (picopass_hdr *)resp.data.asBytes;
|
||||
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(SUCCESS, " CSN: " _GREEN_("%s"), sprint_hex(hdr->csn, sizeof(hdr->csn)));
|
||||
PrintAndLogEx(SUCCESS, " Config: " _GREEN_("%s"), sprint_hex((uint8_t *)&hdr->conf, sizeof(hdr->conf)));
|
||||
|
||||
|
||||
if (loop == false)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DropField();
|
||||
DropField();
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -858,7 +858,7 @@ static int CmdHFiClassReader(const char *Cmd) {
|
|||
char cmdp = tolower(param_getchar(Cmd, 0));
|
||||
if (cmdp == 'h') return usage_hf_iclass_reader();
|
||||
bool loop_read = (cmdp == '1') ? false : true;
|
||||
|
||||
|
||||
return read_iclass_csn(loop_read, true);
|
||||
}
|
||||
|
||||
|
@ -919,7 +919,7 @@ static int CmdHFiClassReader_Replay(const char *Cmd) {
|
|||
|
||||
PacketResponseNG resp;
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_HF_ICLASS_REPLAY, (uint8_t *)&payload, sizeof(payload));
|
||||
SendCommandNG(CMD_HF_ICLASS_REPLAY, (uint8_t *)&payload, sizeof(payload));
|
||||
|
||||
while (true) {
|
||||
printf(".");
|
||||
|
@ -980,7 +980,7 @@ static int CmdHFiClassReader_Replay(const char *Cmd) {
|
|||
saveFile(filename, ".bin", tag_data, bytes_got);
|
||||
saveFileEML(filename, tag_data, bytes_got, 8);
|
||||
saveFileJSON(filename, jsfIclass, tag_data, bytes_got, NULL);
|
||||
|
||||
|
||||
PrintAndLogEx(HINT, "Try `" _YELLOW_("hf iclass decrypt") "` to decrypt dump file");
|
||||
PrintAndLogEx(HINT, "Try `" _YELLOW_("hf iclass view") "` to view dump file");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
|
@ -1157,9 +1157,9 @@ static int CmdHFiClassESave(const char *Cmd) {
|
|||
saveFileEML(filename, dump, bytes, 8);
|
||||
saveFileJSON(filename, jsfIclass, dump, bytes, NULL);
|
||||
free(dump);
|
||||
|
||||
|
||||
PrintAndLogEx(HINT, "Try `" _YELLOW_("hf iclass readtagfile ") "` to view dump file");
|
||||
return PM3_SUCCESS;
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static int CmdHFiClassDecrypt(const char *Cmd) {
|
||||
|
@ -1351,7 +1351,7 @@ static int CmdHFiClassDecrypt(const char *Cmd) {
|
|||
} else {
|
||||
PrintAndLogEx(INFO, "No credential found.");
|
||||
}
|
||||
|
||||
|
||||
// decode block 9
|
||||
if (memcmp(decrypted + (8 * 9), empty, 8) != 0) {
|
||||
|
||||
|
@ -1363,9 +1363,9 @@ static int CmdHFiClassDecrypt(const char *Cmd) {
|
|||
uint8_t pinsize = 0;
|
||||
if (use_sc) {
|
||||
pinsize = GetPinSize(decrypted + (8 * 6));
|
||||
|
||||
|
||||
if (pinsize > 0) {
|
||||
|
||||
|
||||
uint64_t pin = bytes_to_num(decrypted + (8 * 9), 5);
|
||||
char tmp[17] = {0};
|
||||
sprintf(tmp, "%."PRIu64, BCD2DEC(pin));
|
||||
|
@ -1502,17 +1502,17 @@ static bool select_only(uint8_t *CSN, uint8_t *CCNR, bool verbose) {
|
|||
}
|
||||
|
||||
static bool select_and_auth(uint8_t *KEY, uint8_t *MAC, uint8_t *div_key, bool use_credit_key, bool elite, bool rawkey, bool verbose) {
|
||||
|
||||
|
||||
iclass_auth_req_t payload = {
|
||||
.use_raw = rawkey,
|
||||
.use_elite = elite,
|
||||
.use_credit_key = use_credit_key
|
||||
};
|
||||
memcpy(payload.key, KEY, 8);
|
||||
|
||||
SendCommandNG(CMD_HF_ICLASS_AUTH, (uint8_t*)&payload, sizeof(payload));
|
||||
|
||||
SendCommandNG(CMD_HF_ICLASS_AUTH, (uint8_t *)&payload, sizeof(payload));
|
||||
PacketResponseNG resp;
|
||||
clearCommandBuffer();
|
||||
clearCommandBuffer();
|
||||
if (WaitForResponseTimeout(CMD_HF_ICLASS_AUTH, &resp, 2000) == 0) {
|
||||
if (verbose) PrintAndLogEx(WARNING, "Command execute timeout");
|
||||
return false;
|
||||
|
@ -1529,14 +1529,14 @@ static bool select_and_auth(uint8_t *KEY, uint8_t *MAC, uint8_t *div_key, bool u
|
|||
if (verbose) PrintAndLogEx(FAILED, "authentication error");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (div_key)
|
||||
memcpy(div_key, packet->div_key, sizeof(packet->div_key));
|
||||
|
||||
|
||||
if (MAC)
|
||||
memcpy(MAC, packet->mac, sizeof(packet->mac));
|
||||
|
||||
if (verbose)
|
||||
|
||||
if (verbose)
|
||||
PrintAndLogEx(SUCCESS, "authing with %s: %s", rawkey ? "raw key" : "diversified key", sprint_hex(div_key, 8));
|
||||
|
||||
return true;
|
||||
|
@ -1658,7 +1658,7 @@ static int CmdHFiClassDump(const char *Cmd) {
|
|||
uint8_t pagemap = get_pagemap(hdr);
|
||||
|
||||
if (readStatus & (FLAG_ICLASS_CSN | FLAG_ICLASS_CONF | FLAG_ICLASS_CC)) {
|
||||
|
||||
|
||||
memcpy(tag_data, hdr, 24);
|
||||
|
||||
uint8_t type = get_mem_config(hdr);
|
||||
|
@ -1667,22 +1667,22 @@ static int CmdHFiClassDump(const char *Cmd) {
|
|||
if (pagemap == PICOPASS_NON_SECURE_PAGEMODE) {
|
||||
|
||||
PrintAndLogEx(INFO, "Card in non-secure page mode detected");
|
||||
|
||||
|
||||
app_limit1 = card_app2_limit[type];
|
||||
app_limit2 = 0;
|
||||
} else {
|
||||
app_limit1 = hdr->conf.app_limit;
|
||||
app_limit2 = card_app2_limit[type];
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
PrintAndLogEx(FAILED, "failed to read block 0,1,2");
|
||||
DropField();
|
||||
return PM3_ESOFT;
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
if (pagemap == PICOPASS_NON_SECURE_PAGEMODE) {
|
||||
PrintAndLogEx(INFO, "Dumping all available memory, block 3 - %u (0x%02x)",app_limit1 , app_limit1);
|
||||
PrintAndLogEx(INFO, "Dumping all available memory, block 3 - %u (0x%02x)", app_limit1, app_limit1);
|
||||
if (auth) {
|
||||
PrintAndLogEx(INFO, "No keys needed, ignoring user supplied key");
|
||||
}
|
||||
|
@ -1703,7 +1703,7 @@ static int CmdHFiClassDump(const char *Cmd) {
|
|||
.end_block = app_limit1,
|
||||
};
|
||||
memcpy(payload.req.key, KEY, 8);
|
||||
|
||||
|
||||
// tags configured for NON SECURE PAGE, acts different
|
||||
if (pagemap == PICOPASS_NON_SECURE_PAGEMODE) {
|
||||
payload.start_block = 3;
|
||||
|
@ -1711,9 +1711,9 @@ static int CmdHFiClassDump(const char *Cmd) {
|
|||
} else {
|
||||
payload.start_block = 6;
|
||||
}
|
||||
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_HF_ICLASS_DUMP, (uint8_t*)&payload, sizeof(payload));
|
||||
SendCommandNG(CMD_HF_ICLASS_DUMP, (uint8_t *)&payload, sizeof(payload));
|
||||
|
||||
while (true) {
|
||||
printf(".");
|
||||
|
@ -1757,20 +1757,20 @@ static int CmdHFiClassDump(const char *Cmd) {
|
|||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
if (pagemap == PICOPASS_NON_SECURE_PAGEMODE) {
|
||||
if (pagemap == PICOPASS_NON_SECURE_PAGEMODE) {
|
||||
// all memory available
|
||||
memcpy(tag_data + (8 * 3), tempbuf + (8 * 3), (blocks_read * 8) );
|
||||
memcpy(tag_data + (8 * 3), tempbuf + (8 * 3), (blocks_read * 8));
|
||||
} else {
|
||||
// div key KD
|
||||
memcpy(tag_data + (8 * 3), tempbuf + (8 * 3), 8);
|
||||
// AIA data
|
||||
memcpy(tag_data + (8 * 5), tempbuf + (8 * 5), 8);
|
||||
// AA1 data
|
||||
memcpy(tag_data + (8 * 6), tempbuf + (8 * 6), (blocks_read * 8) );
|
||||
memcpy(tag_data + (8 * 6), tempbuf + (8 * 6), (blocks_read * 8));
|
||||
}
|
||||
|
||||
uint16_t bytes_got = (app_limit1 + 1) * 8;
|
||||
|
||||
|
||||
// try AA2 Kc, Credit
|
||||
bool aa2_success = false;
|
||||
|
||||
|
@ -1778,14 +1778,14 @@ static int CmdHFiClassDump(const char *Cmd) {
|
|||
|
||||
// AA2 authenticate credit key
|
||||
memcpy(payload.req.key, CreditKEY, 8);
|
||||
|
||||
|
||||
payload.req.use_credit_key = true;
|
||||
payload.start_block = app_limit1 + 1;
|
||||
payload.end_block = app_limit2;
|
||||
payload.req.do_auth = true;
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_HF_ICLASS_DUMP, (uint8_t*)&payload, sizeof(payload));
|
||||
SendCommandNG(CMD_HF_ICLASS_DUMP, (uint8_t *)&payload, sizeof(payload));
|
||||
|
||||
while (true) {
|
||||
printf(".");
|
||||
|
@ -1825,20 +1825,20 @@ static int CmdHFiClassDump(const char *Cmd) {
|
|||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
goto write_dump;
|
||||
}
|
||||
|
||||
|
||||
// div key KC
|
||||
memcpy(tag_data + (8 * 4), tempbuf + (8 * 4), 8);
|
||||
|
||||
// AA2 data
|
||||
memcpy(tag_data + (8 * (app_limit1 + 1)), tempbuf + (8 * (app_limit1 + 1)), (blocks_read * 8) );
|
||||
memcpy(tag_data + (8 * (app_limit1 + 1)), tempbuf + (8 * (app_limit1 + 1)), (blocks_read * 8));
|
||||
|
||||
bytes_got = (blocks_read * 8);
|
||||
|
||||
|
||||
aa2_success = true;
|
||||
}
|
||||
|
||||
write_dump:
|
||||
|
||||
|
||||
if (have_credit_key && pagemap != 0x01 && aa2_success == false)
|
||||
PrintAndLogEx(INFO, "Reading AA2 failed. dumping AA1 data to file");
|
||||
|
||||
|
@ -1859,7 +1859,7 @@ write_dump:
|
|||
saveFile(filename, ".bin", tag_data, bytes_got);
|
||||
saveFileEML(filename, tag_data, bytes_got, 8);
|
||||
saveFileJSON(filename, jsfIclass, tag_data, bytes_got, NULL);
|
||||
|
||||
|
||||
PrintAndLogEx(HINT, "Try `" _YELLOW_("hf iclass decrypt") "` to decrypt dump file");
|
||||
PrintAndLogEx(HINT, "Try `" _YELLOW_("hf iclass view") "` to view dump file");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
|
@ -1867,55 +1867,55 @@ write_dump:
|
|||
}
|
||||
|
||||
static int iclass_write_block(uint8_t blockno, uint8_t *bldata, uint8_t *KEY, bool use_credit_key, bool elite, bool rawkey, bool verbose) {
|
||||
/*
|
||||
uint8_t MAC[4] = {0x00, 0x00, 0x00, 0x00};
|
||||
uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
if (select_and_auth(KEY, MAC, div_key, use_credit_key, elite, rawkey, verbose) == false) {
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
/*
|
||||
uint8_t MAC[4] = {0x00, 0x00, 0x00, 0x00};
|
||||
uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
if (select_and_auth(KEY, MAC, div_key, use_credit_key, elite, rawkey, verbose) == false) {
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
calc_wb_mac(blockno, bldata, div_key, MAC);
|
||||
calc_wb_mac(blockno, bldata, div_key, MAC);
|
||||
|
||||
struct p {
|
||||
struct p {
|
||||
uint8_t blockno;
|
||||
uint8_t data[12];
|
||||
} PACKED payload;
|
||||
payload.blockno = blockno;
|
||||
|
||||
memcpy(payload.data, bldata, 8);
|
||||
memcpy(payload.data + 8, MAC, 4);
|
||||
|
||||
|
||||
//
|
||||
typedef struct {
|
||||
uint8_t key[8];
|
||||
bool use_raw;
|
||||
bool use_elite;
|
||||
bool use_credit_key;
|
||||
bool send_reply;
|
||||
bool do_auth;
|
||||
uint8_t blockno;
|
||||
uint8_t data[12];
|
||||
} PACKED payload;
|
||||
payload.blockno = blockno;
|
||||
} PACKED iclass_auth_req_t;
|
||||
|
||||
memcpy(payload.data, bldata, 8);
|
||||
memcpy(payload.data + 8, MAC, 4);
|
||||
|
||||
|
||||
//
|
||||
typedef struct {
|
||||
uint8_t key[8];
|
||||
bool use_raw;
|
||||
bool use_elite;
|
||||
bool use_credit_key;
|
||||
bool send_reply;
|
||||
bool do_auth;
|
||||
uint8_t blockno;
|
||||
} PACKED iclass_auth_req_t;
|
||||
// iCLASS write block request data structure
|
||||
typedef struct {
|
||||
iclass_auth_req_t req;
|
||||
uint8_t data[8];
|
||||
} PACKED iclass_writeblock_req_t;
|
||||
|
||||
// iCLASS write block request data structure
|
||||
typedef struct {
|
||||
iclass_auth_req_t req;
|
||||
uint8_t data[8];
|
||||
} PACKED iclass_writeblock_req_t;
|
||||
|
||||
|
||||
*/
|
||||
iclass_writeblock_req_t payload = {
|
||||
|
||||
*/
|
||||
iclass_writeblock_req_t payload = {
|
||||
.req.use_raw = rawkey,
|
||||
.req.use_elite = elite,
|
||||
.req.use_credit_key = use_credit_key,
|
||||
.req.blockno = blockno,
|
||||
.req.send_reply = true,
|
||||
.req.do_auth = true,
|
||||
.req.do_auth = true,
|
||||
};
|
||||
memcpy(payload.req.key, KEY, 8);
|
||||
memcpy(payload.data, bldata, sizeof(payload.data));
|
||||
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_HF_ICLASS_WRITEBL, (uint8_t *)&payload, sizeof(payload));
|
||||
PacketResponseNG resp;
|
||||
|
@ -2230,26 +2230,26 @@ static int CmdHFiClassRestore(const char *Cmd) {
|
|||
}
|
||||
|
||||
static int iclass_read_block(uint8_t *KEY, uint8_t blockno, uint8_t keyType, bool elite, bool rawkey, bool verbose, bool auth, uint8_t *out) {
|
||||
|
||||
|
||||
iclass_auth_req_t payload = {
|
||||
.use_raw = rawkey,
|
||||
.use_elite = elite,
|
||||
.use_credit_key = (keyType == 0x18),
|
||||
.blockno = blockno,
|
||||
.send_reply = true,
|
||||
.do_auth = auth,
|
||||
.do_auth = auth,
|
||||
};
|
||||
memcpy(payload.key, KEY, 8);
|
||||
|
||||
|
||||
PacketResponseNG resp;
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_HF_ICLASS_READBL, (uint8_t*)&payload, sizeof(payload));
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_HF_ICLASS_READBL, (uint8_t *)&payload, sizeof(payload));
|
||||
|
||||
if (WaitForResponseTimeout(CMD_HF_ICLASS_READBL, &resp, 2000) == false) {
|
||||
if (verbose) PrintAndLogEx(WARNING, "Command execute timeout");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
|
||||
if (resp.status != PM3_SUCCESS) {
|
||||
if (verbose) PrintAndLogEx(ERR, "failed to communicate with card");
|
||||
return PM3_EWRONGANSWER;
|
||||
|
@ -2355,24 +2355,24 @@ static int CmdHFiClass_ReadBlock(const char *Cmd) {
|
|||
|
||||
if (auth == false && verbose) {
|
||||
PrintAndLogEx(WARNING, "warning: no authentication used with read. Typical for cards configured toin `non-secure page`");
|
||||
|
||||
|
||||
}
|
||||
|
||||
uint8_t data[8] = {0};
|
||||
int res = iclass_read_block(KEY, blockno, keyType, elite, rawkey, verbose, auth, data);
|
||||
if (res != PM3_SUCCESS)
|
||||
return res;
|
||||
|
||||
|
||||
if (blockno < 6 || blockno > 7)
|
||||
return PM3_SUCCESS;
|
||||
|
||||
|
||||
if (memcmp(data, empty, 8) == 0)
|
||||
return PM3_SUCCESS;
|
||||
|
||||
bool use_sc = IsCryptoHelperPresent(verbose);
|
||||
if (use_sc == false)
|
||||
if (use_sc == false)
|
||||
return PM3_SUCCESS;
|
||||
|
||||
|
||||
// crypto helper available.
|
||||
PrintAndLogEx(INFO, "----------------------------- " _CYAN_("cardhelper") " -----------------------------");
|
||||
|
||||
|
@ -2415,7 +2415,7 @@ static int CmdHFiClass_ReadBlock(const char *Cmd) {
|
|||
|
||||
i &= 0x3C;
|
||||
PrintAndLogEx(SUCCESS, " bin : %s", binstr + i);
|
||||
PrintAndLogEx(INFO, "");
|
||||
PrintAndLogEx(INFO, "");
|
||||
PrintAndLogEx(INFO, "------------------------------ " _CYAN_("wiegand") " -------------------------------");
|
||||
wiegand_message_t packed = initialize_message_object(top, mid, bot);
|
||||
HIDTryUnpack(&packed, true);
|
||||
|
@ -2465,8 +2465,8 @@ void printIclassDumpContents(uint8_t *iclass_dump, uint8_t startblock, uint8_t e
|
|||
picopass_hdr *hdr = (picopass_hdr *)iclass_dump;
|
||||
// picopass_ns_hdr *ns_hdr = (picopass_ns_hdr *)iclass_dump;
|
||||
// uint8_t pagemap = get_pagemap(hdr);
|
||||
// if (pagemap == PICOPASS_NON_SECURE_PAGEMODE) { }
|
||||
|
||||
// if (pagemap == PICOPASS_NON_SECURE_PAGEMODE) { }
|
||||
|
||||
uint8_t lock = hdr->conf.block_writelock;
|
||||
|
||||
// is chip in ReadOnly (RO)
|
||||
|
@ -2505,11 +2505,11 @@ void printIclassDumpContents(uint8_t *iclass_dump, uint8_t startblock, uint8_t e
|
|||
PrintAndLogEx(INFO, "------+----+-------------------------+----------");
|
||||
while (i <= endblock) {
|
||||
uint8_t *blk = iclass_dump + (i * 8);
|
||||
|
||||
|
||||
bool bl_lock = false;
|
||||
if ( ro == false ) {
|
||||
switch(i) {
|
||||
case 12: {
|
||||
if (ro == false) {
|
||||
switch (i) {
|
||||
case 12: {
|
||||
bl_lock = ((lock & 0x40) == 0);
|
||||
break;
|
||||
}
|
||||
|
@ -2541,7 +2541,7 @@ void printIclassDumpContents(uint8_t *iclass_dump, uint8_t startblock, uint8_t e
|
|||
} else {
|
||||
bl_lock = true;
|
||||
}
|
||||
|
||||
|
||||
PrintAndLogEx(INFO, " %c |0x%02X| %s", (bl_lock) ? 'x' : ' ', i, sprint_hex_ascii(blk, 8));
|
||||
i++;
|
||||
}
|
||||
|
@ -2600,7 +2600,7 @@ static int CmdHFiClassView(const char *Cmd) {
|
|||
PrintAndLogEx(INFO, "Printing blocks from");
|
||||
PrintAndLogEx(INFO, "start " _YELLOW_("0x%02x") " end " _YELLOW_("0x%02x"), (startblock == 0) ? 6 : startblock, endblock);
|
||||
}
|
||||
|
||||
|
||||
print_picopass_header((picopass_hdr *) dump);
|
||||
print_picopass_info((picopass_hdr *) dump);
|
||||
|
||||
|
@ -2666,7 +2666,7 @@ static int CmdHFiClassCalcNewKey(const char *Cmd) {
|
|||
bool elite = false;
|
||||
bool errors = false;
|
||||
uint8_t cmdp = 0;
|
||||
|
||||
|
||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
||||
case 'h':
|
||||
|
@ -2737,7 +2737,7 @@ static int CmdHFiClassCalcNewKey(const char *Cmd) {
|
|||
}
|
||||
|
||||
HFiClassCalcNewKey(CSN, OLDKEY, NEWKEY, xor_div_key, elite, old_elite, true);
|
||||
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -3045,7 +3045,7 @@ static int CmdHFiClassCheckKeys(const char *Cmd) {
|
|||
clearCommandBuffer();
|
||||
SendCommandOLD(CMD_HF_ICLASS_CHKKEYS, flags, keys, 0, pre + key_offset, 4 * keys);
|
||||
PacketResponseNG resp;
|
||||
|
||||
|
||||
bool looped = false;
|
||||
while (!WaitForResponseTimeout(CMD_HF_ICLASS_CHKKEYS, &resp, 2000)) {
|
||||
timeout++;
|
||||
|
@ -3252,7 +3252,7 @@ static int CmdHFiClassLookUp(const char *Cmd) {
|
|||
|
||||
// binsearch
|
||||
item = (iclass_prekey_t *) bsearch(&lookup, prekey, keycount, sizeof(iclass_prekey_t), cmp_uint32);
|
||||
|
||||
|
||||
if (item != NULL) {
|
||||
PrintAndLogEx(SUCCESS, "Found valid key " _GREEN_("%s"), sprint_hex(item->key, 8));
|
||||
add_key(item->key);
|
||||
|
@ -3453,15 +3453,15 @@ static command_t CommandTable[] = {
|
|||
{"-----------", CmdHelp, AlwaysAvailable, "--------------------- " _CYAN_("recovery") " ---------------------"},
|
||||
{"chk", CmdHFiClassCheckKeys, AlwaysAvailable, "[options..] Check keys"},
|
||||
{"loclass", CmdHFiClass_loclass, AlwaysAvailable, "[options..] Use loclass to perform bruteforce reader attack"},
|
||||
{"lookup", CmdHFiClassLookUp, AlwaysAvailable, "[options..] Uses authentication trace to check for key in dictionary file"},
|
||||
{"lookup", CmdHFiClassLookUp, AlwaysAvailable, "[options..] Uses authentication trace to check for key in dictionary file"},
|
||||
{"replay", CmdHFiClassReader_Replay, IfPm3Iclass, "<mac> Read Picopass / iCLASS tag via replay attack"},
|
||||
|
||||
{"-----------", CmdHelp, AlwaysAvailable, "--------------------- " _CYAN_("simulation") " ---------------------"},
|
||||
{"sim", CmdHFiClassSim, IfPm3Iclass, "[options..] Simulate iCLASS tag"},
|
||||
{"eload", CmdHFiClassELoad, IfPm3Iclass, "[f <fn> ] Load Picopass / iCLASS dump file into emulator memory"},
|
||||
{"esave", CmdHFiClassESave, IfPm3Iclass, "[f <fn> ] Save emulator memory to file"},
|
||||
{"esave", CmdHFiClassESave, IfPm3Iclass, "[f <fn> ] Save emulator memory to file"},
|
||||
|
||||
{"-----------", CmdHelp, AlwaysAvailable, "--------------------- " _CYAN_("utils") " ---------------------"},
|
||||
{"-----------", CmdHelp, AlwaysAvailable, "--------------------- " _CYAN_("utils") " ---------------------"},
|
||||
{"calcnewkey", CmdHFiClassCalcNewKey, AlwaysAvailable, "[options..] Calc diversified keys (blocks 3 & 4) to write new keys"},
|
||||
{"encrypt", CmdHFiClassEncryptBlk, AlwaysAvailable, "[options..] Encrypt given block data"},
|
||||
{"decrypt", CmdHFiClassDecrypt, AlwaysAvailable, "[options..] Decrypt given block data or tag dump file" },
|
||||
|
@ -3484,16 +3484,16 @@ int CmdHFiClass(const char *Cmd) {
|
|||
}
|
||||
|
||||
//static void test_credential_type(void) {
|
||||
// need AA1 key
|
||||
// Block 5 -> tells if its a legacy or SIO, also tells which key to use.
|
||||
|
||||
// tech | blocks used | desc | num of payloads
|
||||
// -------+-----------------------+-----------------------------------+------
|
||||
// legacy | 6,7,8,9 | AA!, Access control payload | 1
|
||||
// SE | 6,7,8,9,10,11,12 | AA1, Secure identity object (SIO) | 1
|
||||
// SR | 6,7,8,9, | AA1, Access control payload | 2
|
||||
// | 10,11,12,13,14,15,16 | AA1, Secure identity object (SIO) |
|
||||
// SEOS | | |
|
||||
// need AA1 key
|
||||
// Block 5 -> tells if its a legacy or SIO, also tells which key to use.
|
||||
|
||||
// tech | blocks used | desc | num of payloads
|
||||
// -------+-----------------------+-----------------------------------+------
|
||||
// legacy | 6,7,8,9 | AA!, Access control payload | 1
|
||||
// SE | 6,7,8,9,10,11,12 | AA1, Secure identity object (SIO) | 1
|
||||
// SR | 6,7,8,9, | AA1, Access control payload | 2
|
||||
// | 10,11,12,13,14,15,16 | AA1, Secure identity object (SIO) |
|
||||
// SEOS | | |
|
||||
//}
|
||||
|
||||
int info_iclass(void) {
|
||||
|
@ -3528,32 +3528,32 @@ int info_iclass(void) {
|
|||
if (readStatus & FLAG_ICLASS_CONF) {
|
||||
PrintAndLogEx(SUCCESS, " Config: %s (Card configuration)", sprint_hex((uint8_t *)&hdr->conf, sizeof(hdr->conf)));
|
||||
}
|
||||
|
||||
|
||||
// page mapping. If fuse0|1 == 0x01, card is in non-secure mode, with CSN, CONF, AIA as top 3 blocks.
|
||||
// page9 in http://www.proxmark.org/files/Documents/13.56%20MHz%20-%20iClass/DS%20Picopass%202KS%20V1-0.pdf
|
||||
uint8_t pagemap = get_pagemap(hdr);
|
||||
if (pagemap == PICOPASS_NON_SECURE_PAGEMODE) {
|
||||
PrintAndLogEx(SUCCESS, " AIA: %s (Application Issuer area)", sprint_hex(ns_hdr->app_issuer_area, sizeof(ns_hdr->app_issuer_area)));
|
||||
} else {
|
||||
} else {
|
||||
|
||||
if (readStatus & FLAG_ICLASS_CC) {
|
||||
PrintAndLogEx(SUCCESS, "E-purse: %s (Card challenge, CC)", sprint_hex(hdr->epurse, sizeof(hdr->epurse)));
|
||||
}
|
||||
|
||||
|
||||
PrintAndLogEx(SUCCESS, " Kd: %s (Debit key, hidden)", sprint_hex(hdr->key_d, sizeof(hdr->key_d)));
|
||||
PrintAndLogEx(SUCCESS, " Kc: %s (Credit key, hidden)", sprint_hex(hdr->key_c, sizeof(hdr->key_c)));
|
||||
|
||||
if (readStatus & FLAG_ICLASS_AIA) {
|
||||
PrintAndLogEx(SUCCESS, " AIA: %s (Application Issuer area)", sprint_hex(hdr->app_issuer_area, sizeof(hdr->app_issuer_area)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (readStatus & FLAG_ICLASS_CONF) {
|
||||
print_picopass_info(hdr);
|
||||
print_picopass_info(hdr);
|
||||
}
|
||||
|
||||
PrintAndLogEx(INFO, "------ " _CYAN_("Fingerprint") " ------");
|
||||
|
||||
|
||||
uint8_t aia[8];
|
||||
if (pagemap == PICOPASS_NON_SECURE_PAGEMODE)
|
||||
memcpy(aia, ns_hdr->app_issuer_area, sizeof(aia));
|
||||
|
@ -3565,7 +3565,7 @@ int info_iclass(void) {
|
|||
|
||||
bool legacy = (memcmp(aia, "\xff\xff\xff\xff\xff\xff\xff\xff", 8) == 0);
|
||||
bool se_enabled = (memcmp(aia, "\xff\xff\xff\x00\x06\xff\xff\xff", 8) == 0);
|
||||
|
||||
|
||||
if (isHidRange) {
|
||||
PrintAndLogEx(SUCCESS, "CSN is in HID range");
|
||||
if (legacy)
|
||||
|
|
|
@ -1720,7 +1720,7 @@ static int CmdHF14AMfNestedHard(const char *Cmd) {
|
|||
}
|
||||
cmdp++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
case 't':
|
||||
tests = param_get32ex(Cmd, cmdp + 1, 100, 10);
|
||||
if (!param_gethex(Cmd, cmdp + 2, trgkey, 12)) {
|
||||
|
@ -1858,8 +1858,8 @@ static int CmdHF14AMfNestedHard(const char *Cmd) {
|
|||
trgKeyType ? 'B' : 'A',
|
||||
trgkey[0], trgkey[1], trgkey[2], trgkey[3], trgkey[4], trgkey[5],
|
||||
know_target_key ? "" : " (not set)"
|
||||
);
|
||||
PrintAndLogEx(INFO , "File action: %s, Slow: %s, Tests: %d ",
|
||||
);
|
||||
PrintAndLogEx(INFO, "File action: %s, Slow: %s, Tests: %d ",
|
||||
nonce_file_write ? "write" : nonce_file_read ? "read" : "none",
|
||||
slow ? "Yes" : "No",
|
||||
tests);
|
||||
|
@ -1867,7 +1867,7 @@ static int CmdHF14AMfNestedHard(const char *Cmd) {
|
|||
uint64_t foundkey = 0;
|
||||
int16_t isOK = mfnestedhard(blockNo, keyType, key, trgBlockNo, trgKeyType, know_target_key ? trgkey : NULL, nonce_file_read, nonce_file_write, slow, tests, &foundkey, filename);
|
||||
|
||||
if (tests == 0)
|
||||
if (tests == 0)
|
||||
DropField();
|
||||
|
||||
if (isOK) {
|
||||
|
|
|
@ -1864,7 +1864,7 @@ static int getKeySettings(uint8_t *aid) {
|
|||
// KEY Settings - AMK
|
||||
uint8_t num_keys = 0;
|
||||
uint8_t key_setting = 0;
|
||||
mifare_des_authalgo_t algo=MFDES_ALGO_DES;
|
||||
mifare_des_authalgo_t algo = MFDES_ALGO_DES;
|
||||
res = key_setting_to_algo(aid, &key_setting, &algo, &num_keys);
|
||||
|
||||
if (res == PM3_SUCCESS) {
|
||||
|
@ -1916,7 +1916,7 @@ static int getKeySettings(uint8_t *aid) {
|
|||
// KEY Settings - AMK
|
||||
uint8_t num_keys = 0;
|
||||
uint8_t key_setting = 0;
|
||||
mifare_des_authalgo_t algo=MFDES_ALGO_DES;
|
||||
mifare_des_authalgo_t algo = MFDES_ALGO_DES;
|
||||
res = key_setting_to_algo(aid, &key_setting, &algo, &num_keys);
|
||||
if (res == PM3_SUCCESS) {
|
||||
desfire_print_keysetting(key_setting, num_keys, algo);
|
||||
|
@ -2669,7 +2669,7 @@ static int CmdHF14ADesReadData(const char *Cmd) {
|
|||
|
||||
if (res_flen) {
|
||||
PrintAndLogEx(ERR, "File size input error");
|
||||
return PM3_EINVARG;
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
swap24(filesize);
|
||||
|
@ -2859,7 +2859,7 @@ static int CmdHF14ADesWriteData(const char *Cmd) {
|
|||
// with 2char hex, 512bytes could be input.
|
||||
// Instead large binary inputs should be BINARY files and written to card.
|
||||
int dlength = 512;
|
||||
uint8_t data[512] = {0};
|
||||
uint8_t data[512] = {0};
|
||||
int res_data = CLIParamHexToBuf(arg_get_str(ctx, 3), data, 512, &dlength);
|
||||
|
||||
int type = arg_get_int(ctx, 4);
|
||||
|
@ -3767,12 +3767,12 @@ static int CmdHF14ADesChangeKey(const char *Cmd) {
|
|||
uint8_t key[24] = {0};
|
||||
int keylen = 0;
|
||||
int res_klen = CLIParamHexToBuf(arg_get_str(ctx, 3), key, 24, &keylen);
|
||||
|
||||
|
||||
uint8_t newcmdAuthAlgo = arg_get_int_def(ctx, 4, 0);
|
||||
uint8_t newkey[24] = {0};
|
||||
int newkeylen = 0;
|
||||
int res_newklen = CLIParamHexToBuf(arg_get_str(ctx, 5), newkey, 24, &newkeylen);
|
||||
|
||||
|
||||
uint8_t aesversion = arg_get_int_def(ctx, 6, 0);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
|
@ -4535,7 +4535,7 @@ static int CmdHF14aDesNDEF(const char *Cmd) {
|
|||
if (res == PM3_SUCCESS) {
|
||||
uint32_t len = le24toh(fdata.length);
|
||||
NDEFDecodeAndPrint(data, datalen, verbose);
|
||||
|
||||
|
||||
} else {
|
||||
PrintAndLogEx(ERR, "Couldn't read value. Error %d", res);
|
||||
res = handler_desfire_select_application(aid);
|
||||
|
|
|
@ -1206,7 +1206,7 @@ static bool CheckChipType(bool getDeviceData) {
|
|||
PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`lf t55xx`") " commands");
|
||||
retval = true;
|
||||
}
|
||||
|
||||
|
||||
// check for em4x50 chips
|
||||
if (detect_4x50_block()) {
|
||||
PrintAndLogEx(SUCCESS, "Chipset detection: " _GREEN_("EM4x50"));
|
||||
|
@ -1293,7 +1293,7 @@ int CmdLFfind(const char *Cmd) {
|
|||
if (demodParadox() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Paradox ID") " found!"); goto out;}
|
||||
if (demodNexWatch() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("NexWatch ID") " found!"); goto out;}
|
||||
if (demodIndala() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Indala ID") " found!"); goto out;}
|
||||
|
||||
|
||||
if (demodEM410x() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("EM410x ID") " found!"); goto out;}
|
||||
if (demodFDX() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("FDX-B ID") " found!"); goto out;}
|
||||
if (demodGuard() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Guardall G-Prox II ID") " found!"); goto out; }
|
||||
|
@ -1310,7 +1310,7 @@ int CmdLFfind(const char *Cmd) {
|
|||
if (demodSecurakey() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Securakey ID") " found!"); goto out;}
|
||||
if (demodViking() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Viking ID") " found!"); goto out;}
|
||||
if (demodGallagher() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("GALLAGHER ID") " found!"); goto out;}
|
||||
|
||||
|
||||
// if (demodTI() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Texas Instrument ID") " found!"); goto out;}
|
||||
//if (demodFermax() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Fermax ID") " found!"); goto out;}
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ static int usage_lf_em410x_brute(void) {
|
|||
PrintAndLogEx(NORMAL, "Examples:");
|
||||
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 410x_brute ids.txt"));
|
||||
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 410x_brute ids.txt c 32"));
|
||||
PrintAndLogEx(NORMAL, _YELLOW_( " lf em 410x_brute ids.txt d 3000"));
|
||||
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 410x_brute ids.txt d 3000"));
|
||||
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 410x_brute ids.txt d 3000 c 32"));
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
@ -408,7 +408,7 @@ int AskEm410xDemod(const char *Cmd, uint32_t *hi, uint64_t *lo, bool verbose) {
|
|||
static int CmdEM410xWatch(const char *Cmd) {
|
||||
uint8_t c = tolower(param_getchar(Cmd, 0));
|
||||
if (c == 'h') return usage_lf_em410x_watch();
|
||||
|
||||
|
||||
PrintAndLogEx(SUCCESS, "Watching for EM410x cards - place tag on antenna");
|
||||
PrintAndLogEx(INFO, "Press pm3-button to stop reading cards");
|
||||
clearCommandBuffer();
|
||||
|
@ -639,7 +639,7 @@ static int CmdEM410xWrite(const char *Cmd) {
|
|||
} else if (card == 0) {
|
||||
PrintAndLogEx(SUCCESS, "Writing %s tag with UID 0x%010" PRIx64 "(clock rate: %d)", _GREEN_("T5555"), id, clock1);
|
||||
}
|
||||
|
||||
|
||||
struct {
|
||||
uint8_t card;
|
||||
uint8_t clock;
|
||||
|
@ -657,7 +657,7 @@ static int CmdEM410xWrite(const char *Cmd) {
|
|||
|
||||
PacketResponseNG resp;
|
||||
WaitForResponse(CMD_LF_EM410X_WRITE, &resp);
|
||||
switch(resp.status) {
|
||||
switch (resp.status) {
|
||||
case PM3_SUCCESS: {
|
||||
PrintAndLogEx(SUCCESS, "Done");
|
||||
PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`lf em 410x_read`") " to verify");
|
||||
|
|
|
@ -114,8 +114,8 @@ static void prepare_result(const uint8_t *byte, int fwr, int lwr, em4x50_word_t
|
|||
c[j] = 0;
|
||||
|
||||
for (int j = 0; j < 4; j++) {
|
||||
words[i].byte[j] = byte[i*7+j];
|
||||
words[i].row_parity[j] = (byte[i*7+4] >> (3-j)) & 1;
|
||||
words[i].byte[j] = byte[i * 7 + j];
|
||||
words[i].row_parity[j] = (byte[i * 7 + 4] >> (3 - j)) & 1;
|
||||
|
||||
// collect parities
|
||||
p = 0;
|
||||
|
@ -126,7 +126,7 @@ static void prepare_result(const uint8_t *byte, int fwr, int lwr, em4x50_word_t
|
|||
p ^= (words[i].byte[j] >> k) & 1;
|
||||
|
||||
// column parity
|
||||
c[k] ^= (words[i].byte[j] >> (7-k)) & 1;
|
||||
c[k] ^= (words[i].byte[j] >> (7 - k)) & 1;
|
||||
}
|
||||
|
||||
// check row parities
|
||||
|
@ -137,17 +137,17 @@ static void prepare_result(const uint8_t *byte, int fwr, int lwr, em4x50_word_t
|
|||
}
|
||||
|
||||
// check column parities
|
||||
words[i].col_parity = byte[i*7+5];
|
||||
words[i].col_parity = byte[i * 7 + 5];
|
||||
|
||||
for (int j = 0; j < 8; j++) {
|
||||
words[i].cparity[j] = (((words[i].col_parity >> (7-j)) & 1) == c[j]) ? true : false;
|
||||
words[i].cparity[j] = (((words[i].col_parity >> (7 - j)) & 1) == c[j]) ? true : false;
|
||||
|
||||
if (!words[i].cparity[j])
|
||||
words[i].parity = false;
|
||||
words[i].parity = false;
|
||||
}
|
||||
|
||||
// check stop bit
|
||||
words[i].stopbit = byte[i*7+6] & 1;
|
||||
words[i].stopbit = byte[i * 7 + 6] & 1;
|
||||
|
||||
if (words[i].stopbit == 1)
|
||||
words[i].stopparity = false;
|
||||
|
@ -166,7 +166,7 @@ static void print_result(const em4x50_word_t *words, int fwr, int lwr) {
|
|||
for (int i = fwr; i <= lwr; i++) {
|
||||
|
||||
char s[50] = {0};
|
||||
switch(i) {
|
||||
switch (i) {
|
||||
case EM4X50_DEVICE_PASSWORD:
|
||||
sprintf(s, _YELLOW_("password, write only"));
|
||||
break;
|
||||
|
@ -191,13 +191,13 @@ static void print_result(const em4x50_word_t *words, int fwr, int lwr) {
|
|||
for (int j = 3; j >= 0; j--) {
|
||||
sprintf(r + strlen(r), "%02x ", reflect8(words[i].byte[j]));
|
||||
}
|
||||
|
||||
|
||||
PrintAndLogEx(INFO, " %2i | " _GREEN_("%s") "| %s| %s",
|
||||
i,
|
||||
sprint_hex(words[i].byte, 4),
|
||||
r,
|
||||
s
|
||||
);
|
||||
i,
|
||||
sprint_hex(words[i].byte, 4),
|
||||
r,
|
||||
s
|
||||
);
|
||||
}
|
||||
PrintAndLogEx(INFO, "----+-------------+-------------+--------------------");
|
||||
}
|
||||
|
@ -226,14 +226,14 @@ static void print_info_result(uint8_t *data, bool verbose) {
|
|||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, _YELLOW_("EM4x50 data:"));
|
||||
print_result(words, 0, EM4X50_NO_WORDS - 1);
|
||||
|
||||
|
||||
// configuration section
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "---- " _CYAN_("Configuration") " ----");
|
||||
|
||||
PrintAndLogEx(INFO, "first word read %3i", fwr);
|
||||
PrintAndLogEx(INFO, "last word read %3i", lwr);
|
||||
PrintAndLogEx(INFO, "password check %3s", (bpwc) ? _RED_("on"): _GREEN_("off"));
|
||||
PrintAndLogEx(INFO, "password check %3s", (bpwc) ? _RED_("on") : _GREEN_("off"));
|
||||
PrintAndLogEx(INFO, "read after write %3s", (braw) ? "on" : "off");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "--------- " _CYAN_("Protection") " ---------");
|
||||
|
@ -288,9 +288,9 @@ int CmdEM4x50Info(const char *Cmd) {
|
|||
|
||||
case 'p':
|
||||
if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) {
|
||||
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
etd.pwd_given = true;
|
||||
cmdp += 2;
|
||||
break;
|
||||
|
@ -308,8 +308,8 @@ int CmdEM4x50Info(const char *Cmd) {
|
|||
}
|
||||
|
||||
// validation
|
||||
if (errors)
|
||||
return usage_lf_em4x50_info();
|
||||
if (errors)
|
||||
return usage_lf_em4x50_info();
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_LF_EM4X50_INFO, (uint8_t *)&etd, sizeof(etd));
|
||||
|
@ -346,17 +346,17 @@ int CmdEM4x50Write(const char *Cmd) {
|
|||
}
|
||||
case 'p': {
|
||||
if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) {
|
||||
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
etd.pwd_given = true;
|
||||
cmdp += 2;
|
||||
break;
|
||||
}
|
||||
case 'w': {
|
||||
if (param_gethex(Cmd, cmdp + 1, etd.word, 8)) {
|
||||
PrintAndLogEx(FAILED, "\n word has to be 8 hex symbols\n");
|
||||
return PM3_EINVARG;
|
||||
PrintAndLogEx(FAILED, "\n word has to be 8 hex symbols\n");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
bword = true;
|
||||
cmdp += 2;
|
||||
|
@ -383,7 +383,7 @@ int CmdEM4x50Write(const char *Cmd) {
|
|||
}
|
||||
|
||||
if (errors || !bword || !baddr)
|
||||
return usage_lf_em4x50_write();
|
||||
return usage_lf_em4x50_write();
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_LF_EM4X50_WRITE, (uint8_t *)&etd, sizeof(etd));
|
||||
|
@ -428,7 +428,7 @@ static void print_write_password_result(PacketResponseNG *resp, const em4x50_dat
|
|||
sprintf(pstring, "\n writing new password " _GREEN_("ok"));
|
||||
strcat(string, pstring);
|
||||
|
||||
PrintAndLogEx(NORMAL,"%s\n", string);
|
||||
PrintAndLogEx(NORMAL, "%s\n", string);
|
||||
}
|
||||
|
||||
int CmdEM4x50WritePassword(const char *Cmd) {
|
||||
|
@ -452,8 +452,8 @@ int CmdEM4x50WritePassword(const char *Cmd) {
|
|||
|
||||
case 'p':
|
||||
if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) {
|
||||
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
|
||||
return PM3_EINVARG;
|
||||
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
bpwd = true;
|
||||
etd.pwd_given = true;
|
||||
|
@ -462,9 +462,9 @@ int CmdEM4x50WritePassword(const char *Cmd) {
|
|||
|
||||
case 'n':
|
||||
if (param_gethex(Cmd, cmdp + 1, etd.new_password, 8)) {
|
||||
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
bnpwd = true;
|
||||
etd.newpwd_given = true;
|
||||
cmdp += 2;
|
||||
|
@ -478,7 +478,7 @@ int CmdEM4x50WritePassword(const char *Cmd) {
|
|||
}
|
||||
|
||||
if (errors || !bpwd || !bnpwd)
|
||||
return usage_lf_em4x50_write_password();
|
||||
return usage_lf_em4x50_write_password();
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_LF_EM4X50_WRITE_PASSWORD, (uint8_t *)&etd, sizeof(etd));
|
||||
|
@ -493,7 +493,7 @@ int CmdEM4x50WritePassword(const char *Cmd) {
|
|||
if (success)
|
||||
print_write_password_result(&resp, &etd);
|
||||
else
|
||||
PrintAndLogEx(NORMAL,"\nwriting password " _RED_("failed") "\n");
|
||||
PrintAndLogEx(NORMAL, "\nwriting password " _RED_("failed") "\n");
|
||||
|
||||
return (success) ? PM3_SUCCESS : PM3_ESOFT;
|
||||
}
|
||||
|
@ -583,9 +583,9 @@ int CmdEM4x50Read(const char *Cmd) {
|
|||
}
|
||||
case 'p': {
|
||||
if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) {
|
||||
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
etd.pwd_given = true;
|
||||
cmdp += 2;
|
||||
break;
|
||||
|
@ -599,7 +599,7 @@ int CmdEM4x50Read(const char *Cmd) {
|
|||
}
|
||||
|
||||
if (errors || strlen(Cmd) == 0 || etd.addr_given == false)
|
||||
return usage_lf_em4x50_read();
|
||||
return usage_lf_em4x50_read();
|
||||
|
||||
return em4x50_read(&etd, NULL, true);
|
||||
}
|
||||
|
@ -627,9 +627,9 @@ int CmdEM4x50Dump(const char *Cmd) {
|
|||
break;
|
||||
case 'p': {
|
||||
if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) {
|
||||
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
etd.pwd_given = true;
|
||||
cmdp += 2;
|
||||
break;
|
||||
|
@ -642,8 +642,8 @@ int CmdEM4x50Dump(const char *Cmd) {
|
|||
}
|
||||
|
||||
// validation
|
||||
if (errors)
|
||||
return usage_lf_em4x50_dump();
|
||||
if (errors)
|
||||
return usage_lf_em4x50_dump();
|
||||
|
||||
PrintAndLogEx(INFO, "reading EM4x50 tag");
|
||||
clearCommandBuffer();
|
||||
|
@ -675,8 +675,8 @@ int CmdEM4x50Dump(const char *Cmd) {
|
|||
}
|
||||
|
||||
uint8_t data[EM4X50_NO_WORDS * 4] = {0};
|
||||
for (int i=0; i < EM4X50_NO_WORDS; i++) {
|
||||
memcpy(data + (i*4), words[i].byte, 4);
|
||||
for (int i = 0; i < EM4X50_NO_WORDS; i++) {
|
||||
memcpy(data + (i * 4), words[i].byte, 4);
|
||||
}
|
||||
|
||||
// saveFileEML will add .eml extension to filename
|
||||
|
@ -704,8 +704,8 @@ int CmdEM4x50Wipe(const char *Cmd) {
|
|||
|
||||
case 'p':
|
||||
if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) {
|
||||
PrintAndLogEx(FAILED, "\npassword has to be 8 hex symbols\n");
|
||||
return PM3_EINVARG;
|
||||
PrintAndLogEx(FAILED, "\npassword has to be 8 hex symbols\n");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
bpwd = true;
|
||||
cmdp += 2;
|
||||
|
@ -719,12 +719,12 @@ int CmdEM4x50Wipe(const char *Cmd) {
|
|||
}
|
||||
|
||||
if (errors || !bpwd)
|
||||
return usage_lf_em4x50_wipe();
|
||||
return usage_lf_em4x50_wipe();
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_LF_EM4X50_WIPE, (uint8_t *)&etd, sizeof(etd));
|
||||
|
||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2*TIMEOUT)) {
|
||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2 * TIMEOUT)) {
|
||||
PrintAndLogEx(WARNING, "\ntimeout while waiting for reply.\n");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
@ -732,9 +732,9 @@ int CmdEM4x50Wipe(const char *Cmd) {
|
|||
// print response
|
||||
bool isOK = resp.status;
|
||||
if (isOK) {
|
||||
PrintAndLogEx(SUCCESS,"\nwiping data " _GREEN_("ok") "\n");
|
||||
PrintAndLogEx(SUCCESS, "\nwiping data " _GREEN_("ok") "\n");
|
||||
} else {
|
||||
PrintAndLogEx(FAILED,"\nwiping data " _RED_("failed") "\n");
|
||||
PrintAndLogEx(FAILED, "\nwiping data " _RED_("failed") "\n");
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
|
|
|
@ -246,10 +246,10 @@ static int CmdHIDDemod(const char *Cmd) {
|
|||
}
|
||||
if (fmtLen == 32 && (lo & 0x40000000)) { //if 32 bit and Kastle bit set
|
||||
PrintAndLogEx(SUCCESS,
|
||||
"HID Prox (Kastle format) - " _GREEN_("%x%08x (%u)") " - len: " _GREEN_("32") " bit CC: " _GREEN_("%u") " FC: " _GREEN_("%u") " Card: " _GREEN_("%u"), hi, lo, (lo >> 1) & 0xFFFF, cc, fc, cardnum);
|
||||
"HID Prox (Kastle format) - " _GREEN_("%x%08x (%u)") " - len: " _GREEN_("32") " bit CC: " _GREEN_("%u") " FC: " _GREEN_("%u") " Card: " _GREEN_("%u"), hi, lo, (lo >> 1) & 0xFFFF, cc, fc, cardnum);
|
||||
} else {
|
||||
PrintAndLogEx(SUCCESS,
|
||||
"HID Prox - " _GREEN_("%x%08x (%u)") " - len: " _GREEN_("%u") " bit - OEM: " _GREEN_("%03u") " FC: " _GREEN_("%u")" Card: " _GREEN_("%u"),
|
||||
PrintAndLogEx(SUCCESS,
|
||||
"HID Prox - " _GREEN_("%x%08x (%u)") " - len: " _GREEN_("%u") " bit - OEM: " _GREEN_("%03u") " FC: " _GREEN_("%u")" Card: " _GREEN_("%u"),
|
||||
hi, lo, cardnum, fmtLen, oem, fc, cardnum);
|
||||
}
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ static int CmdHIDWatch(const char *Cmd) {
|
|||
PrintAndLogEx(SUCCESS, "Watching for HID Prox cards - place tag on antenna");
|
||||
PrintAndLogEx(INFO, "Press pm3-button to stop reading cards");
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_LF_HID_WATCH, NULL, 0);
|
||||
SendCommandNG(CMD_LF_HID_WATCH, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
WaitForResponse(CMD_LF_HID_WATCH, &resp);
|
||||
PrintAndLogEx(INFO, "Done");
|
||||
|
|
|
@ -738,7 +738,7 @@ void annotateHitag1(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize, bool
|
|||
}
|
||||
|
||||
void annotateHitag2(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize, bool is_response) {
|
||||
|
||||
|
||||
// iceman: live decrypt of trace?
|
||||
if (is_response) {
|
||||
|
||||
|
@ -774,18 +774,18 @@ void annotateHitag2(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize, bool
|
|||
}
|
||||
|
||||
if (cmdsize == 9) {
|
||||
snprintf(exp, size, "Nr Ar Is response");
|
||||
return;
|
||||
snprintf(exp, size, "Nr Ar Is response");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
||||
if (cmdsize == 9) {
|
||||
snprintf(exp, size, "Nr Ar");
|
||||
return;
|
||||
snprintf(exp, size, "Nr Ar");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void annotateHitagS(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize, bool is_reader) {
|
||||
|
|
|
@ -54,7 +54,7 @@ static int usage_lf_indala_demod(void) {
|
|||
PrintAndLogEx(NORMAL, _YELLOW_(" lf indala demod 32") " = demod a Indala tag from GraphBuffer using a clock of RF/32");
|
||||
PrintAndLogEx(NORMAL, _YELLOW_(" lf indala demod 32 1") " = demod a Indala tag from GraphBuffer using a clock of RF/32 and inverting data");
|
||||
PrintAndLogEx(NORMAL, _YELLOW_(" lf indala demod 64 1 0") " = demod a Indala tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -172,7 +172,7 @@ static int CmdIOProxDemod(const char *Cmd) {
|
|||
char crc_str[36] = {0};
|
||||
|
||||
if (crc == calccrc) {
|
||||
snprintf(crc_str, sizeof(crc_str), "(" _GREEN_("ok") ")" );
|
||||
snprintf(crc_str, sizeof(crc_str), "(" _GREEN_("ok") ")");
|
||||
} else {
|
||||
snprintf(crc_str, sizeof(crc_str), "(" _RED_("fail") ") 0x%02X != 0x%02X", crc, calccrc);
|
||||
retval = PM3_ESOFT;
|
||||
|
|
|
@ -190,7 +190,7 @@ int demodKeri(void) {
|
|||
Might be a hash of FC & CN to generate Internal ID
|
||||
*/
|
||||
|
||||
PrintAndLogEx(SUCCESS, "KERI - Internal ID: " _GREEN_("%u") ", Raw: %08X%08X" , ID, raw1, raw2);
|
||||
PrintAndLogEx(SUCCESS, "KERI - Internal ID: " _GREEN_("%u") ", Raw: %08X%08X", ID, raw1, raw2);
|
||||
/*
|
||||
Descramble Data.
|
||||
*/
|
||||
|
|
|
@ -35,7 +35,7 @@ static int CmdMotorolaDemod(const char *Cmd) {
|
|||
}
|
||||
|
||||
int demodMotorola(void) {
|
||||
|
||||
|
||||
//PSK1
|
||||
if (PSKDemod("32 1", true) != PM3_SUCCESS) {
|
||||
PrintAndLogEx(DEBUG, "DEBUG: Error - Motorola: PSK Demod failed");
|
||||
|
@ -118,7 +118,7 @@ int demodMotorola(void) {
|
|||
checksum |= DemodBuffer[62] << 1; // b2
|
||||
checksum |= DemodBuffer[63] << 0; // b1
|
||||
|
||||
|
||||
|
||||
PrintAndLogEx(SUCCESS, "Motorola - fmt: " _GREEN_("26") " FC: " _GREEN_("%u") " Card: " _GREEN_("%u") ", Raw: %08X%08X", fc, csn, raw1, raw2);
|
||||
PrintAndLogEx(DEBUG, "checksum: " _GREEN_("%1d%1d"), checksum >> 1 & 0x01, checksum & 0x01);
|
||||
return PM3_SUCCESS;
|
||||
|
|
|
@ -250,7 +250,7 @@ int demodNexWatch(void) {
|
|||
} else {
|
||||
PrintAndLogEx(DEBUG, " parity : %s (0x%X != 0x%X)", _RED_("fail"), parity, calc_parity);
|
||||
}
|
||||
|
||||
|
||||
PrintAndLogEx(DEBUG, " checksum : %s (0x%02X)", (m_idx < ARRAYLEN(items)) ? _GREEN_("ok") : _RED_("fail"), chk);
|
||||
|
||||
PrintAndLogEx(INFO, " Raw : " _YELLOW_("%"PRIX32"%"PRIX32"%"PRIX32), raw1, raw2, raw3);
|
||||
|
|
|
@ -88,7 +88,7 @@ static int demodbuf_to_pacid(uint8_t *src, const size_t src_size, uint8_t *dst,
|
|||
}
|
||||
|
||||
// overwrite checksum byte with null terminator
|
||||
dst[dataLength - 1] = 0;
|
||||
dst[dataLength - 1] = 0;
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ const uint8_t paradox_lut[] = {
|
|||
0x9F, 0xED, 0x7D, 0x59, 0x22, 0x84, 0x21, 0x4E,
|
||||
0x39, 0x48, 0x12, 0x88, 0x53, 0xDE, 0xBB, 0xE4,
|
||||
0xB4, 0x2D, 0x4D, 0x55, 0xCA, 0xBE, 0xA3, 0xE2
|
||||
};
|
||||
};
|
||||
// FC:108, Card01827
|
||||
// 00000000 01101100 00000111 00100011
|
||||
// hex(0xED xor 0x7D xor 0x22 xor 0x84 xor 0xDE xor 0xBB xor 0xE4 xor 0x4D xor 0xA3 xor 0xE2 xor 0x47) 0xFC
|
||||
|
@ -132,7 +132,7 @@ int demodParadox(void) {
|
|||
|
||||
// not manchester data
|
||||
if (bits[i] == bits[i + 1]) {
|
||||
PrintAndLogEx(WARNING, "Error Manchester at %u", i);
|
||||
PrintAndLogEx(WARNING, "Error Manchester at %u", i);
|
||||
error++;
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ int demodParadox(void) {
|
|||
lo |= 1; // 10
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
setDemodBuff(bits, size, idx);
|
||||
setClockGrid(50, wave_idx + (idx * 50));
|
||||
|
||||
|
@ -163,11 +163,11 @@ int demodParadox(void) {
|
|||
// checksum?
|
||||
uint8_t calc_chksum = 0x47;
|
||||
uint8_t pos = 0;
|
||||
for(uint8_t i = 0; i < 8; i++ ) {
|
||||
|
||||
uint8_t ice = rawhex[i+1];
|
||||
for(uint8_t j = 0x80; j > 0; j >>= 2) {
|
||||
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
|
||||
uint8_t ice = rawhex[i + 1];
|
||||
for (uint8_t j = 0x80; j > 0; j >>= 2) {
|
||||
|
||||
if (ice & j) {
|
||||
calc_chksum ^= paradox_lut[pos];
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ int demodParadox(void) {
|
|||
uint32_t crc = CRC8Maxim(rawhex + 1, 8);
|
||||
PrintAndLogEx(DEBUG, " FSK/MAN raw : %s", sprint_hex(rawhex, sizeof(rawhex)));
|
||||
PrintAndLogEx(DEBUG, " raw : %s = (maxim crc8) %02x == %02x", sprint_hex(rawhex + 1, 8), crc, calc_chksum);
|
||||
// PrintAndLogEx(DEBUG, " OTHER sample CRC-8/MAXIM : 55 55 69 A5 55 6A 59 5A = FC");
|
||||
// PrintAndLogEx(DEBUG, " OTHER sample CRC-8/MAXIM : 55 55 69 A5 55 6A 59 5A = FC");
|
||||
|
||||
uint32_t rawLo = bytebits_to_byte(bits + idx + 64, 32);
|
||||
uint32_t rawHi = bytebits_to_byte(bits + idx + 32, 32);
|
||||
|
|
|
@ -1359,8 +1359,8 @@ bool testKnownConfigBlock(uint32_t block0) {
|
|||
case T55X7_NEDAP_128_CONFIG_BLOCK:
|
||||
case T55X7_VISA2000_CONFIG_BLOCK:
|
||||
case T55X7_SECURAKEY_CONFIG_BLOCK:
|
||||
case T55X7_PAC_CONFIG_BLOCK:
|
||||
case T55X7_VERICHIP_CONFIG_BLOCK:
|
||||
case T55X7_PAC_CONFIG_BLOCK:
|
||||
case T55X7_VERICHIP_CONFIG_BLOCK:
|
||||
case T55X7_KERI_CONFIG_BLOCK:
|
||||
case T55X7_NEXWATCH_CONFIG_BLOCK:
|
||||
case T55X7_JABLOTRON_CONFIG_BLOCK:
|
||||
|
@ -2109,7 +2109,7 @@ static void printT5x7KnownBlock0(uint32_t b0) {
|
|||
break;
|
||||
case T55X7_NEXWATCH_CONFIG_BLOCK:
|
||||
snprintf(s + strlen(s), sizeof(s) - strlen(s), "NexWatch, Quadrakey ");
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
// and it should actually be "10000" (16)
|
||||
// #define T55X7_FDXB_CONFIG_BLOCK 0x903F8080 // BiPhase, fdx-b - xtended mode, BiPhase ('57), data rate 32, 4 data blocks
|
||||
#define T55X7_FDXB_CONFIG_BLOCK 0x903F0082 // BiPhase, fdx-b - xtended mode, BiPhase ('50), invert data, data rate 32, 4 data blocks
|
||||
#define T55X7_FDXB_2_CONFIG_BLOCK 0x00098080 //
|
||||
#define T55X7_FDXB_2_CONFIG_BLOCK 0x00098080 //
|
||||
|
||||
#define T55X7_HID_26_CONFIG_BLOCK 0x00107060 // FSK2a, hid 26 bit - compat mode, data rate 50, 3 data blocks
|
||||
#define T55X7_PARADOX_CONFIG_BLOCK 0x00107060 // FSK2a, hid 26 bit - compat mode, data rate 50, 3 data blocks
|
||||
|
|
|
@ -249,7 +249,7 @@ static int CmdPref(const char *Cmd) {
|
|||
|
||||
static command_t CommandTable[] = {
|
||||
|
||||
{"--------",CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("Technology") " -----------------------"},
|
||||
{"--------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("Technology") " -----------------------"},
|
||||
|
||||
{"analyse", CmdAnalyse, AlwaysAvailable, "{ Analyse utils... }"},
|
||||
{"data", CmdData, AlwaysAvailable, "{ Plot window / data buffer manipulation... }"},
|
||||
|
@ -264,7 +264,7 @@ static command_t CommandTable[] = {
|
|||
{"trace", CmdTrace, AlwaysAvailable, "{ Trace manipulation... }"},
|
||||
{"usart", CmdUsart, IfPm3FpcUsartFromUsb, "{ USART commands... }"},
|
||||
{"wiegand", CmdWiegand, AlwaysAvailable, "{ Wiegand format manipulation... }"},
|
||||
{"--------",CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("General") " -----------------------"},
|
||||
{"--------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("General") " -----------------------"},
|
||||
{"auto", CmdAuto, IfPm3Present, "Automated detection process for unknown tags"},
|
||||
{"help", CmdHelp, AlwaysAvailable, "This help. Use " _YELLOW_("'<command> help'") " for details of a particular command."},
|
||||
{"hints", CmdHints, AlwaysAvailable, "Turn hints on / off"},
|
||||
|
|
|
@ -467,7 +467,7 @@ static int CmdSmartRaw(const char *Cmd) {
|
|||
|
||||
uint8_t flags = SC_LOG;
|
||||
if (active || active_select) {
|
||||
|
||||
|
||||
flags |= (SC_CONNECT | SC_CLEARLOG);
|
||||
if (active_select)
|
||||
flags |= SC_SELECT;
|
||||
|
|
|
@ -206,10 +206,10 @@ static uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *tr
|
|||
return traceLen;
|
||||
}
|
||||
|
||||
// adjust for different time scales
|
||||
if (protocol == ICLASS || protocol == ISO_15693) {
|
||||
duration *= 32;
|
||||
}
|
||||
// adjust for different time scales
|
||||
if (protocol == ICLASS || protocol == ISO_15693) {
|
||||
duration *= 32;
|
||||
}
|
||||
|
||||
|
||||
uint8_t *frame = hdr->frame;
|
||||
|
@ -275,10 +275,10 @@ static uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *tr
|
|||
|
||||
if (data_len == 0) {
|
||||
if (protocol == ICLASS && duration == 2048) {
|
||||
sprintf(line[0], "<SOF>");
|
||||
} else if (protocol == ISO_15693 && duration == 512) {
|
||||
sprintf(line[0], "<EOF>");
|
||||
} else {
|
||||
sprintf(line[0], "<SOF>");
|
||||
} else if (protocol == ISO_15693 && duration == 512) {
|
||||
sprintf(line[0], "<EOF>");
|
||||
} else {
|
||||
sprintf(line[0], "<empty trace - possible error>");
|
||||
}
|
||||
}
|
||||
|
@ -334,11 +334,11 @@ static uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *tr
|
|||
|
||||
uint32_t previous_end_of_transmission_timestamp = 0;
|
||||
if (prev_eot) {
|
||||
if (*prev_eot) {
|
||||
previous_end_of_transmission_timestamp = *prev_eot;
|
||||
} else {
|
||||
previous_end_of_transmission_timestamp = hdr->timestamp;
|
||||
}
|
||||
if (*prev_eot) {
|
||||
previous_end_of_transmission_timestamp = *prev_eot;
|
||||
} else {
|
||||
previous_end_of_transmission_timestamp = hdr->timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
end_of_transmission_timestamp = hdr->timestamp + duration;
|
||||
|
@ -355,7 +355,7 @@ static uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *tr
|
|||
|
||||
if (protocol == FELICA)
|
||||
annotateFelica(explanation, sizeof(explanation), frame, data_len);
|
||||
|
||||
|
||||
if (protocol == PROTO_HITAG1) {
|
||||
annotateHitag1(explanation, sizeof(explanation), frame, data_len, hdr->isResponse);
|
||||
}
|
||||
|
@ -405,38 +405,38 @@ static uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *tr
|
|||
if (j == 0) {
|
||||
|
||||
uint32_t time1 = hdr->timestamp - first_hdr->timestamp;
|
||||
uint32_t time2 = end_of_transmission_timestamp - first_hdr->timestamp;
|
||||
if (prev_eot) {
|
||||
time1 = hdr->timestamp - previous_end_of_transmission_timestamp;
|
||||
time2 = duration;
|
||||
}
|
||||
uint32_t time2 = end_of_transmission_timestamp - first_hdr->timestamp;
|
||||
if (prev_eot) {
|
||||
time1 = hdr->timestamp - previous_end_of_transmission_timestamp;
|
||||
time2 = duration;
|
||||
}
|
||||
|
||||
if (use_us) {
|
||||
PrintAndLogEx(NORMAL, " %10.1f | %10.1f | %s |%-72s | %s| %s",
|
||||
(float)time1/13.56,
|
||||
(float)time2/13.56,
|
||||
(hdr->isResponse ? "Tag" : _YELLOW_("Rdr")),
|
||||
line[j],
|
||||
(j == num_lines - 1) ? crc : " ",
|
||||
(j == num_lines - 1) ? explanation : ""
|
||||
);
|
||||
(float)time1 / 13.56,
|
||||
(float)time2 / 13.56,
|
||||
(hdr->isResponse ? "Tag" : _YELLOW_("Rdr")),
|
||||
line[j],
|
||||
(j == num_lines - 1) ? crc : " ",
|
||||
(j == num_lines - 1) ? explanation : ""
|
||||
);
|
||||
} else {
|
||||
PrintAndLogEx(NORMAL, " %10u | %10u | %s |%-72s | %s| %s",
|
||||
(hdr->timestamp - first_hdr->timestamp),
|
||||
(end_of_transmission_timestamp - first_hdr->timestamp),
|
||||
(hdr->isResponse ? "Tag" : _YELLOW_("Rdr")),
|
||||
line[j],
|
||||
(j == num_lines - 1) ? crc : " ",
|
||||
(j == num_lines - 1) ? explanation : ""
|
||||
);
|
||||
(hdr->timestamp - first_hdr->timestamp),
|
||||
(end_of_transmission_timestamp - first_hdr->timestamp),
|
||||
(hdr->isResponse ? "Tag" : _YELLOW_("Rdr")),
|
||||
line[j],
|
||||
(j == num_lines - 1) ? crc : " ",
|
||||
(j == num_lines - 1) ? explanation : ""
|
||||
);
|
||||
}
|
||||
|
||||
} else {
|
||||
PrintAndLogEx(NORMAL, " | | |%-72s | %s| %s",
|
||||
line[j],
|
||||
(j == num_lines - 1) ? crc : " ",
|
||||
(j == num_lines - 1) ? explanation : ""
|
||||
);
|
||||
line[j],
|
||||
(j == num_lines - 1) ? crc : " ",
|
||||
(j == num_lines - 1) ? explanation : ""
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -683,11 +683,11 @@ int CmdTraceList(const char *Cmd) {
|
|||
}
|
||||
} else {
|
||||
|
||||
if (use_relative) {
|
||||
if (use_relative) {
|
||||
PrintAndLogEx(INFO, _YELLOW_("gap") " = time between transfers. " _YELLOW_("duration") " = duration of data transfer. " _YELLOW_("src") " = source of transfer");
|
||||
} else {
|
||||
} else {
|
||||
PrintAndLogEx(INFO, _YELLOW_("start") " = start of start frame " _YELLOW_("end") " = end of frame. " _YELLOW_("src") " = source of transfer");
|
||||
}
|
||||
}
|
||||
|
||||
if (protocol == ISO_14443A || protocol == PROTO_MIFARE || protocol == MFDES || protocol == TOPAZ || protocol == LTO) {
|
||||
if (use_us)
|
||||
|
@ -736,9 +736,9 @@ int CmdTraceList(const char *Cmd) {
|
|||
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
if (use_relative) {
|
||||
PrintAndLogEx(NORMAL, " Gap | Duration | Src | Data (! denotes parity error, ' denotes short bytes) | CRC | Annotation");
|
||||
} else {
|
||||
if (use_relative) {
|
||||
PrintAndLogEx(NORMAL, " Gap | Duration | Src | Data (! denotes parity error, ' denotes short bytes) | CRC | Annotation");
|
||||
} else {
|
||||
PrintAndLogEx(NORMAL, " Start | End | Src | Data (! denotes parity error) | CRC | Annotation");
|
||||
}
|
||||
PrintAndLogEx(NORMAL, "------------+------------+-----+-------------------------------------------------------------------------+-----+--------------------");
|
||||
|
|
|
@ -497,7 +497,7 @@ int NDEFDecodeAndPrint(uint8_t *ndef, size_t ndefLen, bool verbose) {
|
|||
uint16_t len = ndefTLVGetLength(&ndef[indx], &indx);
|
||||
PrintAndLogEx(SUCCESS, "--- " _CYAN_("NDEF Message") " ---");
|
||||
if (len == 0) {
|
||||
PrintAndLogEx(SUCCESS, "Found NDEF message w zero length");
|
||||
PrintAndLogEx(SUCCESS, "Found NDEF message w zero length");
|
||||
} else {
|
||||
PrintAndLogEx(SUCCESS, "Found NDEF message (%d bytes)", len);
|
||||
|
||||
|
@ -505,7 +505,7 @@ int NDEFDecodeAndPrint(uint8_t *ndef, size_t ndefLen, bool verbose) {
|
|||
if (res != PM3_SUCCESS)
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
indx += len;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -909,7 +909,7 @@ static int CmdPrefShow(const char *Cmd) {
|
|||
if (session.preferences_loaded) {
|
||||
char *fn = prefGetFilename();
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "Using "_YELLOW_("%s"), fn);
|
||||
PrintAndLogEx(INFO, "Using "_YELLOW_("%s"), fn);
|
||||
free(fn);
|
||||
} else {
|
||||
PrintAndLogEx(ERR, "Preferences not loaded");
|
||||
|
|
|
@ -100,8 +100,8 @@ uint8_t GetPinSize(uint8_t *src) {
|
|||
uint8_t c[] = {0x96, CARD_INS_PINSIZE, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
memcpy(c + 5, src, 8);
|
||||
ExchangeAPDUSC(true, c, sizeof(c), false, true, resp, sizeof(resp), &resp_len);
|
||||
|
||||
if ( resp[resp_len - 2] == 0x90 && resp[resp_len - 1] == 0x00) {
|
||||
|
||||
if (resp[resp_len - 2] == 0x90 && resp[resp_len - 1] == 0x00) {
|
||||
return resp[8];
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -68,7 +68,7 @@ uint8_t reflect8(uint8_t b) {
|
|||
}
|
||||
|
||||
|
||||
// Reverse the bits in a byte with 4 operations (64-bit multiply, no division):
|
||||
// Reverse the bits in a byte with 4 operations (64-bit multiply, no division):
|
||||
/*
|
||||
uint8_t reflect8(uint8_t b) {
|
||||
return ((b * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32;
|
||||
|
|
|
@ -207,7 +207,7 @@ hi_get_trace gt(
|
|||
// 110 -- unused
|
||||
// 111 -- FPGA_MAJOR_MODE_OFF
|
||||
|
||||
// 000 001 010 011 100 101 110 111
|
||||
// 000 001 010 011 100 101 110 111
|
||||
mux8 mux_ssp_clk (major_mode, ssp_clk, hr_ssp_clk, hs_ssp_clk, 1'b0, he_ssp_clk, hfl_ssp_clk, gt_ssp_clk, 1'b0, 1'b0);
|
||||
mux8 mux_ssp_din (major_mode, ssp_din, hr_ssp_din, hs_ssp_din, 1'b0, he_ssp_din, hfl_ssp_din, gt_ssp_din, 1'b0, 1'b0);
|
||||
mux8 mux_ssp_frame (major_mode, ssp_frame, hr_ssp_frame, hs_ssp_frame, 1'b0, he_ssp_frame, hfl_ssp_frame, gt_ssp_frame, 1'b0, 1'b0);
|
||||
|
|
|
@ -219,7 +219,7 @@ hi_get_trace gt(
|
|||
// 110 -- unused
|
||||
// 111 -- FPGA_MAJOR_MODE_OFF
|
||||
|
||||
// 000 001 010 011 100 101 110 111
|
||||
// 000 001 010 011 100 101 110 111
|
||||
|
||||
mux8 mux_ssp_clk (major_mode, ssp_clk, hr_ssp_clk, hs_ssp_clk, hisn_ssp_clk, he_ssp_clk, hfl_ssp_clk, gt_ssp_clk, 1'b0, 1'b0);
|
||||
mux8 mux_ssp_din (major_mode, ssp_din, hr_ssp_din, hs_ssp_din, hisn_ssp_din, he_ssp_din, hfl_ssp_din, gt_ssp_din, 1'b0, 1'b0);
|
||||
|
|
|
@ -176,7 +176,7 @@ reg [3:0] mod_detect_reset_time;
|
|||
|
||||
always @(negedge adc_clk)
|
||||
begin
|
||||
if (mod_type == `FPGA_HF_ISO14443A_READER_LISTEN)
|
||||
if (mod_type == `FPGA_HF_ISO14443A_READER_LISTEN)
|
||||
// (our) reader signal changes at negedge_cnt[3:0]=9, tag response expected to start n*16+4 ticks later, further delayed by
|
||||
// 3 ticks ADC conversion. The maximum filter output (edge detected) will be detected after subcarrier zero crossing (+7 ticks).
|
||||
// To allow some timing variances, we want to have the maximum filter outputs well within the detection window, i.e.
|
||||
|
@ -516,7 +516,7 @@ begin
|
|||
if(negedge_cnt[3:0] == 4'd0)
|
||||
begin
|
||||
// What do we communicate to the ARM
|
||||
if(mod_type == `FPGA_HF_ISO14443A_TAGSIM_LISTEN)
|
||||
if(mod_type == `FPGA_HF_ISO14443A_TAGSIM_LISTEN)
|
||||
sendbit = after_hysteresis;
|
||||
else if(mod_type == `FPGA_HF_ISO14443A_TAGSIM_MOD)
|
||||
/* if(fdt_counter > 11'd772) sendbit = mod_sig_coil; // huh?
|
||||
|
@ -550,7 +550,7 @@ wire sub_carrier;
|
|||
assign sub_carrier = ~sub_carrier_cnt[3];
|
||||
|
||||
// in FPGA_HF_ISO14443A_READER_MOD: drop carrier for mod_sig_coil==1 (pause); in FPGA_HF_ISO14443A_READER_LISTEN: carrier always on; in other modes: carrier always off
|
||||
assign pwr_hi = (ck_1356meg & (((mod_type == `FPGA_HF_ISO14443A_READER_MOD) & ~mod_sig_coil) || (mod_type == `FPGA_HF_ISO14443A_READER_LISTEN)));
|
||||
assign pwr_hi = (ck_1356meg & (((mod_type == `FPGA_HF_ISO14443A_READER_MOD) & ~mod_sig_coil) || (mod_type == `FPGA_HF_ISO14443A_READER_LISTEN)));
|
||||
|
||||
|
||||
// Enable HF antenna drivers:
|
||||
|
|
|
@ -59,7 +59,7 @@ reg [5:0] corr_i_cnt;
|
|||
always @(negedge adc_clk)
|
||||
begin
|
||||
corr_i_cnt <= corr_i_cnt + 1;
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
// A couple of registers in which to accumulate the correlations. From the 64 samples
|
||||
|
@ -67,7 +67,7 @@ end
|
|||
// be safe to assume that a tag will not be able to modulate the carrier signal by more than 25%.
|
||||
// 32 * 255 * 0,25 = 2040, which can be held in 11 bits. Add 1 bit for sign.
|
||||
// Temporary we might need more bits. For the 212kHz subcarrier we could possible add 32 times the
|
||||
// maximum signal value before a first subtraction would occur. 32 * 255 = 8160 can be held in 13 bits.
|
||||
// maximum signal value before a first subtraction would occur. 32 * 255 = 8160 can be held in 13 bits.
|
||||
// Add one bit for sign -> need 14 bit registers but final result will fit into 12 bits.
|
||||
reg signed [13:0] corr_i_accum;
|
||||
reg signed [13:0] corr_q_accum;
|
||||
|
@ -87,12 +87,12 @@ begin
|
|||
abs_ci <= corr_i_accum;
|
||||
else
|
||||
abs_ci <= -corr_i_accum;
|
||||
|
||||
|
||||
if (corr_q_accum[13] == 1'b0)
|
||||
abs_cq <= corr_q_accum;
|
||||
else
|
||||
abs_cq <= -corr_q_accum;
|
||||
|
||||
|
||||
if (abs_ci > abs_cq)
|
||||
begin
|
||||
max_ci_cq <= abs_ci;
|
||||
|
@ -120,7 +120,7 @@ begin
|
|||
subcarrier_I = ~corr_i_cnt[3];
|
||||
subcarrier_Q = ~(corr_i_cnt[3] ^ corr_i_cnt[2]);
|
||||
end
|
||||
else if (subcarrier_frequency == `FPGA_HF_READER_SUBCARRIER_212_KHZ)
|
||||
else if (subcarrier_frequency == `FPGA_HF_READER_SUBCARRIER_212_KHZ)
|
||||
begin
|
||||
subcarrier_I = ~corr_i_cnt[5];
|
||||
subcarrier_Q = ~(corr_i_cnt[5] ^ corr_i_cnt[4]);
|
||||
|
@ -146,12 +146,12 @@ begin
|
|||
// send amplitude plus 2 bits reader signal
|
||||
corr_i_out <= corr_amplitude[13:6];
|
||||
corr_q_out <= {corr_amplitude[5:0], after_hysteresis_prev_prev, after_hysteresis_prev};
|
||||
end
|
||||
end
|
||||
else if (minor_mode == `FPGA_HF_READER_MODE_SNIFF_IQ)
|
||||
begin
|
||||
|
||||
// Send 7 most significant bits of in phase tag signal (signed), plus 1 bit reader signal
|
||||
if (corr_i_accum[13:11] == 3'b000 || corr_i_accum[13:11] == 3'b111)
|
||||
if (corr_i_accum[13:11] == 3'b000 || corr_i_accum[13:11] == 3'b111)
|
||||
corr_i_out <= {corr_i_accum[11:5], after_hysteresis_prev_prev};
|
||||
else // truncate to maximum value
|
||||
if (corr_i_accum[13] == 1'b0)
|
||||
|
@ -160,7 +160,7 @@ begin
|
|||
corr_i_out <= {7'b1000000, after_hysteresis_prev_prev};
|
||||
|
||||
// Send 7 most significant bits of quadrature phase tag signal (signed), plus 1 bit reader signal
|
||||
if (corr_q_accum[13:11] == 3'b000 || corr_q_accum[13:11] == 3'b111)
|
||||
if (corr_q_accum[13:11] == 3'b000 || corr_q_accum[13:11] == 3'b111)
|
||||
corr_q_out <= {corr_q_accum[11:5], after_hysteresis_prev};
|
||||
else // truncate to maximum value
|
||||
if (corr_q_accum[13] == 1'b0)
|
||||
|
@ -173,12 +173,12 @@ begin
|
|||
// send amplitude
|
||||
corr_i_out <= {2'b00, corr_amplitude[13:8]};
|
||||
corr_q_out <= corr_amplitude[7:0];
|
||||
end
|
||||
end
|
||||
else if (minor_mode == `FPGA_HF_READER_MODE_RECEIVE_IQ)
|
||||
begin
|
||||
|
||||
// Send 8 bits of in phase tag signal
|
||||
if (corr_i_accum[13:11] == 3'b000 || corr_i_accum[13:11] == 3'b111)
|
||||
if (corr_i_accum[13:11] == 3'b000 || corr_i_accum[13:11] == 3'b111)
|
||||
corr_i_out <= corr_i_accum[11:4];
|
||||
else // truncate to maximum value
|
||||
if (corr_i_accum[13] == 1'b0)
|
||||
|
@ -187,7 +187,7 @@ begin
|
|||
corr_i_out <= 8'b10000000;
|
||||
|
||||
// Send 8 bits of quadrature phase tag signal
|
||||
if (corr_q_accum[13:11] == 3'b000 || corr_q_accum[13:11] == 3'b111)
|
||||
if (corr_q_accum[13:11] == 3'b000 || corr_q_accum[13:11] == 3'b111)
|
||||
corr_q_out <= corr_q_accum[11:4];
|
||||
else // truncate to maximum value
|
||||
if (corr_q_accum[13] == 1'b0)
|
||||
|
@ -199,7 +199,7 @@ begin
|
|||
// for each Q/I pair report two reader signal samples when sniffing. Store the 1st.
|
||||
after_hysteresis_prev_prev <= after_hysteresis;
|
||||
|
||||
// Initialize next correlation.
|
||||
// Initialize next correlation.
|
||||
// Both I and Q reference signals are high when corr_i_nct == 0. Therefore need to accumulate.
|
||||
corr_i_accum <= $signed({1'b0, adc_d});
|
||||
corr_q_accum <= $signed({1'b0, adc_d});
|
||||
|
@ -223,7 +223,7 @@ begin
|
|||
|
||||
// Then the result from last time is serialized and send out to the ARM.
|
||||
// We get one report each cycle, and each report is 16 bits, so the
|
||||
// ssp_clk should be the adc_clk divided by 64/16 = 4.
|
||||
// ssp_clk should be the adc_clk divided by 64/16 = 4.
|
||||
// ssp_clk frequency = 13,56MHz / 4 = 3.39MHz
|
||||
|
||||
if (corr_i_cnt[1:0] == 2'b00)
|
||||
|
@ -307,7 +307,7 @@ begin
|
|||
pwr_hi = ck_1356meg & jam_signal;
|
||||
pwr_oe4 = 1'b0;
|
||||
end
|
||||
else if (minor_mode == `FPGA_HF_READER_MODE_SNIFF_IQ
|
||||
else if (minor_mode == `FPGA_HF_READER_MODE_SNIFF_IQ
|
||||
|| minor_mode == `FPGA_HF_READER_MODE_SNIFF_AMPLITUDE
|
||||
|| minor_mode == `FPGA_HF_READER_MODE_SNIFF_PHASE)
|
||||
begin // all off
|
||||
|
@ -319,7 +319,7 @@ begin
|
|||
pwr_hi = ck_1356meg;
|
||||
pwr_oe4 = 1'b0;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
// always on
|
||||
assign pwr_oe1 = 1'b0;
|
||||
|
|
|
@ -42,7 +42,7 @@ assign pwr_lo = 1'b0; // LF antenna connected to GND
|
|||
assign pwr_oe2 = 1'b0;
|
||||
|
||||
assign adc_clk = ck_1356meg;
|
||||
assign dbg = ssp_frame;
|
||||
assign dbg = ssp_frame;
|
||||
|
||||
// The comparator with hysteresis on the output from the peak detector.
|
||||
reg after_hysteresis;
|
||||
|
@ -67,7 +67,7 @@ begin
|
|||
else
|
||||
begin
|
||||
has_been_low_for <= has_been_low_for + 1;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -95,7 +95,7 @@ begin
|
|||
end
|
||||
|
||||
|
||||
// Produce the byte framing signal; the phase of this signal
|
||||
// Produce the byte framing signal; the phase of this signal
|
||||
// is arbitrary, because it's just a bit stream in this module.
|
||||
reg ssp_frame;
|
||||
always @(negedge adc_clk)
|
||||
|
|
|
@ -51,7 +51,7 @@ static int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile) {
|
|||
fprintf(stderr,
|
||||
"Input files too big (total > %li bytes). These are probably not PM3 FPGA config files.\n"
|
||||
, num_infiles * FPGA_CONFIG_SIZE
|
||||
);
|
||||
);
|
||||
|
||||
for (uint16_t j = 0; j < num_infiles; j++) {
|
||||
fclose(infile[j]);
|
||||
|
|
|
@ -702,4 +702,4 @@ D232A3D1
|
|||
7F8185C6
|
||||
00000000
|
||||
00000000
|
||||
00000000
|
||||
00000000
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue