3

I have been trying for a long while now to write and read data from my NFC cards. The cards are NTAG216. I can use libnfc examples to read manufacturer ID and it works fine. But I need to write to each tag some custom data, e.g. the string "abcdefg" and read it back.

I have read almost everything relevant I could find about libnfc but all of them does not talk about this specific area. I would appreciate any guidance. Code example will be appreciated.

I use an ACRU122 NFC reader/writer with libnfc 1.7.1 from Github.

Michael Roland
  • 39,663
  • 10
  • 99
  • 206
Stefano Mtangoo
  • 6,017
  • 6
  • 47
  • 93

1 Answers1

2

Once you enumerated and activated the tag, you can use the method nfc_initiator_transceive_bytes() to send raw NTAG commands (such as READ/WRITE) to the tag. Since the command set of NTAG216 is compatible to the MIFARE Ultralight command set (including the COMPATIBILITY WRITE command), you could also use the convenience methods for MIFARE tags defined in utils/mifare.h:

  • nfc_initiator_mifare_cmd(pnd, MC_WRITE, page, &mp)
  • nfc_initiator_mifare_cmd(pnd, MC_READ, page, &mp)

See the nfc-mfultralight utility for complete code examples: nfc-mfultralight.c.

However, you might want to adapt that code to use the more efficient MIFARE Ultralight/NTAG WRITE (0xA2) command instead of the COMPATIBILITY WRITE (which is what MC_WRITE uses).

Michael Roland
  • 39,663
  • 10
  • 99
  • 206
  • thanks Mike. I will go though whatever you wrote and come back. On thing, do those command allow rewrite or once you write once everything becomes read only? – Stefano Mtangoo Mar 27 '16 at 16:52
  • 1
    @StefanoMtangoo That depends on where you write to. NTAG216 has one one-time programmable page (page 3) and re-writable data pages (as long as you don't set thew lock-bits for those pages). – Michael Roland Mar 27 '16 at 22:55
  • this should work by using MIFARE ultralight cards which are in accordance with: ISO/IEC 14443 A ? – willyMon May 31 '18 at 19:11