1
votes

I am trying to read blocks with mifare classic card 1k and android nfc (on galaxy nexus).

private final int mMaxSize = 64;

mClassic.connect();

boolean success = mClassic.authenticateSectorWithKeyA(1, MifareClassic.KEY_DEFAULT );
final ByteArrayBuffer b = new ByteArrayBuffer(mMaxSize);

if (success)
{   
    b.append(mClassic.readBlock(0), 0, 16);
    b.append(mClassic.readBlock(1), 0, 16);
    b.append(mClassic.readBlock(2), 0, 16);
    b.append(mClassic.readBlock(3), 0, 16);
}

If I want to read sector 0, that's all ok. But if I want to read a different sector (for example sector 1), success has true value, but when the app go to readBlock(), an IOException is triggered and I have returned tranceiver failed.

What I am doing wrong?

2
did you try the following link mifareclassicdetectiononandroid.blogspot.inblganesh101

2 Answers

0
votes

In your code example you're authenticating for sector 1 but then try to read blocks from sector 0. Remember sector and block numbers are zero-based. You may also be interested in blockToSector(int block).

0
votes

you should

b.append(mClassic.readBlock(4), 0, 16);
b.append(mClassic.readBlock(5), 0, 16);
b.append(mClassic.readBlock(6), 0, 16);
b.append(mClassic.readBlock(7), 0, 16);