在NTAG213中获得例外

时间:2015-12-31 07:52:16

标签: 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"。

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

1 个答案:

答案 0 :(得分:1)

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

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

$props = @{
HostingEnvironmentId ='/subscriptions/xyz/resourceGroups/ResourceGroup1/providers/Microsoft.Web/hostingEnvironments/ASE1
ServerFarmId = '/subscriptions/XXXX/resourceGroups/EDSGRP1/providers/Microsoft.Web/serverfarms/ASP1'
HostingEnvironment = ResourceGroup1
ClientCertEnabled ='True'
}

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

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

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

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