简体   繁体   English

Android:14443 A型卡的HCE

[英]Android: HCE of 14443 type A card

I'm trying to develop an application that uses Android NFC as smart card (Android 4.4.2 in HCE mode). 我正在尝试开发一个使用Android NFC作为智能卡的应用程序(HCE模式下的Android 4.4.2)。 I've read the guide about HCE on Android 4.4 . 我已经阅读了有关Android 4.4上的HCE指南 I used the example along with the Android 4.4 SDK. 我将示例与Android 4.4 SDK一起使用。 But if try to read the HCE-emulated smart card from another Android NFC device (Android 4.3) with an NFC reader application, I see only these logs: 但是,如果尝试从另一个带有NFC读取器应用程序的Android NFC设备(Android 4.3)读取HCE仿真的智能卡,则只会看到以下日志:

03-31 17:02:21.151: I/NFC-HCI(600): I'm P2P Active Initiator @ 424 kb/s
03-31 17:02:21.159: D/NFCJNI(600): Discovered P2P Target
03-31 17:02:21.159: D/NfcService(600): LLCP Activation message
03-31 17:02:21.183: I/NFC-HCI(600): I'm P2P Active Initiator @ 424 kb/s
03-31 17:02:21.190: I/NFCJNI(600): LLCP Link activated (LTO=150, MIU=128, OPTION=0x00, WKS=0x13)
03-31 17:02:21.190: I/NfcP2pLinkManager(600): LLCP activated
03-31 17:02:21.190: D/NfcP2pLinkManager(600): onP2pInRange()
[...]
03-31 17:02:22.144: I/NFCJNI(600): LLCP Link deactivated
03-31 17:02:22.144: D/NfcService(600): LLCP Link Deactivated message. Restart polling loop.
03-31 17:02:22.144: I/NfcP2pLinkManager(600): LLCP deactivated.
03-31 17:02:22.144: D/NfcP2pLinkManager(600): Debounce timeout
03-31 17:02:22.151: D/NfcP2pLinkManager(600): onP2pOutOfRange()

If I try, instead, to read a real smart card, it works as expected and I'm able to read the card: 如果我尝试读取真实的智能卡,它会按预期运行,并且能够读取该卡:

TagID (hex): c4 2a 29 c8
TagID (dec): 3291097544
Technologies: MifareClassic, NfcA,NdefFormatable
Mifare Classic type: Classic
Mifare size: 1024 btes
Mifare sectors: 16
Mifare blocks: 64

I've read this thread but my knowledge in this regard are very few. 我已经阅读了该主题,但是我在这方面的知识很少。

Simple answer: what you are trying to do is not possible. 简单的答案:您试图做的事是不可能的。

The problem here is that two Android devices will communicate in peer-to-peer mode by default (even if one or both devices support host card emulation). 这里的问题是,默认情况下,两个Android设备将以对等模式进行通信(即使其中一个或两个设备都支持主机卡仿真)。 Once an Android device successfully communicates in peer-to-peer mode, it won't try to communicate in reader/writer mode. Android设备一旦成功以对等模式进行通信,就不会尝试以读取器/写入器模式进行通信。 Consequently, your device with the reader app won't detect the HCE-emulated "card" of the other device. 因此,带有阅读器应用程序的设备将不会检测到另一设备的HCE模拟的“卡”。

In order to permit the Android HCE-emulated card to be visible to the second device with the reader app, that second device would need to disable its peer-to-peer mode capabilities and be active only in reader/writer mode. 为了允许带有读取器应用程序的第二个设备看到Android HCE仿真卡,该第二个设备将需要禁用其对等模式功能,并且仅在读取器/写入器模式下处于活动状态。 That's were the thread you were refereing to ( Android : How to change NFC protocol priority? ) comes in. By using the reader mode API, more specifically the enableReaderMode method of the NfcAdapter with the flags FLAG_READER_NFC_A , FLAG_READER_NFC_B (and optionally FLAG_READER_SKIP_NDEF_CHECK ), you can force the (reader side!!!) Android device to act only in reader/writer mode and to disable peer-to-peer mode: 这就是您所引用的线程( Android:如何更改NFC协议优先级? )。通过使用读取器模式API,更具体地说,使用带有标志FLAG_READER_NFC_AFLAG_READER_NFC_B (和可选的FLAG_READER_SKIP_NDEF_CHECK )的NfcAdapterenableReaderMode方法。可以强制(阅读器端!!!)Android设备仅在阅读器/写入器模式下运行并禁用对等模式:

NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
nfcAdapter.enableReaderMode(this, new NfcAdapter.ReaderCallback() {
    public void onTagDiscovered(Tag tag) {
        // TODO: access tag...
    }
},
NfcAdapter.FLAG_READER_NFC_A | NfcAdapter.FLAG_READER_NFC_B | NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK, null);

Unfortunately, this API is only available on Android 4.4 and later. 不幸的是,该API仅在Android 4.4及更高版本上可用。 So with an Android 4.3 device, you have no means to disable peer-to-peer mode and therefore can't communicate with an Android HCE "card". 因此,对于Android 4.3设备,您无法禁用对等模式,因此无法与Android HCE“卡”进行通信。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM