diff --git a/Adafruit_PN532.cpp b/Adafruit_PN532.cpp index 5f5a67c..15c23f8 100644 --- a/Adafruit_PN532.cpp +++ b/Adafruit_PN532.cpp @@ -539,6 +539,41 @@ bool Adafruit_PN532::setPassiveActivationRetries(uint8_t maxRetries) { /***** ISO14443A Commands ******/ +/**************************************************************************/ +/*! + @brief Waits for an ISO14443A target to enter the field and reads + its ID. + + @param cardbaudrate Baud rate of the card + @param uid Pointer to the array that will be populated + with the card's UID (up to 7 bytes) + @param uidLength Pointer to the variable that will hold the + length of the card's UID. + @param atqa Pointer to the variable that will hold the + ATQA of the card + @param sak Pointer to the variable that will hold the + SAK of the card + @param timeout Timeout in milliseconds. + + @return 1 if everything executed properly, 0 for an error +*/ +/**************************************************************************/ +bool Adafruit_PN532::readPassiveTargetID(uint8_t cardbaudrate, uint8_t *uid, + uint8_t *uidLength, uint16_t *atqa, uint8_t *sak, uint16_t timeout) { + pn532_packetbuffer[0] = PN532_COMMAND_INLISTPASSIVETARGET; + pn532_packetbuffer[1] = 1; // max 1 cards at once (we can set this to 2 later) + pn532_packetbuffer[2] = cardbaudrate; + + if (!sendCommandCheckAck(pn532_packetbuffer, 3, timeout)) { +#ifdef PN532DEBUG + PN532DEBUGPRINT.println(F("No card(s) read")); +#endif + return 0x0; // no cards read + } + + return readDetectedPassiveTargetID(uid, uidLength, atqa, sak); +} + /**************************************************************************/ /*! @brief Waits for an ISO14443A target to enter the field and reads @@ -566,8 +601,10 @@ bool Adafruit_PN532::readPassiveTargetID(uint8_t cardbaudrate, uint8_t *uid, #endif return 0x0; // no cards read } + uint16_t atqa; + uint8_t sak; - return readDetectedPassiveTargetID(uid, uidLength); + return readDetectedPassiveTargetID(uid, uidLength, &atqa, &sak); } /**************************************************************************/ @@ -599,7 +636,7 @@ bool Adafruit_PN532::startPassiveTargetIDDetection(uint8_t cardbaudrate) { */ /**************************************************************************/ bool Adafruit_PN532::readDetectedPassiveTargetID(uint8_t *uid, - uint8_t *uidLength) { + uint8_t *uidLength, uint16_t *atqa, uint8_t *sak) { // read data packet readdata(pn532_packetbuffer, 20); // check some basic stuff @@ -624,9 +661,10 @@ bool Adafruit_PN532::readDetectedPassiveTargetID(uint8_t *uid, if (pn532_packetbuffer[7] != 1) return 0; - uint16_t sens_res = pn532_packetbuffer[9]; - sens_res <<= 8; - sens_res |= pn532_packetbuffer[10]; + *atqa = pn532_packetbuffer[9]; + *atqa <<= 8; + *atqa |= pn532_packetbuffer[10]; + *sak = pn532_packetbuffer[11]; #ifdef MIFAREDEBUG PN532DEBUGPRINT.print(F("ATQA: 0x")); PN532DEBUGPRINT.println(sens_res, HEX); diff --git a/Adafruit_PN532.h b/Adafruit_PN532.h index 593d711..239ab49 100644 --- a/Adafruit_PN532.h +++ b/Adafruit_PN532.h @@ -177,10 +177,11 @@ class Adafruit_PN532 { // ISO14443A functions bool readPassiveTargetID( - uint8_t cardbaudrate, uint8_t *uid, uint8_t *uidLength, + uint8_t cardbaudrate, uint8_t *uid, uint8_t *uidLength, uint16_t *atqa, uint8_t *sak, uint16_t timeout = 0); // timeout 0 means no timeout - will block forever. + bool readPassiveTargetID(uint8_t cardbaudrate, uint8_t *uid, uint8_t *uidLength, uint16_t timeout = 0); bool startPassiveTargetIDDetection(uint8_t cardbaudrate); - bool readDetectedPassiveTargetID(uint8_t *uid, uint8_t *uidLength); + bool readDetectedPassiveTargetID(uint8_t *uid, uint8_t *uidLength, uint16_t *atqa, uint8_t *sak); bool inDataExchange(uint8_t *send, uint8_t sendLength, uint8_t *response, uint8_t *responseLength); bool inListPassiveTarget();