Android ACR122U NFC integration
Asked Answered
L

0

3

See NFC reader "SELECT (by AID)" APDU is not routed to Android device on debugging and eventual results. TL;DR the reader might simply be defunct.


I have ACR122U reader connected to my Android device. My final goal is to use another Android device in HCE mode to enable data communication between the devices.

Currently I have a problem with integrating with ACR122U reader. I use lib acssmc-1.1.1.jar provider by the vendor. This is the code I currently have (omitting the example code of opening the reader).

mReader.power(slotNum, Reader.CARD_WARM_RESET);
mReader.setProtocol(slotNum, Reader.PROTOCOL_T0 | Reader.PROTOCOL_T1);

//FF 00 00 00 04 D4 4A 01 00 00 - Polling for the ISO14443-4 A ??
byte[] w = new byte[255];
int len = mReader.transmit(0, new byte[] { (byte)0xFF, 0x00, 0x00, 0x00, 0x04,(byte)0xD4, 0x4A, 0x01, 0x00}, 9, w, w.length);
Log.e("Response", "r: " + NfcUtils.convertBinToASCII(w, 0, len));

//00 A4 04 00 07 F0 01 02 03 04 05 07 00 - Select AID APDU
w = new byte[255];
mReader.transmit(0, new byte[] {0x00, (byte) 0xA4, 0x04, 0x00, 7,
    (byte)0xF0, 0x01, 0x02, 0x03, 0x04, (byte) 0x05, 0x07, 0}, 13, w, w.length);
Log.e("Response", "r: " + Arrays.toString (recvBuffer));

If I tap a tag to the NFC reader this is the output I get

r: D54B0101440004048853606A9000
r: lots of zeroes

When I tap an Android device this is the response:

r: D54B6300
r: lots of zeroes

basically it fails on the polling stage (?). On the Android device I have a basic HostAdpuService implementation:

public class MyHostApduService extends HostApduService {

    @Override
    public void onCreate() {
        super.onCreate();
        Log.e("APDU", "APDU service was created.");
    }

    @Override
    public byte[] processCommandApdu(byte[] apdu, Bundle extras) {
       Log.e("APDU", "command apdu: " + Arrays.toString(apdu));
       return new byte[2];
    }
    @Override
    public void onDeactivated(int reason) {
       Log.e("APDU", "ON DEACTIVATED.");
    }
}

processCommandApdu never got called. Looking through the logs of an Android device I can't find anything relevant at the moment when I tap the device.

I went through several examples online and wasn't able to make it work on other (not Android) platforms (Windows, OSX) as well.

Lagena answered 11/5, 2018 at 14:51 Comment(2)
You have turned NFC on right?Kironde
Yes, NFC is turned on, and this service is actually launched when I tap it to another Android device which sends select aid APDU, so I believe it's not the hce service problemLagena

© 2022 - 2024 — McMap. All rights reserved.