Configure Host Card Emulation

I'm currently trying to connect between Arduino UNO and NFC Shield to my Nexus 4 running Android 4.4.

I have a service setup, it just logs in at the moment. The problem is that the intent of NFC is not related to my application. The debugger reports the following error:

11-24 02:45:46.139 4006-4027/? E/BrcmNfcNfa﹕ UICC[0x0] is not activated 

So here are my 2 questions:

  • On the Arduino side of things, what kind of “message” does the NFC screen need to send to my phone for my phone to understand that I'm looking for a specific application in the “Other” category?

  • As for the Android side, what will be the meaning of the help filter tag to catch this intention? Can I make my own or do I need to adhere to some ISO specification for this to work?

UPDATE

OK, so here is the relevant part of my Arduino sketch, where I create the APDU:

  uint8_t message[5]; message[0] = 0x00; message[1] = 0xA4; message[2] = 0x04; message[3] = 0x00; message[4] = 0x08; message[5] = 0x4C656C616E746F73ULL; 

And here is the APDU service XML file in my Android application:

 <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="4C656C616E746F73"/> </aid-group> </host-apdu-service> 

And this is the log I get when I pointed my phone to the NFC screen:

 11-24 22:33:40.563 4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: event=0x18 11-24 22:33:40.563 4006-4027/? D/HostEmulationManager﹕ notifyHostEmulationActivated 11-24 22:33:40.563 4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: event=0x17 11-24 22:33:40.563 4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: NFA_CE_DATA_EVT; h=0x302; data len=5 11-24 22:33:40.563 4006-4027/? D/HostEmulationManager﹕ notifyHostEmulationData 11-24 22:33:40.563 4006-4027/? D/HostEmulationManager﹕ Dropping non-select APDU in STATE_W4_SELECT 11-24 22:33:40.683 4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: event=0x17 11-24 22:33:40.683 4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: NFA_CE_DATA_EVT; h=0x302; data len=5 11-24 22:33:40.683 4006-4027/? D/HostEmulationManager﹕ notifyHostEmulationData 11-24 22:33:40.683 4006-4027/? D/HostEmulationManager﹕ Dropping non-select APDU in STATE_W4_SELECT 11-24 22:33:40.804 4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: event=0x17 11-24 22:33:40.804 4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: NFA_CE_DATA_EVT; h=0x302; data len=5 11-24 22:33:40.804 4006-4027/? D/HostEmulationManager﹕ notifyHostEmulationData 11-24 22:33:40.804 4006-4027/? D/HostEmulationManager﹕ Dropping non-select APDU in STATE_W4_SELECT 11-24 22:33:40.924 4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: event=0x17 11-24 22:33:40.924 4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: NFA_CE_DATA_EVT; h=0x302; data len=5 11-24 22:33:40.934 4006-4027/? D/HostEmulationManager﹕ notifyHostEmulationData 11-24 22:33:40.934 4006-4027/? D/HostEmulationManager﹕ Dropping non-select APDU in STATE_W4_SELECT 11-24 22:33:41.054 4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: event=0x17 11-24 22:33:41.054 4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: NFA_CE_DATA_EVT; h=0x302; data len=5 11-24 22:33:41.054 4006-4027/? D/HostEmulationManager﹕ notifyHostEmulationData 11-24 22:33:41.054 4006-4027/? D/HostEmulationManager﹕ Dropping non-select APDU in STATE_W4_SELECT 11-24 22:33:41.174 4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: event=0x17 11-24 22:33:41.174 4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: NFA_CE_DATA_EVT; h=0x302; data len=5 11-24 22:33:41.174 4006-4027/? D/HostEmulationManager﹕ notifyHostEmulationData 11-24 22:33:41.174 4006-4027/? D/HostEmulationManager﹕ Dropping non-select APDU in STATE_W4_SELECT 11-24 22:33:41.304 4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: event=0x19 11-24 22:33:41.304 4006-4027/? D/HostEmulationManager﹕ notifyHostEmulationDeactivated 11-24 22:33:41.304 4006-4027/? E/BrcmNfcNfa﹕ UICC[0x0] is not activated 

Why doesn't Android redirect APDUs to my HCE service?

+1
android arduino nfc hce apdu
source share
3 answers

Do you understand that

 uint8_t message[5]; message[0] = 0x00; message[1] = 0xA4; message[2] = 0x04; message[3] = 0x00; message[4] = 0x08; message[5] = 0x4C656C616E746F73ULL; 

will actually result in an array that looks like this:

 uint8_t message[] = { 0x00, 0xA4, 0x04, 0x00, 0x08, 0x73 }; 

This means that the rest of your AID ( 0x4C , 0x65 , 0x6C , 0x61 , 0x6E , 0x74 , 0x6F ) is effectively trimmed and therefore your APDU also has the wrong length field (Lc).

So, you can format SELECT APDU correctly:

 uint8_t message[] = { 0x00, /* CLA */ 0xA4, /* INS */ 0x04, /* P1 */ 0x00, /* P2 */ 0x08, /* Lc */ 0x4C, 0x65, 0x6C, 0x61, 0x6E, 0x74, 0x6F, 0x73, 0x00 /* Le */ }; 

In addition, I suggest that you use the AID of the form Fxxxxxxxxx... (that is, the top nibble of the first byte set to 0xF , length from 5 to 16 bytes) indicating the patented unregistered AID, otherwise you may encounter other standard applications. See ISO / IEC 7816-4 for more information on proper AID formatting.

+4
source share

This can be done by choosing AID = "F0394148148100", which is within the margin of the proprietary range i. e. bits 8-5 of the first byte shall be set to "1". which is "F", then use the AID in the APDU of Arudino as follows.

  private static byte[] AID={ (byte)0x00 , (byte)0xA4 , (byte)0x04 , (byte)0x00 , (byte)0x07 , (byte)0xF0, (byte)0x39, (byte)0x41, (byte)0x48, (byte)0x14, (byte)0x81, (byte)0x00 , (byte)0x00 }; 

Then use this AID in apduxml which looks like this

 <host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android" android:description="@string/ServiceMe" android:requireDeviceUnlock="false"> <aid-group android:description="@string/NfcService" android:category="other"> <aid-filter android:name="F0394148148100"/> </aid-group> </host-apdu-service> 

then use the service that is defined in the manifest service tag of your application

 public class MyHostApduService extends HostApduService { @Override public void onDeactivated(int reason) { // TODO Auto-generated method stub } @Override public byte[] processCommandApdu(byte[] commandApdu, Bundle extras) { // TODO Auto-generated method stub String n1="Hi there this is working"; byte[] response=n1.getBytes(); System.err.println(response); return response; } } 

then get the APDU response and get the string as a result.

+1
source share
  • AID must meet the ISO criteria for length, for example: android filter: name = "F0010203040506"
  • Arduino needs to send a well formatted APDU to the Nexus. (CLK / BLU / P1 / P2 / Len)
  • regarding error: this means that your messages are forwarded to UICC. This may be the case if the HCE application does not determine the correct AID that you select with the Aduino Board.

An example here ( http://developer.android.com/guide/topics/connectivity/nfc/hce.html ) works out of the box.

0
source share

All Articles