hce-to-chromenfc-app

Chrome App that talks to Android host-based card emulation application.

APACHE-2.0 License

Stars
10
Committers
1

Android HCE to Chrome NFC App

Chrome App that talks to Android host-based card emulation application.

This Chrome Application example listens for a Android host-based card emilation NFC Forum Type-4 "tag" with an a single NDEF record (RTD_TEXT). This Chrome App with send a APDU SELECT for F0394148148100 (which is an example that is defined in the Android documentation).

Whoa there what?

About 9 months ago, the Chrome team released a sample called Chrome-NFC. Their application interacted with an NFC card reader via chrome.usb.Tbulkransfer() and included support for TT2 and Mifare Classic. Pretty sweet stuff.

I decided to extend it to a little more: I wanted it interact with NFC Forum Type 4 Tag Operation Specification 3.0, which outlines how to interact with tags. This would allow:

  1. Using Host-based Card Emulation in Android, we can create a "tag" that we can do all sorts of cool things with (kiosk sign-ins, badging for events, games, et cetera).

  2. We can write a Chrome App that we can deploy on Chromebooks/Chromeboxes that sends the proper APDU SELECT and associated commands and interact with our Android "card".

What hardware do I need to run this?

  1. I built and tested this on a Chromebook Pixel, but any Chromebook/Chromebox should do.
  2. A supported NFC reader. I use the ACR122U, but the SCL3711 should also work.
  3. An Android device with NFC and running at least API 19. I use the Nexus 4/5 for testing.

How do I use this application?

  1. Under chrome://extensions, verify that have enabled Developer Mode.
  2. Clone this repo.
  3. Click the Load unpacked extension button and select the folder where you cloned the repo

Where do I get the Android application?

My android hostcardemulation sample is also open source. You can pull the source and build with Android Studio.

Where is your Chrome-NFC fork?

Also available on Github (make sure you use my type4-conversation branch).

I just want to point out that I didn't have to do a great deal of work to make the conversation work; the folks on the Chrome team who wrote the wire communications did a real nice job (I had no issue sending commands to the reader via writeFrame()).

Updating and building

Since we're a Chrome App and we're using Polymer, we need to use vulecanize and the --csp option. Remember, we have to handle the strict Content Security Policy, otherwise things won't work.

Luckily, this is taken care of via grunt.

npm install -g grunt-cli
npm install
grunt

Note: Building a Chrome App and want to spin up some Polymer fast? Check out PolymerLabs/polymerchromeapp, which is what I spun this project from.

Any gotcha's?

Sure. I'm not using wait_for_passive_target() at the moment in this build (it doesn't quite work like libnfc's nfc_initiator_select_passive_target() and I haven't had time to dive into it). There are few shortcuts (there is limited to no NDEF checking; since I wrote the HCE to be RTD_TEXT, I presume RTD_TEXT here...which young programmers, you shouldn't do unless you're running the demo yourself :-).

There are areas for improvement, of course. Consider it all a work in progress.

Where can I get the tag operational spec?

There are various copies on the Internet, but the place to go is to sign the specification license and download direct from the NFC Forum document library.

Where can I learn more about Host Card Emulation on Android?

You'll need API 19 (aka Android 4.4) to use HCE. See Host-based Card Emulation @ developers.android.com for all the details.