如何在安卓上以编程方式编写保护NTAG203 NFC芯片



我一直在研究NTAG203 NFC芯片作为会员卡解决方案,并打算在每张卡上设置并写入一个唯一的ID。

奇怪的是,我在网上找不到太多关于如何编写保护NTAG203芯片的信息,尽管我可以找到正在出售的写保护芯片。我还看到了提供写保护服务的应用程序。

您如何编写安卓应用程序以在NTAG203上启用写保护?

谢谢!

(为清楚起见,已编辑问题)

是的,这是可能的。NTAG203(数据表)是 ISO/IEC 14443 A 型 ("NFC-A") 标签,遵循 NFC 论坛 2 类标签操作规范。为了激活此类标签的物理写保护功能,您需要设置锁定位。

在 Android 上,您可以通过获取标记句柄的 NfcA 技术连接器类的实例来访问此类标记:

Tag tag = ...  // I assume you already received the tag handle by means of an NFC discovery intent
NfcA nfcA = NfcA.get(tag);
if (nfcA != null) {
    // this is an NFC-A tag
    ...

NTAG203的锁定位位于第 2 页 (0x02) 字节 2-3 和第 40 页 (0x28) 字节 0-1。这 4 个字节中的每一个位都控制NTAG203内存区域某些页面的锁定状态。为了激活锁定,您必须通过对包含锁定位的页面发出写入命令来将锁定位设置为 '1'。因此,对于锁定整个标签的最简单方案,您可以执行以下操作:

    // connect to the tag
    nfcA.connect();
    byte[] result;
    // write all-ones to the lock bits on page 0x02
    result = nfcA.transceive(new byte[]{
            (byte)0xA2,  // Command: WRITE
            (byte)0x02,  // Address: page 0x02 (2)
            (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0xFF  // Data: set bytes 2-3 to all '1'
    });
    // write all-ones to the lock bits on page 0x28
    result = nfcA.transceive(new byte[]{
            (byte)0xA2,  // Command: WRITE
            (byte)0x02,  // Address: page 0x28 (40)
            (byte)0xFF, (byte)0x11, (byte)0x00, (byte)0x00  // Data: set byte 0 and lock bits in byte 1 to all '1'
    });
    nfcA.close();

最新更新