通过javax.smartcardio读取幻象NFC标签 [英] Reading phantom NFC tags via javax.smartcardio

查看:155
本文介绍了通过javax.smartcardio读取幻象NFC标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个旧的NFC阅读器用于tikitag Web服务(后来改名为 touchatag ,并最终在2012年左右放弃).由于该网站不再可用,我无法再找到原始的tikitag/touchatag驱动程序.经过一番搜索,我发现此NFC读取器是通用的ACS ACR122U USB读取器,并从

I have an an old NFC reader for the tikitag web service (which was later renamed touchatag, and finally abandoned around 2012). Since the website is no longer available, I could no longer find the original tikitag/touchatag drivers. After some searching, I found this NFC reader is a generic ACS ACR122U USB reader, and installed a suitable driver from here. My system is Windows 7 (64-bits).

首先,我尝试使用 NFC工具库对NFC标签进行高级读写访问.我收到一条错误消息,说遇到了不受支持的标签;尽管阅读器上甚至附近都不存在标签.似乎其他开发人员也对该库遇到了相同的错误,如此处.请注意,此标签会无限期地被检测到(因此,它一次被检测到并不会消失).

First, I tried the NFC Tools library for high-level read and write access to NFC tags. I got an error saying an unsupported tag was encountered; although no tag was present on the reader, or even remotely nearby. It seems other developers also encountered the same error with this library, as shown here. Note this tag is detected ad infinitum (so, it does not just disappear after being detected once).

我将所需的低级代码复制到一个单独的类(即独立于NFC工具库的类)中.您可以在下面找到此代码(类似的代码也可以在教程中找到):

I copied the required low-level code into a separate class (i.e., independent from the NFC Tools library). You can find this code below (similar code can also be found in tutorials):

import java.util.List;

import javax.smartcardio.Card;
import javax.smartcardio.CardTerminal;
import javax.smartcardio.TerminalFactory;

import org.nfctools.utils.NfcUtils;

public class NdefTest {

    public static void main(String[] args) throws Exception {
        TerminalFactory factory = TerminalFactory.getDefault();
        List<CardTerminal> terminals = factory.terminals().list();
        CardTerminal terminal = terminals.get(0);

        if (terminal.waitForCardPresent(5000)) {
            Card card = terminal.connect("T=0");
            System.out.println(NfcUtils.convertBinToASCII(card.getATR().getHistoricalBytes()));
        }
    }
}

此代码检测与使用NFC工具库时完全相同的幻影"标签.因此,此问题似乎与NFC工具库无关(如库开发人员对错误报告的响应所暗示).我丢失了某些东西,或者问题是与已安装的驱动程序,NFC读取器硬件有关,或者是javax.smartcardio中的一些未修复的错误(按可能性顺序列出).

This code detects the exact same "phantom" tag as when using the NFC Tools library. Therefore, this issue seems unrelated to the NFC Tools library (as implied by the library developer in response to the error report). Either I'm missing something, or the issue is either related to the installed driver, the NFC reader hardware, or some unfixed bug in javax.smartcardio (listed in order of likelihood).

我尝试卸载上述驱动程序,并让Windows 7自行安装合适的驱动程序(称为"Microsoft Usbccid智能卡读取器(WUDF)"),这导致与上述相同的错误.我没有尝试过其他读者,因为我只有一个.

I have tried uninstalling the aforementioned driver and letting Windows 7 install a suitable driver on its own (called "Microsoft Usbccid Smartcard Reader (WUDF)"), which results in the same errors as described above. I have not tried another reader, since I only have the one.

(注意:此NFC读取器在Windows设备概述中的名称为"CCID USB Reader",而不是"ACS ACR122"或相关名称.不知道这是否重要,只是以为我会提到它. ).

(Note: the name of this NFC reader in the Windows device overview is "CCID USB Reader", instead of "ACS ACR122" or something related. Don't know whether this is important, just thought I would mention it.).

有人遇到过此问题,并设法解决了吗?

Has anyone encountered this issue, and managed to resolve it?

更新

好吧,我已经尝试在检测到模拟标签之后向阅读器发送CLF命令.即获取连接的PICC的ATS( ACR122U手册):

Ok, I've tried sending a CLF command to the reader after the simulated tag has been detected; namely, getting the ATS of the connected PICC (p. 11 of the ACR122U manual):

TerminalFactory factory = TerminalFactory.getDefault();
List<CardTerminal> terminals = factory.terminals().list();

// (this is the correct terminal)
CardTerminal terminal = terminals.get(0);

if (terminal.waitForCardPresent(5000)) {
    Card card = terminal.connect("*");

    CardChannel channel = card.getBasicChannel();

// (I tried both 0x00 and 0x01 as P1, as well as 0x05 for Le)
    CommandAPDU getAts = new CommandAPDU(0xFF, 0xCA, 0x00, 0x00, 0x04);
    ResponseAPDU response = channel.transmit(getAts);

    System.out.println(response.getSW1());
    System.out.println(response.getSW2());
}

但是我一直收到错误响应代码(0x63 0x00).关于我可能做错了什么的任何想法?

But I keep getting an error response code (0x63 0x00). Any ideas on what I could be doing wrong?

推荐答案

您遇到的问题是,此版本的ACR122U阅读器以某种非标准的方式使用PC/SC(CCID).

The problem you encounter is that this version of the ACR122U reader uses PC/SC (CCID) in a somewhat non-standard way.

您使用PC/SC API检测到的卡"实际上是读卡器模拟的虚拟卡(即使没有卡也允许PC/SC API打开连接)或其中的智能卡芯片读取器的SAM插槽(读取器外壳内部有接触卡).

The "card" that you detect with the PC/SC API is actually either a dummy card simulated by the reader (to allow the PC/SC API to open a connection even if no card is present) or a smartcard chip in the reader's SAM slot (contact card present inside the reader's casing).

在任何一种情况下,该读取器仅将PC/SC用作该读取器(NXP PN532)中使用的非接触式前端芯片的本机命令的传输协议.因此,如果要使用阅读器的非接触式功能,则必须使用CLF的本机命令集.请参阅 ACR122U API文档 libnfc 实现,以获取更多详细信息.

In either case, this reader uses PC/SC only as a transport protocol for native commands of the contactless frontend chip used within this reader (NXP PN532). Thus, if you want to use the reader's contactless functionality, you have to use the CLF's native command set. See the ACR122U API documentation or the libnfc implementation for further details.

这篇关于通过javax.smartcardio读取幻象NFC标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆