make style
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user