0

对于某些背景,我使用In_List_Passive_Target了 PN532 用户手册中指定的命令来检索终端字段中所有卡的 UID。我还使用 ACR122U 的伪命令FF 00 00 00 04将这些命令发送到 PN532。

>>  FF 00 00 00 04 D4 4A 01 00           # In_List_Passive_Target (1)
<<  D5 4B 01 01 00 04 08 04 3E 58 A7 D1  # Response including UID (1)
>>  FF 00 00 00 04 D4 4A 01 00           # In_List_Passive_Target (2)
<<  D5 4B 01 01 00 04 08 04 9E 69 A7 D1  # Response including UID (2)
>>  FF 00 00 00 04 D4 4A 01 00           # In_List_Passive_Target (3)
<<  D5 4B 00                             # No more cards in field (3)

现在我已经这样做了,我想一一选择这些。我可以通过In_Deselect在使用完一张卡片 ( ) 后暂停它,然后使用In_List_Passive_Target带有其 UID 的命令选择下一张卡片来做到这一点。

但是,每次我选择一张卡时,我都想知道它返回的 ATR。事实证明,使用 Java Smart Card IO API 很难做到这一点,因为终端创建的卡对象始终是同一张卡(因此返回相同的 ATR),即使我断开卡然后创建新卡也是如此。考虑到如果我通过 PN532 终端命令与卡通信,这很奇怪In_Data_Exchange,它是正确的不同卡(不是通过 Card 对象可访问的旧卡)。我需要 ATR 能够检测它是哪种类型的卡(Mifare Classic、Desfire、Ultralight 等)

这是我为收集卡片创建的功能:

public static void getCardsInField()
    {
        cardList = new ArrayList<AbstractCard>();
        Boolean loop = true;

        // Card already connected to the terminal
        byte[] firstCardUID = transmitADPUCommand(GET_ADDRESS);
        MifareClassic firstCard = new MifareClassic(cardChannel, firstCardUID);
        cardList.add(firstCard);

        System.out.println(firstCard);
        System.out.println(readable(card.getATR().getBytes()));

        while(loop)
        {
            byte[] inDeselectResponse = transmitADPUCommand(IN_DESELECT); // Deselect current card
            byte[] inListPassiveTargetsResponse = transmitADPUCommand(IN_LIST_PASSIVE_TARGETS); // Select a new card

            System.out.println(">>  " + readable(IN_LIST_PASSIVE_TARGETS));
            System.out.println("<<  " + readable(inListPassiveTargetsResponse));

            // Trying to create a new card object for new card
            try
            {
                card.disconnect(true);
                card = cardTerminal.connect("*");
                cardChannel = card.getBasicChannel();
            }
            catch (CardException e)
            {
                e.printStackTrace();
            }

            if (Arrays.equals(inListPassiveTargetsResponse, IN_LIST_PASSIVE_TARGET_RESPONSE_NO_TARGETS)) // no more targets
            {
                loop = false;
            }
            else
            {
                byte[] loopCardUID = extractUID(inListPassiveTargetsResponse);
                MifareClassic loopCard = new MifareClassic(cardChannel, loopCardUID);
                cardList.add(loopCard);

                System.out.println(loopCard);
                System.out.println(readable(card.getATR().getBytes())); // this should be different ATR but it is the old cards atr
            }
        }
    }
4

1 回答 1

1

非接触式卡没有 ATR(复位应答)。ATR 仅由接触卡生成(ISO/IEC 7816-3 响应取消置位复位引脚)。此外,PC/SC 模拟非接触式卡的 ATR(基于卡的某些参数),因为 PC/SC 主要是为接触式卡设计的,因此,PC/SC API 期望 ATR 可用。

非接触式卡具有其他价值。例如,基于 ISO/IEC 14443 Type A 的卡具有 ATQA (SENS_RES)、SAK (SEL_RES)、UID (NFCID1) 和可能的 ATS(接近于 ATR)。基于 ISO/IEC 14443 B 类的非接触式卡具有相似的值。

您将获得识别卡类型以响应 InListPassiveTarget 命令所需的所有信息:

Card 1: D5 4B 01 01 00 04 08 04 3E 58 A7 D1
Card 2: D5 4B 01 01 00 04 08 04 9E 69 A7 D1

对于卡 1,此数据解码为:

  • ATQA (SENS_RES) =00 04
  • SAK (SEL_RES) =08
  • UID (NFCID1) =3E 58 A7 D1
  • ATS = 无

对于卡 2,此数据解码为:

  • ATQA (SENS_RES) =00 04
  • SAK (SEL_RES) =08
  • UID (NFCID1) =9E 69 A7 D1
  • ATS = 无

因此,两张卡都有 ATQA =00 04和 SAK = 08,这意味着它们很可能是 MIFARE Classic 1K 或 MIFARE Plus。

有关用于识别 NXP 的 ISO/IEC 14443 Type A 卡的值的完整列表,请参阅MIFARE 类型识别程序。

于 2015-10-03T12:05:14.590 回答