装有Nexus 5的Android(4.4/KitKat及更高版本)上的主机卡仿真 [英] Host card emulation on Android (4.4 / KitKat and above) with Nexus 5

查看:120
本文介绍了装有Nexus 5的Android(4.4/KitKat及更高版本)上的主机卡仿真的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据此文档用Nexus 5模拟NFC标签,但是我的服务永远不会被调用. 我应该关闭Android Beam吗?

我想模拟一个包含网址的简单标签.

阅读器是Nexus 7(2012),我已经弄清楚了这一过程,就像在Nexus 7上使用Android Beam进行NFC标签的简单扫描一样.

此外,我对辅助过滤器的名称有些困惑.有他们的名单吗?

我确定我听不懂. 谢谢

解决方案

首先(尽管这不能直接回答您的问题),在两个Android NFC设备之间传输URL的首选方法是使用Android Beam(对等对等模式). Android HCE(主机卡仿真)通常用于仿真非接触式智能卡应用程序,而不是NFC标签.

我是否需要关闭Android Beam才能使用Android HCE?

否,Android HCE不受Android Beam的开/关设置的影响.实际上,即使关闭Beam,Android NFC设备仍将执行对等模式的链接激活.

我想模拟一个包含URL的简单标签.

Android HCE模拟基于ISO/IEC 14443-4和ISO/IEC 7816-4的智能卡应用程序.因此,如果您想以此模拟NFC标签,则需要在Android HCE服务中实现NFC论坛的Type 4标签操作规范. NFC论坛的规范可在其网站上免费获得.

总结本规范的要求:

  1. 您需要为NFC论坛4类标签应用程序AID:D2760000850101注册服务.
  2. 您的服务需要以状态码成功(0x9000)响应该AID的SELECT(按DF名称)APDU:

    > 00 A4 04 00 07 D2760000850101 00
    < 9000
    

  3. 您的服务需要以状态码成功响应功能容器(CC)文件(E103)的SELECT(通过EF ID)APDU:

    > 00 A4 00 0C 02 E103
    < 9000
    

  4. 您的服务在收到READ BINARY APDU(选择CC文件后)后需要使用CC(或它的一部分)进行响应:

    > 00 B0 Offset_High Offset_Low Length
    < <Length bytes of the CC starting at Offset> 9000
    

  5. 您的服务需要以成功的状态码响应NDEF文件(在CC中定义的EF ID)的SELECT(通过EF ID)APDU:

    > 00 A4 00 0C 02 <EF ID>
    < 9000
    

  6. 您的服务在收到READ BINARY APDU(选择NDEF文件之后)后,需要使用NDEF文件内容(或其中的一部分)进行响应:

    > 00 B0 Offset_High Offset_Low Length
    < <Length bytes of the NDEF file starting at Offset> 9000
    

我希望第二台Android设备自动 提取URL.

这是有问题的部分,也是Beam成为首选方式的原因.即使您使用一台Android设备模拟NFC论坛Type 4标签,将两台Android设备放在一起仍将导致它们建立对等链接(即使关闭了Beam!).因此,第二台Android设备将不会将您的HCE仿真卡检测为NFC标签.克服此限制的唯一方法是在第二台设备上使用NFC Reader模式API(Android 4.4中的新增功能).但是,在这种情况下,您需要在接收设备上有一个在前台处于活动状态的应用程序(这是启用读取器模式API的唯一方法).

I'm trying to emulate an NFC tag with my Nexus 5 according to this document, but my service is never invoke. Should I turn off Android beam?

I'd like to emulate a simple tag containing a url.

The reader is a Nexus 7 (2012) and I've figured out the process like a simple scan of a NFC tag using Android beam on Nexus 7.

In addition I'm a bit confused about aid-filter name. Is there a list of them?

I'm sure that I don't understand something. Thanks

解决方案

First of all (though this does not directly answer your question), the preferred way to transfer a URL between two Android NFC device is to use Android Beam (peer-to-peer mode). Android HCE (Host Card Emulation) is typically intended for emulation of contactless smartcard applications other than NFC tags.

Do I need to turn off Android Beam in order to use Android HCE?

No, Android HCE is not influenced by the on/off setting of Android Beam. Actually, even if Beam is turned off an Android NFC device will still perform peer-to-peer mode link activation.

I'd like to emulate a simple tag containing a URL.

Android HCE emulates smartcard applications based on ISO/IEC 14443-4 and ISO/IEC 7816-4. Thus, if you want to emulate an NFC tag with this, you would need to implement the NFC Forum's Type 4 Tag Operation specification in your Android HCE service. The NFC Forum's specifications are freely available on their website.

To summarize the requirements of this specification:

  1. You need to register your service for the NFC Forum Type 4 tag application AID: D2760000850101.
  2. Your service needs to respond with status code success (0x9000) to a SELECT (by DF name) APDU for that AID:

    > 00 A4 04 00 07 D2760000850101 00
    < 9000
    

  3. Your service needs to respond with status code success to a SELECT (by EF ID) APDU for the capability container (CC) file (E103):

    > 00 A4 00 0C 02 E103
    < 9000
    

  4. Your service needs to responds with the CC (or parts of it) upon receiving a READ BINARY APDU (after the CC file had been selected):

    > 00 B0 Offset_High Offset_Low Length
    < <Length bytes of the CC starting at Offset> 9000
    

  5. Your service needs to respond with status code success to a SELECT (by EF ID) APDU for the NDEF file (EF ID as defined in the CC):

    > 00 A4 00 0C 02 <EF ID>
    < 9000
    

  6. Your service needs to responds with the NDEF file content (or parts of it) upon receiving a READ BINARY APDU (after the NDEF file had been selected):

    > 00 B0 Offset_High Offset_Low Length
    < <Length bytes of the NDEF file starting at Offset> 9000
    

I want a second Android device to automatically pick up the URL.

That's the problematic part and the reason why Beam is the preferred way to go. Even if you emulate an NFC Forum Type 4 tag with one Android device, putting two Android devices together will still result in them establishing a peer-to-peer link (even if Beam is turned off!). Thus, the second Android device will not detect your HCE emulated card as an NFC tag. The only way to overcome this limitation is to use the NFC Reader mode API (new in Android 4.4) on the second device. However, in that case, you would need to have an app on the receiving device that is active in the foreground (that's the only way to enable the Reader mode API).

这篇关于装有Nexus 5的Android(4.4/KitKat及更高版本)上的主机卡仿真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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