How to permanently lock pages 30 to 38?
In order to set the lock-bits that include pages 30 to 38, you would need to set the lock-bits that are located in bits 5, 6, and 7 of byte 0 of page 40. You can do this with the WRITE command. For lock bits (or any OTP pages) this command will only program those bits that are set to '1' in the data parameter of the command (essentially resulting into a logical OR). Note that the WRITE command always takes one full page (i.e. 4 bytes) as its data parameter:
byte[] result = nfcA.transceive(new byte[] {
(byte)0xA2, /* CMD = WRITE */
(byte)0x28, /* PAGE = 40 */
(byte)0xE0, (byte)0x00, (byte)0x00, (byte)0x00 /* DATA = lock pages 28..39 */
});
But hey, I did not want to lock pages 28, 29, and 39! How can I only lock pages 30 to 38?
Unfortunately, you can't! The locking mechanism of MIFARE Ultralight C for pages 16 to 39 is organized in blocks of 4 pages. Hence, you can only lock the following groups of 4 pages:
- Pages 16..19
- Pages 20..23
- Pages 24..27
- Pages 28..31
- Pages 32..35
- Pages 36..39
What does the block locking bit do?
The block locking bit sets the write protection for bits within the lock page. So for instance if the block locking bit for pages 28 to 39 is set to '1', this means that you cannot change the state of the three lock-bits for these pages. Hence, if you set the lock-bit for pages 28 to 31 but leave the lock-bits for pages 32 to 35 and 36 to 39 unset, and then set the block locking bit, you can no longer activate the write protection for pages 32 to 39.