The procedure of Mifare Classic 1K is
- Polling for tags
- Authenticate those tags
- If authentication succeded then read/write.
I already completed those procedures and also read and write data from specific sectors.
Command for Polling for tags is
new byte[] { (byte) 0xFF, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x04, (byte) 0xD4, (byte) 0x4A,
(byte) 0x01, (byte) 0x00 }
Authentication command is
new byte[] { (byte) 0xFF, (byte) 0x86, (byte) 0x00,
(byte) 0x00, (byte) 0x05, (byte) 0x01,(byte) 0x00, (byte) 0x04,
(byte) 0x60,(byte) 0x00 };
Here "(byte) 0x01" is the Sector 1
And Write on Sector 1, block 5 is
new byte[] { (byte) 0xFF, (byte) 0x00, (byte) 0x00,(byte) 0x00, (byte) 0x15, (byte) 0xD4,
(byte) 0x40,(byte) 0x01, (byte) 0xA0, (byte) 0x05,(byte) 0x01, (byte) 0x02,
(byte) 0x03,(byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07,(byte) 0x08,
(byte) 0x09,(byte) 0x0A,(byte) 0x0B, (byte) 0x0C, (byte) 0x0D,(byte) 0x0E,
(byte) 0x0F, (byte) 0x10};
Here
(byte) 0x01, (byte) 0x02, (byte) 0x03,(byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07,(byte) 0x08,(byte) 0x09,(byte) 0x0A,(byte) 0x0B, (byte) 0x0C, (byte) 0x0D,(byte) 0x0E,(byte) 0x0F,(byte) 0x10
is data those are writing on block 5 on Sector 1.
Read From Sector 1 and Block 5 Command is
new byte[] { (byte) 0xFF, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x05, (byte) 0xD4, (byte) 0x40,
(byte) 0x01, (byte) 0x30, (byte) 0x05 };
My Related Complete Code is here...
My Problem is how can I "Lock/make read only" a block from a specific sector?
The authentication keys and the access conditions for each sector of a MIFARE card are located in the last block of that sector (the sector trailer). You can update this block with new access conditions and authentication keys using a regular write command.
The sector trailer looks like this:
So the access bits are located in byte 6-8 and look like this:
Where nCx_y = not Cx_y and "C1_x, C2_x, C3_x" is the access condition for block x:
You can find a detailed list of possible access conditions in the MIFARE 1K datasheet: http://www.nxp.com/documents/data_sheet/MF1S503x.pdf