Android: card emulation - read ndef message with PN532 nfc module
Asked Answered
W

1

11

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.

Whiff answered 12/5, 2015 at 10:2 Comment(0)
J
2

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.

Jennefer answered 7/6, 2015 at 6:58 Comment(3)
I am sorry for such late response. I had some other projects which had to be done first. Your answer helped me a lot. thanks! (I figured it out that i don't need ndef messages so I didn't test this part). Thanks a lot!Raptorial
hi, I have another question. It is working smoothly with OnePluse One with CM. in logcat I have those outputs: 07-08 10:30:03.445 1468-26171/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: event=0x18 07-08 10:30:03.450 1468-26171/? D/HostEmulationManager﹕ notifyHostEmulationActivated 07-08 10:30:03.452 1468-26171/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: event=0x17 07-08 10:30:03.452 1468-26171/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: NFA_CE_DATA_EVT; stat=0x0; h=0x301; data len=13Raptorial
and NFCPlayer finds my android device as ISO 14443-A card with 1234 ID and then I can exch. PDU. but with another device (LG d320n) it is not working... NFCPlayer does not recognise it and RoutingManager::stackCallback: event=0x18 or notifyHostEmulationActivated is not called as I could see it in logcat. why is that? Interesting is that oneplus device is recogniseing LG with grundid app (receiver mode). Thanks in advance!Raptorial

© 2022 - 2024 — McMap. All rights reserved.