Home » Android » tags – Android: card emulation – read ndef message with PN532 nfc module

tags – Android: card emulation – read ndef message with PN532 nfc module

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have an LG D320n Android phone, elechouse’s PN532 nfc module and Stollmann’s NFCPlayer with which I can read NFC tags properly.

I tested a sample from here: https://github.com/grundid/host-card-emulation-sample

It works fine, when I read one Android device as tag with another Android device as reader. But I can not read the Android device as tag with PN532 reader through NFCPlayer. I want reader to read an NDEF message from the Android device acting as a tag, but NFCPlayer doesn’t even recognise the Android device. I think I have to write some modifications on the Android side but I can’t figure it out what to do. I think I don’t have enough knowlege about how NFC communication and HCE work, even though I read this:
https://developer.android.com/guide/topics/connectivity/nfc/hce.html

I would really appreciate any guideline that could help me understand what am I missing here.

How to&Answers:

The grundid example app should be discovered by NFCPlayer as a “legacy tag” (tab “R/W: Legacy”) as it does not implement the NDEF abstraction layer. On that tab, you can exchange PDUs (APDUs in the case of HCE) with the emulated smartcard. A valid APDU for the example app would be

00 A4 04 00 07 F0010203040506 00

You can send this APDU by typing it into the PDU field and clicking on the “Exch. PDU” button. Note that the grundid HCE app does not even implement ISO/IEC 7816-4 response APDUs. Hence, you may run into troubles with some contactless smartcard readers.

If you want your emulated smartcard to be discoverabe by NFCPlayer as NFC Forum Type 4 tag containing an NDEF message (tab “R/W: NDEF”), you would need to implement the NFC Forum Type 4 Tag Operation specification (as defined by the NFC Forum. This specification defines how data must be stored on an (emulated) ISO/IEC 14443-4 smartcard to be interpreted as NDEF tag. As a starting point you could use this NDEF on HCE example app (though, the quality and reliability of that code is questionable). This example implements the smartcard filesystem for storing NDEF data.