I'm trying to do Host card emulation on an Android device using this example using ACR1281U NFC tag reader.
This is the kind of application I want to make.
As per the Android documentation and the example, it is required to register an AID in the Android project:
<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
android:description="@string/servicedesc"
android:requireDeviceUnlock="false">
<aid-group android:description="@string/aiddescription"
android:category="other">
<aid-filter android:name="F0010203040506"/>
<aid-filter android:name="F0394148148100"/>
</aid-group>
</host-apdu-service>
How do I know which AID I need to register in my Android application so that the reader can read the HCE Android app?
Here is another question I posted regarding the same: No supported card terminal found ARC1281U nfc card reader
I have referred to the following links, but there were not of much help:
- Setting up host card emulation
- To get Application ID for NFC based Identification System
- How does Host-based Card Emulation deal with AID (Application ID)?
- Android HCE: are there rules for AID?
Please help as there is very little resources available on HCE!
EDIT
The example uses the AID F0010203040506
in the SELECT (by AID) command but my ACR128 reader was unable to read the HCE device.
private static final byte[] CLA_INS_P1_P2 = { 0x00, (byte)0xA4, 0x04, 0x00 };
private static final byte[] AID_ANDROID = { (byte)0xF0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
private byte[] createSelectAidApdu(byte[] aid) {
byte[] result = new byte[6 + aid.length];
System.arraycopy(CLA_INS_P1_P2, 0, result, 0, CLA_INS_P1_P2.length);
result[4] = (byte)aid.length;
System.arraycopy(aid, 0, result, 5, aid.length);
result[result.length - 1] = 0;
return result;
}
Then I changed the AID to F00000000A0101
(which was used by some other example app) and used this in AID filter as well. After changing to this AID, the ACR reader was able to detect the HCE device.
- Both of the AIDs (the one used in example that did not work and another that was used in the app which worked) conform to the specification, how to I know which AID to use?
- The example adds multiple AIDs in the AID filter but sends only one of them in the SELECT (by AID) APDU. Should I also add multiple AIDs in the AID filter? What is its use?