区分NTAG213和MF0ICU2

Gre*_*eny 1 tags android nfc fingerprinting mifare

有没有办法根据其UID,ATQA或SAK值区分NTAG213MF0ICU2标签?因为我必须以不同的方式编程标签(用于NTAG213的PWD/PACK或用于MF0ICU2的3DES),必须有一种方法来调用一种或另一种方法.

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

其他应用程序,如NXP的NFC TagInfo可以告诉我标签的确切类型,所以我知道必须有某种方式.

Mic*_*and 6

一旦你知道标签是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. 如果标记不是EV1标记,则可以发送AUTHENTICATE(第1部分)命令.如果此命令成功,则表示该标记为MIFARE Ultralight C.否则,您可以认为该标记为Ultralight或NTAG203.

  4. 为了区分MIFARE Ultralight和NTAG203,您可以尝试读取Ultralight上不存在的页面(例如,阅读第41页).

您可以使用NfcAMifareUltralight(如果甚至可用于标记)标记技术将命令发送到标记:

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;
}
Run Code Online (Sandbox Code Playgroud)

请注意,当标签不支持命令时,某些NFC堆栈将生成IOException(通常为a TagLostException).无论是否收到NACK响应或IOException不支持的命令,都应该断开并重新连接标记,以便在继续发送其他命令之前重置标记的状态.