byte PN532::mifare_WriteBlock(uint8_t blockNumber, uint8_t * data) { Serial.print("Try to write a block "); Serial.println(blockNumber); if (!InDataExchange(1, MIFARE_CMD_WRITE, blockNumber, data, 16)) { Serial.println("Failed to receive ACK for write command"); } byte c = getCommandResponse(packet); if (! c) { Serial.println("Unexpected response"); Serial.printBytes(packet, 26); Serial.println(); return 0; } Serial.print("Packet "); Serial.printBytes(packet, c); Serial.println(); if (packet[0] != 0) { // error. return 0; } memcpy(data, packet + 1, 16); Serial.print("data "); Serial.println(blockNumber); Serial.printBytes(data, 16); Serial.println(); return 16; }
byte PN532::getListPassiveTarget(byte * data) { byte count = getCommandResponse(packet); if (!count) return 0; // count -= 2; // remove checksum and postamble bytes. memcpy(data, packet, count); return packet[0]; }
byte PN532::getAutoPollResponse(byte * respo) { // byte cnt; if (!getCommandResponse(respo)) return 0; if (respo[0]) { switch (respo[1]) { case Type_FeliCa212kb: targetSet(respo[1], respo + 3 + 3, 8); break; case Type_Mifare: targetSet(respo[1], respo + 3 + 5, respo[3 + 4]); break; } } else { targetClear(); } return respo[0]; }
byte PN532::mifare_ReadDataBlock(uint8_t blockNumber, uint8_t * data) { #ifdef MIFAREDEBUG Serial.print("Try to read 16 bytes from block "); Serial.println(blockNumber); #endif // Access the Target 1 after polling by InList or AutoPoll // Authentication must be succeeded so the uid (and its length) is // stored in target.UID /* Send the command */ if (!InDataExchange(1, MIFARE_CMD_READ, blockNumber, packet, 0)) { #ifdef MIFAREDEBUG Serial.println("Failed to receive ACK for read command"); #endif } byte c = getCommandResponse(packet); if (!c ) { #ifdef MIFAREDEBUG Serial.println("Unexpected response"); printHexString(packet, 26); Serial.println(); #endif return 0; } //#define MIFAREDEBUG #ifdef MIFAREDEBUG Serial.print("Packet "); printHexString(packet, c); Serial.println(); #endif if (packet[0] != 0) { // error. return 0; } memcpy(data, packet + 1, 16); #ifdef MIFAREDEBUG Serial.print("data "); Serial.println(blockNumber); printHexString(data, 16); Serial.println(); #endif //#undef MIFAREDEBUG return 16; }
byte PN532::getCommunicateThruResponse(byte * data) { // InCommunicateThru(data, len); /* Read the response packet */ int count = getCommandResponse(packet); if (!count ) { return 0; } #ifdef FELICADEBUG Serial.print("Response: "); Serial.print("count = "); Serial.print(count, DEC); Serial.print(" "); printHexString(packet, count); Serial.println(); #endif if (packet[0] != 0) { return 0; } count = packet[1] - 1; memcpy(data, packet + 2, count); return count; }
byte PN532::getAutoPollResponse(void) { if (!getCommandResponse(packet)) { comm_status = RESP_FAILED; return 0; } comm_status = RESP_RECEIVED; // ignore the tag no. 2 or greater if ( packet[0] > 0 ) { // count // memcpy(respo, packet+3, packet[2]); // length switch (packet[1]) { // type case NFC::CARDTYPE_FELICA_212K: targetSet(NFC::CARDTYPE_FELICA_212K, packet+3+3, 8); //respo+3, 8); break; case NFC::CARDTYPE_MIFARE: targetSet(NFC::CARDTYPE_MIFARE, packet+3+5, packet[7]); //respo[4]); break; } } else { targetClear(); } return packet[2]; }