Android NFC transceive() using NFCF tech (Sony Felica)
android, nfc
Solution
Here is an example function of how to send a "raw" command, given the target device (tag) IDm, 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);
}
Problem
I am attempting to connect my Android tablet to a device using NFC and retrieve data from the device. What I've Tried Sending commands as it explains in the nfc_device_detection_1.01.pdf (Chapter 4) The android java doc for transceive() mentions the "Applications must not append the SoD (length) or EoD (CRC) to the payload, it will be automatically calculated" I have therefore tried with and without the CRC, with and without the packet data length but the documentation is not clear on if I should leave it blank or if i should just not include it. Another approach I have taken is following the diagram in chapter 2.2 of format_sequence_guidelines_1.1.pdf (Sync Code followed by Request) but same results. The problem I do not know what command (bytes) to send as an argument into the transceive() method.** Questions Does anyone: - have an example of NFCF communication? - have more information on the protocol/command that should be used? - know if the NFC Tag contain the bytes I need for the command? Code transceive() throws an IO Exception "Tag was lost". I believe this is because my command bytes are not correct (I have used a range of different commands). Last Note (I have also tired putting the transceive() in a while loop and closed and connected the communication each 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 for your answers. Thank you.