Skip to content Skip to sidebar Skip to footer

Enable/disable Counter For Ntag213

MifareUltralight mifareUltralight = MifareUltralight.get(tag); byte[] toggleCounterCommand = new byte[]{(byte)0xA2, // NTAG213 command to write

Solution 1:

Context for anyone coming to this in the future:

NTAG21x features a NFC counter function. This function enables NTAG21x to automatically increase the 24 bit counter value, triggered by the first valid

  • READ command or
  • FAST-READ command

after the NTAG21x tag is powered by an RF field. Once the NFC counter has reached the maximum value of FF FF FF hex, the NFC counter value will not change any more. The NFC counter is enabled or disabled with the NFC_CNT_EN bit (see Section 8.5.7) http://www.nxp.com/documents/data_sheet/NTAG213_215_216.pdf.

My understanding is that you're on the right track with writing to the tag, you want to use the transceive method to update that bit, but you're not sure what data to write in order to achieve this . Note that MifraUltralight.transceieve(byte[]) is equivalent to connecting to this tag via NfcA and calling transceive(byte[]).

An important thing to note is that "Applications must only send commands that are complete bytes" (from Android docs) so we must update that entire byte. However, we want to write to the tag, which only supports a payload of 4 bytes (1 page) so we will be rewriting the whole page.

This is where my experience starts to break down a little bit, but I would suggest an approach of:

  1. Read page 42, copy the bytes to a buffer
  2. Write those copied bytes to page 42, but update the counter bit first

Doing step 1:

NfcAtransaction= NfcA.get(tag);
transaction.connect(); // error handlebytecmdRead= (byte)0x30;
bytepage= (byte)(0x42 & 0xff); // AND to make sure it is the correct sizebyte[] command = newbyte[] {cmdRead, page};
byte[] page42 = nfcAtransaction.transceive(command); // error handlebytemask=0b00010000; // 3rd bit, or should it be 4th?bytenewData= page42[0] | mask; 

Doing step 2:

byte cmdWrite = (byte)0xA2;
byte page = (byte)(42 & 0xff);
byte[] command = newbyte[] { cmdWrite, page, newData, page42[1], page42[2], page42[3]};
byte[] result = nfcA.transceive(command); 

Completely untested, but I hope this helps.

Post a Comment for "Enable/disable Counter For Ntag213"