java - 启用/禁用 NTAG213 计数器

标签 java android nfc mifare open-nfc

    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. 

NTAG213的数据手册说第42页的第0字节有访问信息。

第 0 个字节的结构如下:

 7       6         5        *4*            3          2  1  0
PROT  CFGLCK   RFUI    *NFC_CNT_EN*  NFC_CNT_PWD_PROT   AUTHLIM

将第 4 位设置为 0 或 1 应启用或禁用计数器。但我不确定在标签上书写时如何设置第四位。

最佳答案

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.

我的理解是,您在写入标签时处于正确的轨道上,您希望使用 transceive 方法来更新该位,但您不确定要写入哪些数据才能实现此目的。请注意,MifraUltralight.transceieve(byte[]) 相当于通过 NfcA 连接到此标签并调用 transceive(byte[])

需要注意的重要一点是“应用程序只能发送完整字节的命令”(来自 Android docs ),因此我们必须更新整个字节。但是,我们想要写入标签,该标签仅支持 4 字节(1 页)的有效负载,因此我们将重写整个页面。

这是我的经验开始有点崩溃的地方,但我建议采用以下方法:

  1. 读取第 42 页,将字节复制到缓冲区
  2. 将这些复制的字节写入第 42 页,但首先更新计数器位

执行第 1 步:

NfcA transaction = NfcA.get(tag);
transaction.connect(); // error handle
byte cmdRead = (byte)0x30;
byte page = (byte)(0x42 & 0xff); // AND to make sure it is the correct size
byte[] command = new byte[] {cmdRead, page};
byte[] page42 = nfcAtransaction.transceive(command); // error handle

byte mask = 0b00010000; // 3rd bit, or should it be 4th?
byte newData = page42[0] | mask; 

执行步骤 2:

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

完全未经测试,但我希望这会有所帮助。

关于java - 启用/禁用 NTAG213 计数器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43665215/

相关文章:

java - java中的浮点到时间

java - 如何更改 Hadoop 2 中用户日志的日志级别?

java - 使用正则表达式分割具有多个条件的字符串

Android Layer-List Drawable 有两个项目未正确绘制且大小错误

android - OKHttp HEAD 请求 - 速度优化

ios - 在iOS 13中读取NFC卡的UID

java - 将字符串转换为日期类型

java - 应用程序包路径

java - 如何使用Android studio将2个项目合并为1个?

java - 点击另一个支持 NFC 的设备后无法进入 onNewIntent。(android)