Reputation: 9
I am working with NFC Android programming and I want to read Mifare Classic cards. Does anybody know how to read the sectors off such a card?
My problem is the transceive()
method. I don't know how to use it to read a sector
for example to read sector 1.
Authentication method returns true which means that authentication is done. After authentication, sector should be ready for any IO action but whenever i use readBlock() method or transceive() method, I get exception with IOException("transceive failed"). I can not find any example which uses the Mifare Classic, so i want to know if it is possible to read the Mifare Classic with this API or not.
Kind Regards.
Upvotes: 0
Views: 11829
Reputation: 981
It is for sure possible to read Mifare Classic with this API - we have applications that do it.
You shouldn't need to use transceive()
directly if you just want to read the card - just use the readBlock()
convenience method.
A common pitfall is that authentication is done on the sector level, whereas reading is done on a block level. On Mifare Classic, a sector is comprised of several blocks. Unfortunately, the number of blocks per sector may vary, even on the same card.
Use MifareClassic.sectorToBlock(sector)
to retrieve the first starting block of the sector that you authenticated for. Then, you may read all blocks of that sector. The number of blocks in a sector can be retrieved with MifareClassic.getBlockCountInSector(sector)
.
If it still doesn't work, can you post some code?
Upvotes: 9