mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-07-05 20:41:34 -07:00
improve cardhopper to improve reliability when parts of the packet are buffered
This commit is contained in:
parent
5057f1a684
commit
df5e2ce05b
3 changed files with 27 additions and 6 deletions
|
@ -33,7 +33,10 @@
|
|||
#ifdef CARDHOPPER_USB
|
||||
#define cardhopper_write usb_write
|
||||
#define cardhopper_read usb_read_ng
|
||||
#define cardhopper_data_available usb_poll_validate_length
|
||||
bool cardhopper_data_available(void);
|
||||
bool cardhopper_data_available(void) {
|
||||
return usb_read_ng_has_buffered_data() || usb_poll_validate_length();
|
||||
}
|
||||
#else
|
||||
#define cardhopper_write usart_writebuffer_sync
|
||||
#define cardhopper_read usart_read_ng
|
||||
|
@ -107,14 +110,22 @@ void RunMod(void) {
|
|||
break;
|
||||
}
|
||||
|
||||
if (memcmp(magicREAD, modeRx.dat, sizeof(magicREAD)) == 0) {
|
||||
if (modeRx.len == 0) {
|
||||
DbpString(_CYAN_("[@]") " Zero length message");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (modeRx.len == sizeof(magicREAD) && memcmp(magicREAD, modeRx.dat, sizeof(magicREAD)) == 0) {
|
||||
DbpString(_CYAN_("[@]") " I am a READER. I talk to a CARD.");
|
||||
become_reader();
|
||||
} else if (memcmp(magicCARD, modeRx.dat, sizeof(magicCARD)) == 0) {
|
||||
} else if (modeRx.len == sizeof(magicCARD) && memcmp(magicCARD, modeRx.dat, sizeof(magicCARD)) == 0) {
|
||||
DbpString(_CYAN_("[@]") " I am a CARD. I talk to a READER.");
|
||||
become_card();
|
||||
} else if (memcmp(magicEND, modeRx.dat, sizeof(magicEND)) == 0) {
|
||||
} else if (modeRx.len == sizeof(magicEND) && memcmp(magicEND, modeRx.dat, sizeof(magicEND)) == 0) {
|
||||
break;
|
||||
} else if (modeRx.len == sizeof(magicRSRT) && memcmp(magicRSRT, modeRx.dat, sizeof(magicRSRT)) == 0) {
|
||||
DbpString(_CYAN_("[@]") " Got RESET but already reset.");
|
||||
continue;
|
||||
} else {
|
||||
DbpString(_YELLOW_("[!]") " unknown mode!");
|
||||
Dbhexdump(modeRx.len, modeRx.dat, true);
|
||||
|
@ -142,7 +153,12 @@ static void become_reader(void) {
|
|||
WDT_HIT();
|
||||
|
||||
read_packet(rx);
|
||||
if (memcmp(magicRSRT, rx->dat, sizeof(magicRSRT)) == 0) break;
|
||||
if (rx->len == sizeof(magicRSRT) && memcmp(magicRSRT, rx->dat, sizeof(magicRSRT)) == 0) break;
|
||||
|
||||
if (BUTTON_PRESS()) {
|
||||
DbpString(_CYAN_("[@]") " Button pressed - Breaking from reader loop");
|
||||
break;
|
||||
}
|
||||
|
||||
if (rx->dat[0] == ISO14443A_CMD_RATS && rx->len == 4) {
|
||||
// got RATS from reader, reset the card
|
||||
|
@ -206,7 +222,7 @@ static void become_card(void) {
|
|||
iso14443a_setup(FPGA_HF_ISO14443A_TAGSIM_LISTEN);
|
||||
|
||||
uint8_t tagType;
|
||||
uint16_t flags;
|
||||
uint16_t flags = 0;
|
||||
uint8_t data[PM3_CMD_DATA_SIZE] = { 0 };
|
||||
packet_t ats = { 0 };
|
||||
prepare_emulation(&tagType, &flags, data, &ats);
|
||||
|
|
|
@ -718,6 +718,10 @@ static uint8_t usb_read_ng_buffer[64] = {0};
|
|||
static uint8_t usb_read_ng_bufoffset = 0;
|
||||
static uint8_t usb_read_ng_buflen = 0;
|
||||
|
||||
bool usb_read_ng_has_buffered_data(void) {
|
||||
return usb_read_ng_buflen > 0;
|
||||
}
|
||||
|
||||
uint32_t usb_read_ng(uint8_t *data, size_t len) {
|
||||
|
||||
if (len == 0) {
|
||||
|
|
|
@ -39,6 +39,7 @@ int async_usb_write_start(void);
|
|||
void async_usb_write_pushByte(uint8_t data);
|
||||
bool async_usb_write_requestWrite(void);
|
||||
int async_usb_write_stop(void);
|
||||
bool usb_read_ng_has_buffered_data(void);
|
||||
uint32_t usb_read_ng(uint8_t *data, size_t len);
|
||||
void usb_update_serial(uint64_t newSerialNumber);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue