Search code examples
androidnfcnfc-p2pandroid-beamacr122

How to a send SNEP GET request from Android


I have an NFC reader ACS ACR122U and I want to send data from my Android phone to it.

I have found many examples on how to connect my two devices in P2P mode and how to send data from my phone to the ACR122U, but my desktop server (ACR122U) always receives a SNEP PUT request. I would send a GET request but I can find only examples that use Android built in NDEF system without specifing PUT or GET request.

How can I package and send a SNEP GET request from my Android device to an ACR122U?


Solution

  • Short answer: You can't.

    The Android API does not allow you to implement custom LLCP services. The only LLCP services implemented on Android devices are the NFC Forum Default SNEP Server (service name urn:nfc:sn:snep, service access point address 4) and, for legacy reasons, the Android NDEF push protocol (similar to SNEP but dates back to times before the SNEP specification was published).

    While the SNEP protocol specification defines a GET request to pull an NDEF message from another device, the NFC Forum Default SNEP Server is defined to only accept PUT requests. GET requests must be rejected by that SNEP server.

    From the NFC Forum Simple NDEF Exchange Protocol technical specification (Version 1.0):

    The default SNEP server provides a logical inbox. A client connected to the default server can place NDEF messages into the inbox using Put request messages. [...]

    The default server SHALL NOT accept Get requests. The appropriate response for a Get request message is Not Implemented.

    So you can only push NDEF messages to the NFC Forum Default SNEP Server and not the other way round.

    Hence, if you want to send an NDEF message to an Android device through peer-to-peer mode, you need to implement a SNEP client on the ACR122U side. You can then let that client connect to the SNEP server on the Android device (at service name urn:nfc:sn:snep) and push the NDEF message to it using a PUT request.

    If you want to receive an NDEF message from an Android device through peer-to-peer mode, you need to implement a SNEP server on the ACR122U side. The Android SNEP client will then connect to your SNEP server and push the waiting NDEF message (e.g. registered through NfcAdapter.setNdefPushMessage()) to it using, again, a PUT request.