Host card emulation on Android (4.4 / KitKat and above) with Nexus 5
Asked Answered
A

1

9

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

Assort answered 18/4, 2014 at 14:1 Comment(2)
We need more information to tell what possibly could go wrong here. What application are you emulationg (i.e. what AID did you register your service for)? What are you expecting from the emulated card (i.e. should it respond as an NFC Forum tag containing an NDEF message or should it emulate some custom application)? How are you trying to read on the Nexus 7 (i.e. did you develop a special application or do you expect it to pick up the URL automatically to launch it in a web browser)?Husbandman
You take the point. I'm using the aid that I've found in the android sample. I don't know what should be the right AID to use. I'm confused about AID. If I understand the problem, yes I'd like to have a NFC forum tag with a NDEF message and I expect that my Nexus5 scanning the Nexus7 automatically picks up the url and launch the browser.Assort
H
18

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).

Husbandman answered 20/4, 2014 at 8:51 Comment(2)
A comment addressed to you has just been added as an answer: "@Michael Roland, is it still the case in 2023 that putting two Android devices together will establish a P2P link rather than trigger the appropriate app for the contents of the emulated tag?"Show
@user27611 yes, that can still be problematic.Husbandman

© 2022 - 2024 — McMap. All rights reserved.