android - 在 NTAG213 中获取异常

标签 android authentication tags nfc mifare

我使用以下代码在 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”。

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

最佳答案

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
});

关于android - 在 NTAG213 中获取异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34543076/

相关文章:

android - 如何保持我的应用程序服务继续运行,即使应用程序从 MI 手机中的任务管理器关闭

c# - 帮助理解标签云算法

javascript - Android 浏览器远程调试

Android:如何使 swipeRefreshLayout 更难向下滑动

javascript - 账号onLogin hook meteor 循环

c# - 在 ASP.NET Core 应用程序中同时启用 Windows 身份验证和匿名身份验证

java - 使用 APACHE Shiro 将用户重定向到特定 URL

video - 如果支持,请使用 HTML <video> 标签,否则使用 lightbox??? (脚本)

html - css强制仅在标签内的某些字符使用斜体?

Android:TextView 中的多种样式静态