【问题标题】:Getting exception in NTAG213在 NTAG213 中获取异常
【发布时间】:2015-12-31 07:52:16
【问题描述】:

我正在使用以下代码在 NTAG213 NFC 标签上设置 AUTH0(需要密码验证的第一页):

try {
    result = nfca.transceive(new byte[]{
            (byte) 0xA2,  // Command: WRITE
            (byte) 0x29,  // Address: AUTH0
            (byte) 0x00   // starting address
    });
} catch (IOException e) {
    e.printStackTrace();
}

但是,当我在 AUTH0 上写入 00h(作为起始地址)时,我总是收到异常:“Transceive failed”。

你能告诉我这里可能出了什么问题吗?

【问题讨论】:

    标签: android authentication tags nfc mifare


    【解决方案1】:

    NTAG213(与其他 NTAG 和 MIFARE Ultralight 芯片一样)使用 4 字节的页面大小。 WRITE 命令 (0xA2) 只能用于写入一整页。因此,WRITE 命令的数据参数需要由 4 个字节组成。

    最简单的方法是覆盖整个配置页面:

    result = nfca.transceive(new byte[]{
            (byte) 0xA2,  // Command: WRITE
            (byte) 0x29,  // Address: CONFIG0
            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
    });
    

    但请记住,这也会覆盖其他配置参数(镜像字节和镜像页面)。如果您想将这些其他参数设置为其默认值,您可以简单地使用:

    result = nfca.transceive(new byte[]{
            (byte) 0xA2,  // Command: WRITE
            (byte) 0x29,  // Address: CONFIG0
            (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00
    });
    

    但是,如果您想将这些其他值保留为它们当前包含的值,您可能需要先读取页面,然后使用这些值更新页面(仅将 AUTH0 设置为 0x00):

    byte[] currentData = nfca.transceive(new byte[]{
            (byte) 0x30,  // Command: READ
            (byte) 0x29,  // Address: CONFIG0
    });
    
    result = nfca.transceive(new byte[]{
            (byte) 0xA2,  // Command: WRITE
            (byte) 0x29,  // Address: CONFIG0
            currentData[0], currentData[1], currentData[2], (byte) 0x00
    });
    

    【讨论】:

      猜你喜欢
      • 2019-11-29
      • 2012-06-22
      • 1970-01-01
      • 1970-01-01
      • 2011-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多