gpt4 book ai didi

android - 区分NTAG213和MF0ICU2

转载 作者:行者123 更新时间:2023-11-29 14:46:14 28 4
gpt4 key购买 nike

有没有办法区分NTAG213来自MF0ICU2基于其 UID、ATQA 或 SAK 值的标签?因为我必须对标签进行不同的编程(NTAG213 的 PWD/PACK 或 MF0ICU2 的 3DES),所以必须有一种方法可以调用一个或另一个方法。

不幸的是,Android 框架告诉我这两个标签都是 MifareUltralight,类型为 TYPE_ULTRALIGHT_C。 ATQA (0x0044) 和 SAK (0x00) 也是相同的。

其他应用程序,例如 NFC TagInfo by NXP可以告诉我标签的确切类型,所以我知道一定有某种方法。

最佳答案

一旦知道标签是 NXP 标签(UID 以 0x04 开头),您就会

  1. 首先发送一个 GET_VERSION 命令。如果此命令成功,则您知道标签是 EV1 或更高版本(MIFARE Ultralight EV1、NTAG21x)。否则,您可以假设它是第一代标签(MIFARE Ultralight、Ultralight C、NTAG203)。

  2. 如果标签是 EV1 标签,您可以继续分析对 GET_VERSION 命令的响应。这将揭示产品类型(NTAG 或 Ultralight EV1)以及产品子类型、产品版本和存储大小(这使您可以确定确切的芯片类型:

    +------------+------+---------+-----------+--------------+| 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         |+------------+------+---------+-----------+--------------+
  3. 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.

  4. 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;
}

请注意,当标签不支持命令时,某些 NFC 堆栈会生成 IOException(通常是 TagLostException)。无论收到 NACK 响应还是针对不受支持的命令的 IOException,您都应该在之后断开并重新连接标签,以便在继续发送其他命令之前重置标签的状态。

关于android - 区分NTAG213和MF0ICU2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37002498/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com