Permalink
Browse files

adding auth failed support

Auth failed was still returning 1 even in failure case, so changed it to return 0 now on fail.

Signed-off-by: Scott Gustafson <scott@garlicsoftware.com>
  • Loading branch information...
1 parent b2e590c commit bd041b4828c3b90ff9b95abbf98323eea534e68f @scott-42 scott-42 committed Mar 28, 2012
Showing with 11 additions and 5 deletions.
  1. +11 −5 Adafruit_PN532.cpp
View
@@ -526,11 +526,17 @@ uint8_t Adafruit_PN532::mifareclassic_AuthenticateBlock (uint8_t * uid, uint8_t
// Read the response packet
readspidata(pn532_packetbuffer, 12);
- // ToDo: How to check if the response is valid and we are authenticated???
- // #ifdef PN532DEBUG
- // Serial.println("Authentification failed%s");
- // #endif
- // return 0;
+ // check if the response is valid and we are authenticated???
+ // for an auth success it should be bytes 5-7: 0xD5 0x41 0x00
+ // Mifare auth error is technically byte 7: 0x14 but anything other and 0x00 is not good
+ if (pn532_packetbuffer[7] != 0x00)
+ {
+ #ifdef PN532DEBUG
+ Serial.print("Authentification failed: ");
+ Adafruit_PN532::PrintHexChar(pn532_packetbuffer, 12);
+ #endif
+ return 0;
+ }
return 1;
}

0 comments on commit bd041b4

Please sign in to comment.