Android NFC transceive () using NFCF technology (Sony Felica)

I am trying to connect an Android tablet to a device using NFC and retrieve data from the device.

What i tried

Sending commands, as explained in nfc_device_detection_1.01.pdf (chapter 4)

Android java doc for transceive () mentions

"Applications should not add SoD (length) or EoD (CRC) to the payload, they will be automatically calculated"

So I tried with and without CRC, with and without packet length, but the documentation is unclear if I should leave it empty or I just shouldn't include it.

Another approach I took is following the diagram in chapter 2.2 format_sequence_guidelines_1.1.pdf (the synchronization code followed by the request), but the same results.

Problem

I do not know which command (bytes) to send as an argument to the transceive () method. **

Questions

Someone:

  • Is there an example of NFCF exchange?
  • is there any additional protocol / command information to be used?
  • to know if the NFC tag contains the bytes I need for the command?

The code

transceive () throws an IO exception "The tag was lost."

I believe this is because my command bytes are incorrect (I used a number of different commands).

Last note (I am also tired of putting transceive () in a while loop and closing and connecting the connection every time)

String action = intent.getAction(); if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) { Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); NfcF nfcf = NfcF.get(tag); nfcf.connect(); byte[] command = new byte[] { (byte) 0x00, (byte) 0x00}; byte[] response = nfcf.transceive(command); } 

Please comment if any additional information is required to receive answers. Thanks.

+4
source share
2 answers

Here is an example of a raw command sending function, taking into account the IDm of the target device (tag), the FeliCa command byte and the payload:

 byte[] rawCmd(NfcF nfcF, byte[] IDm, byte felicaCmd, byte[] payload) throws IOException { final int len = payload != null ? payload.length : 0; final byte[] cmd = new byte[10 + len]; cmd[0] = (byte) (10 + len); cmd[1] = felicaCmd; System.arraycopy(IDm, 0, cmd, 2, IDm.length); if (payload != null) { System.arraycopy(payload, 0, cmd, 10, payload.length); } nfcF.transceive(cmd); } 
+3
source

I hope this can help someone in the future.

 byte[] transceiveProtocol(NfcF nfcF, int systemCode, int requestCode, int timeSlot) { byte d0 = 6; byte d1 = 0; byte d2 = (byte)(systemCode>> 8 & 0xFF); byte d3 = (byte)(systemCode>> 0 & 0xFF); byte d4 = (byte)(requestCode & 0xFF); byte d5 = (byte)(timeSlot & 0xFF); byte[] command = { d0, d1, d2, d3, d4, d5 }; return nfcF.transceive(command); } 
0
source

Source: https://habr.com/ru/post/1494690/


All Articles