chg: 'hf iclass' generically, check button press fewer times to not interupt time critical parts too much

This commit is contained in:
iceman1001 2019-08-04 18:31:52 +02:00
commit 2cc24c8714

View file

@ -884,9 +884,17 @@ void RAMFUNC SniffIClass(void) {
// contains LOW nibble = tag data // contains LOW nibble = tag data
// so two bytes are needed in order to get 1byte of either reader or tag data. (ie 2 sample bytes) // so two bytes are needed in order to get 1byte of either reader or tag data. (ie 2 sample bytes)
// since reader data is manchester encoded, we need 2bytes of data in order to get one demoded byte. (ie: 4 sample bytes) // since reader data is manchester encoded, we need 2bytes of data in order to get one demoded byte. (ie: 4 sample bytes)
while (!BUTTON_PRESS()) { uint16_t checked = 0;
for (;;) {
WDT_HIT(); WDT_HIT();
if ( checked == 1000 ) {
if (BUTTON_PRESS() || data_available() ) break;
checked = 0;
} else {
checked++;
}
previous_data <<= 8; previous_data <<= 8;
previous_data |= *data; previous_data |= *data;
@ -996,9 +1004,18 @@ static bool GetIClassCommandFromReader(uint8_t *received, int *len, int maxLen)
uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR; uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
(void)b; (void)b;
while (!BUTTON_PRESS()) { uint16_t checked = 0;
for (;;) {
WDT_HIT(); WDT_HIT();
if ( checked == 1000 ) {
if( BUTTON_PRESS() || data_available() ) return false;
checked = 0;
} else {
checked++;
}
// keep tx buffer in a defined state anyway. // keep tx buffer in a defined state anyway.
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY))
AT91C_BASE_SSC->SSC_THR = 0x00; AT91C_BASE_SSC->SSC_THR = 0x00;
@ -1645,8 +1662,15 @@ static int SendIClassAnswer(uint8_t *resp, int respLen, uint16_t delay) {
AT91C_BASE_SSC->SSC_THR = 0x00; AT91C_BASE_SSC->SSC_THR = 0x00;
while (!BUTTON_PRESS()) { uint16_t checked = 0;
for (;;) {
if ( checked == 1000 ) {
if ( BUTTON_PRESS() || data_available()) return 0;
checked = 0;
} else {
checked++;
}
// Prevent rx holding register from overflowing // Prevent rx holding register from overflowing
if ((AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY)) { if ((AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY)) {
b = AT91C_BASE_SSC->SSC_RHR; b = AT91C_BASE_SSC->SSC_RHR;
@ -1813,9 +1837,18 @@ static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples,
uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR; uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
(void)b; (void)b;
while (!BUTTON_PRESS()) { uint16_t checked = 0;
for (;;) {
WDT_HIT(); WDT_HIT();
if ( checked == 1000 ) {
if (BUTTON_PRESS() || data_available()) return false;
checked = 0;
} else {
checked++;
}
// keep tx buffer in a defined state anyway. // keep tx buffer in a defined state anyway.
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) { if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
AT91C_BASE_SSC->SSC_THR = 0x00; AT91C_BASE_SSC->SSC_THR = 0x00;
@ -2006,6 +2039,7 @@ void ReaderIClass(uint8_t arg0) {
setupIclassReader(); setupIclassReader();
uint16_t checked = 0;
bool userCancelled = BUTTON_PRESS() || data_available(); bool userCancelled = BUTTON_PRESS() || data_available();
while (!userCancelled) { while (!userCancelled) {
@ -2105,7 +2139,13 @@ void ReaderIClass(uint8_t arg0) {
} }
} }
LED_B_OFF(); LED_B_OFF();
if ( checked == 1000 ) {
userCancelled = BUTTON_PRESS() || data_available(); userCancelled = BUTTON_PRESS() || data_available();
checked = 0;
} else {
checked++;
}
} }
if (userCancelled) { if (userCancelled) {
@ -2299,11 +2339,17 @@ void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain) {
setupIclassReader(); setupIclassReader();
uint16_t checked = 0;
int read_status = 0; int read_status = 0;
uint8_t startup_limit = 10; uint8_t startup_limit = 10;
while (read_status != 2) { while (read_status != 2) {
if (BUTTON_PRESS() && !data_available()) goto out; if ( checked == 1000 ) {
if (BUTTON_PRESS() || !data_available()) goto out;
checked = 0;
} else {
checked++;
}
read_status = handshakeIclassTag_ext(card_data, use_credit_key); read_status = handshakeIclassTag_ext(card_data, use_credit_key);
if (startup_limit-- == 0) { if (startup_limit-- == 0) {
@ -2318,7 +2364,12 @@ void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain) {
for (i = 0; i < keyCount; i++) { for (i = 0; i < keyCount; i++) {
// Allow button press / usb cmd to interrupt device // Allow button press / usb cmd to interrupt device
if (BUTTON_PRESS() && !data_available()) break; if ( checked == 1000 ) {
if (BUTTON_PRESS() || !data_available()) goto out;
checked = 0;
} else {
checked++;
}
WDT_HIT(); WDT_HIT();
LED_B_ON(); LED_B_ON();