MifareUltralight mifareUltralight = MifareUltralight.get(tag);
byte[] toggleCounterCommand = new byte[]{(byte)0xA2, // NTAG213 command to write
(byte)0x2A, // page 42(dec) 2A(hex)
(byte)___};// not sure what to put here.
The data sheet for NTAG213 says that the 0th byte of page 42 has the access information.
The 0th byte is structured in the following way :
7 6 5 *4* 3 2 1 0
PROT CFGLCK RFUI *NFC_CNT_EN* NFC_CNT_PWD_PROT AUTHLIM
Setting the 4th bit to 0 or 1 should enable or disable the counter. But I'm not sure how to set the 4th bit while writing on the tag.
Context for anyone coming to this in the future:
My understanding is that you're on the right track with writing to the tag, you want to use the
transceivemethod to update that bit, but you're not sure what data to write in order to achieve this . Note thatMifraUltralight.transceieve(byte[])is equivalent to connecting to this tag viaNfcAand callingtransceive(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:
Doing step 1:
Doing step 2:
Completely untested, but I hope this helps.