Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ntag2xx_WriteNDEFURI sets up incorrect Lock Control TLV #87

Open
vmsh0 opened this issue Feb 8, 2021 · 0 comments
Open

ntag2xx_WriteNDEFURI sets up incorrect Lock Control TLV #87

vmsh0 opened this issue Feb 8, 2021 · 0 comments

Comments

@vmsh0
Copy link

vmsh0 commented Feb 8, 2021

Hello,

The Adafruit_PN532::ntag2xx_WriteNDEFURI method writes an NDEF URI in a NTAG2xx tag. To do so, it completely reformats the user data memory area. This is how that's achieved:

  // Setup the record header
  // See NFCForum-TS-Type-2-Tag_1.1.pdf for details
  uint8_t pageHeader[12] = {
      /* NDEF Lock Control TLV (must be first and always present) */
      0x01, /* Tag Field (0x01 = Lock Control TLV) */
      0x03, /* Payload Length (always 3) */
      0xA0, /* The position inside the tag of the lock bytes (upper 4 = page
               address, lower 4 = byte offset) */
      0x10, /* Size in bits of the lock area */
      0x44, /* Size in bytes of a page and the number of bytes each lock bit can
               lock (4 bit + 4 bits) */
      /* NDEF Message TLV - URI Record */
      [ ... etc ... ]
  };

While reformatting the memory area, the method writes a Lock Control TLV.

There are two issues with this:

  1. The TLV, as hardcoded in the method, seems (i.e. as per back-of-the-envelope computation) to be completely wrong for all NTAG2xx platforms, and as it is hardcoded, it can ever be correct correct for at most a specific model of the platform series
  2. In contrast to what is suggested in the comment, the TVL block does not always have to be present; the NFC Forum standard for T2T platforms states (RQ_T2T_MEM_021): "The Lock Control TLV can be present inside the Type 2 Tag Platform." And in fact, in the case of NTAG2xx platforms, it is completely useless, as the user data area is contiguous and limited by the Capability Container.

Since it is both wrong and useless, I suggest that it should not be written. If you agree, I would be happy to submit a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant