uint8_t PN532::mifareclassic_ReadDataBlock (uint8_t blockNumber, uint8_t *data) { DMSG("Trying to read 16 bytes from block "); DMSG_INT(blockNumber); /* Prepare the command */ pn532_packetbuffer[0] = PN532_COMMAND_INDATAEXCHANGE; pn532_packetbuffer[1] = 1; /* Card number */ pn532_packetbuffer[2] = MIFARE_CMD_READ; /* Mifare Read command = 0x30 */ pn532_packetbuffer[3] = blockNumber; /* Block Number (0..63 for 1K, 0..255 for 4K) */ /* Send the command */ if (HAL(writeCommand)(pn532_packetbuffer, 4)) { return 0; } /* Read the response packet */ HAL(readResponse)(pn532_packetbuffer, sizeof(pn532_packetbuffer)); /* If byte 8 isn't 0x00 we probably have an error */ if (pn532_packetbuffer[0] != 0x00) { return 0; } /* Copy the 16 data bytes to the output buffer */ /* Block content starts at byte 9 of a valid response */ memcpy (data, pn532_packetbuffer + 1, 16); return 1; }
NfcTag NfcAdapter::read() { uint8_t type = guessTagType(); // TODO need an abstraction of Driver if (type == TAG_TYPE_MIFARE_CLASSIC) { #ifdef NDEF_DEBUG DMSG("Reading Mifare Classic"); #endif MifareClassic mifareClassic = MifareClassic(*shield); return mifareClassic.read(uid, uidLength); } else if (type == TAG_TYPE_2) { #ifdef NDEF_DEBUG DMSG("Reading Mifare Ultralight"); #endif MifareUltralight ultralight = MifareUltralight(*shield); return ultralight.read(uid, uidLength); } else if (type == TAG_TYPE_UNKNOWN) { DMSG("Can not determine tag type"); //DMSG("Can not determine tag type for ATQA 0x"); //Serial.print(atqa, HEX);DMSG(" SAK 0x");DMSG(sak, HEX); return NfcTag(uid, uidLength); } else { DMSG("No driver for card type "); DMSG_INT(type); // TODO should set type here return NfcTag(uid, uidLength); } }