I have created a HCE service with an AID of F0123412349999. According to the Android HCE documentation, I need to send a SELECT APDU so the HCE service will know which service to redirect the following messages to. here is the APDU I am sending to the phone upon successful connection:
{ 0x00, //CLA
0xA4, //INS
0x00, //P1
0x07, //P2
0x07, //Lc Length Content
0xF0, //Data (AID)
0x12,
0x34,
0x12,
0x34,
0x99,
0x99,
0x00 //Length of data expected
};
The transmit is successful, but what ever I do the android phone returns 0x6f00. This is translated to "No Precise Diagnosis". I have no idea what goes wrong, and apparently the error messages is somewhat vague. The following code is my HCE service:
public class MyHostApduService extends HostApduService {
@Override
public byte[] processCommandApdu(byte[] apdu, Bundle extras) {
Log.i("HCE service", "processCommandApdu");
byte[] answer = new byte[2];
answer[0] = (byte) 0x90;
answer[1] = (byte) 0x00;
return answer;
}
@Override
public void onDeactivated(int reason) {
Log.i("HCE service", "Deactivated: " + reason);
}
@Override
public void onCreate() {
Log.i("HCE service", "Created");
}
}
and the AID registration:
<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
android:description="@string/app_name"
android:requireDeviceUnlock="false" >
<aid-group
android:category="other"
android:description="@string/app_name" >
<aid-filter android:name="F0123412349999" />
<aid-filter android:name="F0394148148100" />
</aid-group>
</host-apdu-service>
And the manifest registration:
<service
android:name=".MyHostApduService"
android:exported="true"
android:permission="android.permission.BIND_NFC_SERVICE" >
<intent-filter>
<action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE" />
</intent-filter>
<meta-data
android:name="android.nfc.cardemulation.host_apdu_service"
android:resource="@xml/apduservice" />
</service>
The reader I am using to read the Android phone is a ACR122 reader. The mobile is a HTC One. one thing that strikes me odd is the ATR that the phone sends on contact with the reader which is 0x3B80800101. I though this would be larger and contain more information, but I might be wrong.
What can I change/fix to make the android send my messages to my HCE service?
The values for the parameters P1 and P2 in the SELECT APDU you are sending to the phone might not be valid. Try the following:
P1 = 0x04
P2 = 0x00
You can check all the parameters for the SELECT command in a document called "Card Specification", published by Global Platform, an industry consortium.