我一直在研究用于会员卡解决方案的 NTAG203 NFC 芯片,并打算在每张卡上设置和写入唯一 ID。
奇怪的是,我在网上找不到太多关于如何写保护 NTAG203 芯片的信息,尽管我可以找到正在出售的写保护芯片。我还看到了提供写保护服务的应用程序。
您如何编写 Android 应用程序以在 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();