有什么方法可以区分 NTAG213 和 MF0ICU2 标签基于其 UID、ATQA 或 SAK 值?由于我必须对标签进行不同的编程(NTAG213 的 PWD/PACK 或 MF0ICU2 的 3DES),因此必须有一种方法可以调用一个或另一个方法.
不幸的是,Android 框架告诉我这两个标签都是 MifareUltralight
,类型为 TYPE_ULTRALIGHT_C
.ATQA (0x0044
) 和 SAK (0x00
) 也是一样的.
NXP 的 NFC TagInfo 等其他应用可以告诉我一个标签的确切类型,这样我就知道一定有办法.
一旦你知道标签是NXP标签(UID以0x04开头),你会
首先发送一个 GET_VERSION 命令.如果此命令成功,您就知道标签是 EV1 或更高版本(MIFARE Ultralight EV1、NTAG21x).否则,您可以假设它是第一代标签(MIFARE Ultralight、Ultralight C、NTAG203).
如果标签是 EV1 标签,您可以继续分析对 GET_VERSION 命令的响应.这将显示产品类型(NTAG 或 Ultralight EV1)以及产品子类型、产品版本和存储大小(让您可以确定确切的芯片类型:
<上一页>+------------+------+---------+------------+-------------+|芯片 |类型 |亚型 |版本 |存储大小 |+------------+------+---------+------------+-------------+|NTAG210 |0x04 |0x01 |0x01 0x00 |0x0B ||NTAG212 |0x04 |0x01 |0x01 0x00 |0x0E ||NTAG213 |0x04 |0x02 |0x01 0x00 |0x0F ||NTAG213F |0x04 |0x04 |0x01 0x00 |0x0F ||NTAG215 |0x04 |0x02 |0x01 0x00 |0x11 ||NTAG216 |0x04 |0x02 |0x01 0x00 |0x13 ||NTAG216F |0x04 |0x04 |0x01 0x00 |0x13 |+------------+------+---------+------------+-------------+|NT3H1101 |0x04 |0x02 |0x01 0x01 |0x13 ||NT3H1101W0 |0x04 |0x05 |0x02 0x01 |0x13 ||NT3H2111W0 |0x04 |0x05 |0x02 0x02 |0x13 ||NT3H2101 |0x04 |0x02 |0x01 0x01 |0x15 ||NT3H1201W0 |0x04 |0x05 |0x02 0x01 |0x15 ||NT3H2211W0 |0x04 |0x05 |0x02 0x02 |0x15 |+------------+------+---------+------------+-------------+|MF0UL1101 |0x03 |0x01 |0x01 0x00 |0x0B ||MF0ULH1101 |0x03 |0x02 |0x01 0x00 |0x0B ||MF0UL2101 |0x03 |0x01 |0x01 0x00 |0x0E ||MF0ULH2101 |0x03 |0x02 |0x01 0x00 |0x0E |+------------+------+---------+------------+-------------+如果标签不是 EV1 标签,您可以发送 AUTHENTICATE(第 1 部分)命令.如果此命令成功,您就知道标签是 MIFARE Ultralight C.否则,您可以假设标签是 Ultralight 或 NTAG203.
为了区分 MIFARE Ultralight 和 NTAG203,您可以尝试读取 Ultralight 上不存在的页面(例如读取第 41 页).
您可以使用 NfcA
或 MifareUltralight
(如果标签甚至可用)标签技术向标签发送命令:
boolean testCommand(NfcA nfcA, byte[] command) throws IOException {最终布尔值 leaveConnected = nfcA.isConnected();boolean commandAvailable = false;如果(!离开连接){nfcA.connect();}尝试 {byte[] 结果 = nfcA.transceive(command);if ((result != null) &&(result.length > 0) &&!((result.length == 1) && ((result[0] & 0x00A) == 0x000))) {//收到一些响应并且响应不是 NACK 响应命令可用=真;//您可能还想检查是否收到响应//这对于你之前的特定命令是合理的//假设该命令实际上是可用的并且什么//你期望...}} 捕捉(IOException e){//IOException(包括 TagLostException)可能表明//要么标签不再在范围内,要么命令在//标签不支持}尝试 {nfcA.close();} 捕捉(异常 e){}如果(离开连接){nfcA.connect();}返回命令可用;}
请注意,当标签不支持命令时,某些 NFC 堆栈会生成 IOException
(通常是 TagLostException
).无论收到 NACK 响应还是针对不受支持的命令的 IOException
,您都应该在之后断开并重新连接标签,以便在继续发送其他命令之前重置标签的状态.
Is there any way to distinguish a NTAG213 from a MF0ICU2 tag based on its UID, ATQA or SAK values? As I have to program the tags differently (PWD/PACK for NTAG213 or 3DES for MF0ICU2) there must be a way to call either one or another method.
Unfortunately, the Android framework tells me that both tags are MifareUltralight
with type TYPE_ULTRALIGHT_C
. The ATQA (0x0044
) and SAK (0x00
) are identical, too.
Other apps like NFC TagInfo by NXP can tell me the exact type of a tag, so I know that there must be some way.
Once you know that the tag is an NXP tag (UID starts with 0x04), you would
first send a GET_VERSION command. If this command succeeds, you know that the tag is EV1 or later (MIFARE Ultralight EV1, NTAG21x). Otherwise, you can assume that it is a first generation tag (MIFARE Ultralight, Ultralight C, NTAG203).
If the tag is an EV1 tag, you can continue by analyzing the resonse to the GET_VERSION command. This will reveal the product type (NTAG or Ultralight EV1) as well as product subtype, product version and storage size (which allows you to determine the exact chip type:
+------------+------+---------+-----------+--------------+ | Chip | Type | Subtype | Version | Storage size | +------------+------+---------+-----------+--------------+ | NTAG210 | 0x04 | 0x01 | 0x01 0x00 | 0x0B | | NTAG212 | 0x04 | 0x01 | 0x01 0x00 | 0x0E | | NTAG213 | 0x04 | 0x02 | 0x01 0x00 | 0x0F | | NTAG213F | 0x04 | 0x04 | 0x01 0x00 | 0x0F | | NTAG215 | 0x04 | 0x02 | 0x01 0x00 | 0x11 | | NTAG216 | 0x04 | 0x02 | 0x01 0x00 | 0x13 | | NTAG216F | 0x04 | 0x04 | 0x01 0x00 | 0x13 | +------------+------+---------+-----------+--------------+ | NT3H1101 | 0x04 | 0x02 | 0x01 0x01 | 0x13 | | NT3H1101W0 | 0x04 | 0x05 | 0x02 0x01 | 0x13 | | NT3H2111W0 | 0x04 | 0x05 | 0x02 0x02 | 0x13 | | NT3H2101 | 0x04 | 0x02 | 0x01 0x01 | 0x15 | | NT3H1201W0 | 0x04 | 0x05 | 0x02 0x01 | 0x15 | | NT3H2211W0 | 0x04 | 0x05 | 0x02 0x02 | 0x15 | +------------+------+---------+-----------+--------------+ | MF0UL1101 | 0x03 | 0x01 | 0x01 0x00 | 0x0B | | MF0ULH1101 | 0x03 | 0x02 | 0x01 0x00 | 0x0B | | MF0UL2101 | 0x03 | 0x01 | 0x01 0x00 | 0x0E | | MF0ULH2101 | 0x03 | 0x02 | 0x01 0x00 | 0x0E | +------------+------+---------+-----------+--------------+
If the tag is not an EV1 tag, you can send an AUTHENTICATE (part 1) command. If this command succeeds, you know that the tag is MIFARE Ultralight C. Otherwise, you can assume that the tag is either Ultralight or NTAG203.
In order to distinguish between MIFARE Ultralight and NTAG203, you can try to read pages that do not exist on Ultralight (e.g. read page 41).
You can send commands to the tag using the NfcA
or MifareUltralight
(if even available for the tag) tag technologies:
boolean testCommand(NfcA nfcA, byte[] command) throws IOException {
final boolean leaveConnected = nfcA.isConnected();
boolean commandAvailable = false;
if (!leaveConnected) {
nfcA.connect();
}
try {
byte[] result = nfcA.transceive(command);
if ((result != null) &&
(result.length > 0) &&
!((result.length == 1) && ((result[0] & 0x00A) == 0x000))) {
// some response received and response is not a NACK response
commandAvailable = true;
// You might also want to check if you received a response
// that is plausible for the specific command before you
// assume that the command is actualy available and what
// you expected...
}
} catch (IOException e) {
// IOException (including TagLostException) could indicate that
// either the tag is no longer in range or that the command is
// not supported by the tag
}
try {
nfcA.close();
} catch (Exception e) {}
if (leaveConnected) {
nfcA.connect();
}
return commandAvailable;
}
Note that some NFC stacks will generate an IOException
(typically a TagLostException
) when a command is not supported by the tag. Regardless of receiving a NACK response or an IOException
for an unsupported command, you should disconnect and reconnect the tag afterwards in order to reset the state of the tag before you continue to send other commands.
这篇关于区分 NTAG213 和 MF0ICU2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!