简体   繁体   English

Android 4.4.2,PN532 NFC读卡器和NFC卡仿真

[英]Android 4.4.2, PN532 NFC reader and NFC Card emulation

I have developed a system that can read NFC tag using a reader with PN532 chip . 我开发了一个系统,可以使用带有PN532芯片阅读器读取NFC标签。 It works ok. 它工作正常。 I can read Mifare Classic and Mifare Ultralight tag. 我可以阅读Mifare Classic和Mifare Ultralight标签。

Now I'd like to use a Nexus Tablet with Android 4.4.2 to emulate a tag. 现在,我想使用Android 4.4.2的Nexus平板电脑来模拟标签。 I have no experience with android development but I think it is possible. 我没有Android开发经验,但我认为这是可能的。

I have set NFC communication in the Nexus Tablet but I think I have to download or write some application to emulate a Tag and an NDEF communication. 我已经在Nexus平板电脑中设置了NFC通信,但我认为我必须下载或编写一些应用程序来模拟标签和NDEF通信。

What is the easiest way? 什么是最简单的方法?

That depends on what Nexus tablet you have: 这取决于您拥有的Nexus平板电脑:

  • Nexus 7 (first generation/2012 version): This device uses NXP's PN544 NFC controller. Nexus 7(第一代/ 2012版):该设备使用恩智浦的PN544 NFC控制器。 It seems that it's currently not possible to perform host-based card emulation with Android 4.4+ on these devices (see this question and my answer here ). 似乎目前无法在这些设备上使用Android 4.4+执行基于主机的卡仿真(请参阅此问题我的答案 )。

  • Nexus 7 (second generation/2013 version) and Nexus 10: These devices use Broadcom's NFC controller. Nexus 7(第二代/ 2013版)和Nexus 10:这些设备使用Broadcom的NFC控制器。 Therefore, you can use Android 4.4's HCE API to emulate a contactless smartcard. 因此,您可以使用Android 4.4的HCE API来模拟非接触式智能卡。

With Android's HCE API you will emulate an ISO 14443-4 smartcard and you can only communicate using the application selection and APDU format defined in ISO 7816-4. 使用Android的HCE API,您将模拟ISO 14443-4智能卡,并且只能使用ISO 7816-4中定义的应用程序选择和APDU格式进行通信。 You would first create and register a HCE service (see the API guide ). 您首先要创建并注册HCE服务(请参阅API指南 )。 Then you can process incoming APDUs using the service's processCommandApdu() method (see this answer ). 然后,您可以使用服务的processCommandApdu()方法处理传入的APDU(请参阅此答案 )。

If your reader-side application currently only processes MIFARE Classic and Ultralight, you would have to extend it to also communicate with ISO 14443-4/APDU-based smartcards. 如果您的读者端应用程序目前仅处理MIFARE Classic和Ultralight,则必须将其扩展为与基于ISO 14443-4 / APDU的智能卡进行通信。 (Emulation of non-APDU based cards like MIFARE Classic and Ultralight is not possible on top of ANdroid's HCE API.) The PN532 will typically handle the bigger part of this for you, so once you discover such a smartcard (eg with InListPassiveTarget ) it should automatically handle the ISO 14443-4 transport protocol and you can directly send APDU commands using the InDataExchange command. (在ANdroid的HCE API之上,不能对基于非APDU的卡(如MIFARE Classic和Ultralight)进行仿真。)PN532通常会为您处理大部分内容,因此一旦您发现这样的智能卡(例如使用InListPassiveTarget ),应自动处理ISO 14443-4传输协议,您可以使用InDataExchange命令直接发送APDU命令。

If you want to exchange NDEF messages over HCE, once you have APDU-based communication up and running, you could implement the NFC Forum's Type 4 Tag Operation specification (get it from the NFC Forum's website ) within the Android HCE service to emulate a Type 4 NDEF tag. 如果您想通过HCE交换NDEF消息,一旦您启动并运行基于APDU的通信,您可以在Android HCE服务中实现NFC论坛的Type 4标签操作规范(从NFC论坛的网站获取 )以模拟类型4 NDEF标签。

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

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