Skip to content

Commit

Permalink
Break early if an RF error occurs. Significantly reduces the refracto…
Browse files Browse the repository at this point in the history
…ry period if a tag is removed prematurely
  • Loading branch information
henryk committed May 17, 2013
1 parent 7bb453d commit b905a0b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions libopenkey/libopenkey.c
Expand Up @@ -73,6 +73,11 @@ static const char * const PATH_SEPARATOR = "/";

#define ROLEMASK(x) (1<<(x))

/* Hack: libfreefare allows no direct access to the nfc_device. However, a pointer
* to it is the first member of the MifareTag structure, so a cast will do for now
*/
#define RFERROR(tag) (nfc_device_get_last_error(*(nfc_device**)tag) == NFC_ERFTRANS)

struct openkey_context {
uint8_t roles_initialized;

Expand Down Expand Up @@ -2387,6 +2392,8 @@ int openkey_authenticator_card_authenticate_pw(openkey_context_t ctx, MifareTag
if(r >= 0) {
retval = r;
goto abort;
} else if(RFERROR(tag)) {
break;
}
}
} else if(slot >= OPENKEY_SLOT_MIN && slot <= OPENKEY_SLOT_MAX) {
Expand All @@ -2399,6 +2406,8 @@ int openkey_authenticator_card_authenticate_pw(openkey_context_t ctx, MifareTag
if(r >= 0) {
retval = r;
goto abort;
} else if(RFERROR(tag)) {
break;
}
} else {
continue;
Expand Down

0 comments on commit b905a0b

Please sign in to comment.