4

I have successfully written some data on data pages 30 to 38.

After that I want to lock those pages in order to prevent further writing. The write lock should be permanent, so even if someone knows the authentication key, they should not be able to write to those pages.

As far as I have understood the datasheet, I have to write some bits on OTP pages. But I do not fully understand what command I have to send for locking specifically pages 30 to 38.

Can somebody help me in identifying the command that needs to be sent to the card? My thinking is that I have to write F0 on page 40. However, this might also make pages 28, 29 and 39 locked and, hence, unusable.

Michael Roland
  • 39,663
  • 10
  • 99
  • 206
Kamran Shahid
  • 3,954
  • 5
  • 48
  • 93

1 Answers1

4

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.

Michael Roland
  • 39,663
  • 10
  • 99
  • 206
  • Thanks Michael. Can you please tell what's the use of bit 4of byte 0 of page 40. Document says it is for BLOCK LOCKING PAGES 29 - 39 That's why I were thinking of setting bit 4,5,6,7 [which results in F0] – Kamran Shahid May 08 '15 at 12:01
  • Michael Manual says. "Once the block-locking bits are set, the locking configuration for the corresponding memory area is frozen." could you please help me in it – Kamran Shahid May 08 '15 at 12:17
  • Any comments Michael about block locking bit. Should i set it to true or not? – Kamran Shahid May 09 '15 at 09:10
  • 1
    See my edit. That depends on what you want to achieve. – Michael Roland May 09 '15 at 09:13
  • Thanks Michael. I have the case where i have to block sequential pages from 30 to 38 (in real 28 to 39 because of the supported configuration) Hence it mean's setting E0 or F0 doesn't made too much difference. I might go with F0. Thanks a lot – Kamran Shahid May 09 '15 at 10:35