Topic: P2P communication between android phone and nfc reader

I am trying to establish NFC P2P communication between an android mobile and an ACR 122 U reader that is connected to my desktop. When I read through the android SDK documentation I found that, to establish P2P communication with the device, the other device must also use NDEF protocol over LLCP.

Is libnfc providing any library for it? If not, can you please suggest any library that could be used?

Re: P2P communication between android phone and nfc reader

Hello,

libnfc is not LLCP compliant but a project have been started on nfc-tools googlecode project. For now, there is no much code, but this project will be in beta in few weeks.
Next LLCP, you will have to implement NDEF over LLCP, using libndef (for NDEF), libnfc-llcp (for LLCP) which rely on libnfc (for NFC).

I hope it helps,

Romuald Conty

Re: P2P communication between android phone and nfc reader

Hello,

nfcpy (https://launchpad.net/nfcpy) fully implements LLCP and also provides an LLCP test suite that was used to validate the specification before it got published. It does however not support the ACR 122 but it should not be too difficult to run it on top of libnfc. I've read in other threads that libnfc supports the data exchange protocol interface of the PN53x and also there already exists pynfc to access libnfc from Python. Maybe that's an option too.

/Stephen

Re: P2P communication between android phone and nfc reader

Hello nephets,

I already leave a topic about nfcpy, could you post a description for this project (featues, supported devices, etc.) in:
http://www.libnfc.org/community/topic/3 … c-devices/

Thank you.

Romuald Conty

Re: P2P communication between android phone and nfc reader

I am very interested in the LLCP and NPP implementations in libnfc because I would like to establish p2p NFC communication between my SCM SCL3711 and my Nexus S. As I understand it these are the missing pieces, right?

Is there anything I can do to help? Is there something to test?

Re: P2P communication between android phone and nfc reader

I am very much interested in the P2P connection between SCM SCL3711 and Nexus S. If there is a pointer to know more about this please send me the pointer.

Thanks.

Re: P2P communication between android phone and nfc reader

EDevil wrote:

I am very interested in the LLCP and NPP implementations in libnfc because I would like to establish p2p NFC communication between my SCM SCL3711 and my Nexus S. As I understand it these are the missing pieces, right?

That's right libnfc does not implement LLCP, but Romain starts to work on it:
http://code.google.com/p/nfc-tools/sour … ibnfc-llcp

I don't which development step is reach or not, but that will become the official LLCP stack for libnfc.

EDevil wrote:

Is there anything I can do to help? Is there something to test?

NPP is not implemented in C but available in nfcpy (https://launchpad.net/nfcpy) which does not use libnfc btw.

Romuald Conty

Re: P2P communication between android phone and nfc reader

Hi everyone,
i am looking for a way to do exactly what was asked in the beginning of the thread, a nfc p2p communication between a nfclib device and a android phone, and i am not afraid of contributing new stuff. more specifically i have a omnikey 5553 usb device, that seems to be not supported in any way by libnfc (correct if i missed something with that, and if this board is not supported, what do i have to do to make it compatible with libnfc), and a nexus s. i could however maybe able to get a APPB usb device, not sure if with pn531 oder pn532.
anyway, it seems there are missing pieces, especially for my usb devices, and i like to ask particulary for some kind of roadmap to implement the p2p functionality, meaning more or less exactly what has to be implemented where, and how possible that is to do. i did not found that information in the clarity and deepth and need. i am not quite sure anymore about the chain of protocols, what is part of libnfc, what is implemented somewhere else, and what is actually missing.
and don't be too shy with "but that seems to be too much work", i looks like i will invest plenty of time in that work, and i want to get crackin' any time soon.
my only real limitation is that i am bound by the project parameters to a OEM usb board (with a crude workaround maybe not even that, but thats definitely not preferred), and the whole thing runs on linux.

PS: i dont want to sound harsh, english is not my first language, so i am not good at being polite and indirect.

9 (edited by nitegate 2011-06-02 10:10:33)

Re: P2P communication between android phone and nfc reader

Hi!

I'm current working on a LLCP/NPP implementation for nfctools for java. It is a real pain to work with nexus s (android 2.3.4). It constantly hangs in all phases of the protocol. After that it is unable to reset itself so I have to deactivate and activate the NFC option in the settings or even reboot the phone.

Yesterday I was able to exchange a NDEF message from the ForegroundNdefPush demo app. I wanted to post my TAMA messages exchange log here, but my editor crashed  sad
Today the app doesn’t work anymore…

I will keep trying and hopefully come back with an update. If you are working on LLCP/NPP please help share your findings to make the communication more stable. Here is what I found out so far:

-    The nexus S is in a constant NDEF push state. As soon as the display is on it will connect to a target and initiate a NFCIP connection.
-    If there is no NDEF message to be sent it will start to exchange SYMMETRY LLCP protocol data units (PDU). This can go on forever (I assume).
-    If you have an NDEF message on the phone, it will send a CONNECT PDU to the service “com.android.npp”, and expect a CONNECT_COMPLETE answer. Then it will send an INFORMATION PDU with the NDEF message which is encapsulated in the NPP format. I answered this with a RECEIVE_READY PDU. After that it will send a DISCONNECT PDU which I answered with a DISCONNECT_MODE PDU.
-    I haven’t successfully send a message which is longer than the 128 byte (maximum exchange unit) so I don’t know how the messages will be split, but this is the moment where my software stopped working yesterday.

Here is some of the stuff that still works:

I’m sending the following data in the TAMA tgInitAsTarget

0000FF27D9 D48C 00 000000000040 01FE01020000000001000000000000000000 01010100000000000000 00 00 5A00

The phone answers with:

0000FF21DF D58D 22 1ED40001FE01020000000000000000003246666D01011003020001040196 8A00

Interesting here is the mode byte 0x22: it says, baudrate 424kbps, DEP no, Felica Mode.
Note also the 46666D LLCP header with the params behind it.

After that I send my general bytes also with the LLCP header and version param:

0000FF08F8 D492 46666D010110 6F00

Then I send a tgGetData:

0000FF02FE D486 A600

And receive a CONNECT PDU:

0000FF16EA D587 00 0521060F636F6D2E616E64726F69642E6E7070 9F00

My answer is CONNECT_COMPLETE PDU via tgSetData:

0000FF04FC D48E 8581 9800

After that I’m stuck right now, because the next tgGetData is answered with

0000FF03FD D587 13 9100

Here you see the 0x13 error code: DEP Protocol/Mifare/ISO-14443-4: The data format does not match the specification
No idea why it is that. Must investigate. Please help if you notice anything strange here.

Re: P2P communication between android phone and nfc reader

I was able to restore my test app and now the complete log is as follows. I removed the checksums and header :

> D48C0001010000004001FE0100000000000000000000000000FFFF01FE01000000000000000646666D01011000
< D58D221ED40001FE01000000000000000000003246666D01011003020001040196
> D49246666D010110
< D59300
> D486
< D587000521060F636F6D2E616E64726F69642E6E7070
> D48E8581
< D58F00
> D486
< D5870007210001000000010100000017D101135402656E4E44454620507573682053616D706C65
> D48E874100
< D58F00
> D486
< D587000561
> D48E85C100
< D58F00

This sends the text "NDEF Push Sample" (line 10) from the android phone to the desktop reader.

I think that the problems before where due to timing issues, but i'm not sure. I'm still not able to receive longer messages.

Re: P2P communication between android phone and nfc reader

I have also been playing with a Nexus S and LLCP+NPP, but using nfcpy. I also share your impressions that the Android NFC stack constantly crashes, but I usually turn the screen off for a while and the stack resets itself as per the phone log.

nfcpy sucessfully establishes a LLCP link with the Nexus S (although I have been using the reader as the initiator). If there is an application running and it has configured the foregroundNdefPush() then the Nexus will immediately try to use the NPP protocol to push the NDEF. I have implemented the NPP protocol and successfully receive this message. Looks like it only tries to push NDEF messages when the LLCP link is established, if the application later uses the foregroundNdefPush() the message will not be sent.

After this the reader can also use the NPP protocol to push NDEFs to the Nexus and these are delivered to the application that has the correct intent registered.

Re: P2P communication between android phone and nfc reader

Thx, EDevil.

Have you found out how an Android App can find out, if an NDEF Push Message was delivered successfully?
This enableForegroundNdefPush approach is quite one-way as it seems.

Re: P2P communication between android phone and nfc reader

I don't think there is a native way to know that. The best you can do is send an ACK from the reader as a NDEF message.

Have you succeeded in sending several messages from the Android to the reader?

Re: P2P communication between android phone and nfc reader

EDevil wrote:

Have you succeeded in sending several messages from the Android to the reader?

If you mean one larger message than 128 bytes then "no".

I'm now able to send messages from the reader to the android phone and vice versa but no larger than 128 bytes.

Re: P2P communication between android phone and nfc reader

What I meant was invoking the pushNDEF from the Android several times in the same session to send several messages. I think Android only pushes NDEFs if they are available when the LLCP link is established. So the only way to send another one would be to teardown and establish LLCP again...

Re: P2P communication between android phone and nfc reader

Ah. ok. I tried this, but it does not work. In the android log I see:

06-02 22:33:58.234: ERROR/NfcService(185): Replacing active NDEF push message

On the LLCP level only SYMM PDUs are exchanged. I think it is not implemented yet.

But I was able to receive and send messages over the same LLCP connection:

06-02 22:41:51.835: INFO/NFC JNI(185): LLCP Link activated (LTO=10, MIU=128, OPTION=0x00, WKS=0x01)
06-02 22:41:51.851: DEBUG/NdefPushClient(185): LLCP connection up and running
06-02 22:41:51.855: DEBUG/NdefPushClient(185): sending foreground
06-02 22:41:51.867: DEBUG/NdefPushClient(185): about to create socket
06-02 22:41:51.874: DEBUG/NdefPushClient(185): about to connect to service com.android.npp
06-02 22:41:51.921: DEBUG/NdefPushClient(185): about to send a 34 byte message
06-02 22:41:51.921: DEBUG/NdefPushClient(185): about to send a 34 byte packet
06-02 22:41:52.003: DEBUG/NdefPushClient(185): about to close
06-02 22:41:52.925: DEBUG/NdefPushServer(185): accept returned com.android.internal.nfc.LlcpSocket@4057db58
06-02 22:41:52.929: DEBUG/NdefPushServer(185): about to accept
06-02 22:41:52.937: DEBUG/NdefPushServer(185): starting connection thread
06-02 22:41:52.945: DEBUG/NdefPushServer(185): read 105 bytes
06-02 22:41:52.957: DEBUG/NFC JNI(185): Socket Disconnected
06-02 22:41:52.964: DEBUG/NdefPushServer(185): connection broken by IOException
06-02 22:41:52.964: DEBUG/NdefPushServer(185): java.io.IOException
06-02 22:41:52.964: DEBUG/NdefPushServer(185):     at com.android.internal.nfc.LlcpSocket.receive(LlcpSocket.java:193)
06-02 22:41:52.964: DEBUG/NdefPushServer(185):     at com.android.nfc.ndefpush.NdefPushServer$ConnectionThread.run(NdefPushServer.java:70)
06-02 22:41:52.968: DEBUG/NdefPushServer(185): got message com.android.nfc.ndefpush.NdefPushProtocol@4057fb10
06-02 22:41:52.972: DEBUG/NfcService(185): mock NDEF tag, starting corresponding activity
06-02 22:41:52.972: DEBUG/NfcService(185): TAG uid = [B@405800e8 Tech [
06-02 22:41:52.976: DEBUG/NdefPushServer(185): about to close
06-02 22:41:52.980: DEBUG/NdefPushServer(185): finished connection thread
06-02 22:41:58.558: INFO/NFC JNI(185): LLCP Link deactivated

First android sends me 34 bytes and than I send 105 bytes without disconnecting the LLCP layer. Basically as soon as I receive the first SYMM PDU I send a CONNECT PDU.

The IOException is strage. To be honest I did not see the NDEF message on my phone wink but the log says "got message..." so it is lost in the system I guess.
More investigations to be done...

Re: P2P communication between android phone and nfc reader

Yes, I can also receive ONE from the phone (which is the first thing that happens when the LLCP link is up), and send multiple to the phone on the same session. I cannot however send multiple NDEF messages from the Android application in the same LLCP session.

18 (edited by MDummy 2011-06-06 14:04:49)

Re: P2P communication between android phone and nfc reader

Hi nitegate!

I face the same problem as you. I have to connect to a galaxy s with a contactless reader (ACR122U). I only have to transmit one single PDU message where a number is stored.

I just downloaded the trunk of your googlecode project nfc-tools. But the last changes are dated with 30.5. Is it possible that you merge your NdefPushServer and NdefPushClient Project to the trunk?

Many thanks, MDummy

Re: P2P communication between android phone and nfc reader

Hello,

mrtj wrote:

more specifically i have a omnikey 5553 usb device, that seems to be not supported in any way by libnfc
(correct if i missed something with that, and if this board is not supported,

You are right, Omnikey 5553 is currently not supported.

mrtj wrote:

what do i have to do to make it compatible with libnfc

You need to wrote a dedicated driver like pn532_uart, pn53x_usb or arygon already presents in libnfc.
The main task is to wrote hardware-dependent functions (ie. nfc_select_passive_target, nfc_deselect_target, etc.) and wrap them using the nfc_driver structure.

mrtj wrote:

I could however maybe able to get a APPB usb device, not sure if with pn531 oder pn532.

This one is supported using arygon driver.

mrtj wrote:

anyway, it seems there are missing pieces, especially for my usb devices, and i like to ask particulary for some kind of roadmap to implement the p2p functionality, meaning more or less exactly what has to be implemented where, and how possible that is to do.

P2P feature relies on DEP support (already implemented in libnfc with PN53x devices) and LLCP, a logical protocol specification provided by NFC-Forum.
Romain has started a project to bring LLCP support to libnfc-enabled device:
http://code.google.com/p/nfc-tools/sour … ibnfc-llcp

I hope its clear and it helps.

Romuald Conty

Re: P2P communication between android phone and nfc reader

Hi MDummy

   I think NdefPushServer and NdefPushCient which Nitegate mentioned are classes of Android Nfc framework, and you can download from github.

MDummy wrote:

Hi nitegate!

I face the same problem as you. I have to connect to a galaxy s with a contactless reader (ACR122U). I only have to transmit one single PDU message where a number is stored.

I just downloaded the trunk of your googlecode project nfc-tools. But the last changes are dated with 30.5. Is it possible that you merge your NdefPushServer and NdefPushClient Project to the trunk?

Many thanks, MDummy

Re: P2P communication between android phone and nfc reader

@guty: Thanks 4 your reply!
If you were right and nitegate uses the android nfc framework, how can he use that framework with an contactless nfc-reader like ACR122? The framework uses native phone functions I think. Do I have this right?

Re: P2P communication between android phone and nfc reader

Nitegate use desktop application to talk with an android phone. Desktop application is based on nfclib and a nfc reader. And the log is debug info of android side.

MDummy wrote:

@guty: Thanks 4 your reply!
If you were right and nitegate uses the android nfc framework, how can he use that framework with an contactless nfc-reader like ACR122? The framework uses native phone functions I think. Do I have this right?

Re: P2P communication between android phone and nfc reader

@guty: Ok, but the desktop application based code isn't published anywhere, right?
Nitegate wrote "I'm current working on a LLCP/NPP implementation for nfctools for java." so he worked with nfctools (which uses nfclib as plattform I think).

@Nitegate: Can you please publish the desktop side code you are using in communicating with the nexus s?

thx, MDummy

Re: P2P communication between android phone and nfc reader

Hey,

guty wrote:

Desktop application is based on nfclib and a nfc reader.

Which desktop application ? and what is nfclib ?

Romuald Conty

Re: P2P communication between android phone and nfc reader

it's libnfc what I meant.
The desktop application is the "object of ambition" of this forum thread i think. Because it's clear how to get the android phone to send a npp message, but the problem is to read that message with an card reader at desktop side!