Writing data to Nexus 4 in card emulation mode with ACR122

I am trying to send some data to Nexus 4 via NFC (i.e. card emulation mode). I tried several APDU commands, such as writing and updating APDUs, but I could not get them to work.

I'm trying to say that I want to send some data (not AID) to the phone after selecting the APDU command.

Thanks in advance,

Bader

-1
source share
1 answer

The HCE emulated card will understand exactly the commands that your HCE application APDU service processes. So, for example, if your processCommandApdu() service processCommandApdu() service callback method looks like this:

 final static byte[] SW_NO_ERROR = new byte[]{ (byte)0x90, (byte)0x00 }; final static byte[] SW_INCORRECT_P1P2 = new byte[]{ (byte)0x6A, (byte)0x86 }; final static byte[] SW_INS_NOT_SUPPORTED = new byte[]{ (byte)0x6D, (byte)0x00 }; final static byte[] SW_ERR_UNKNOWN = new byte[]{ (byte)0x6F, (byte)0x00 }; @Override public byte[] processCommandApdu(byte[] apdu, Bundle extras) { if (apdu.length >= 4) { if ((apdu[1] == (byte)0xA4) && (apdu[2] == (byte)0x04)) { // SELECT APPLICATION return SW_NO_ERROR; } else if ((apdu[1] == (byte)0xCA) && (apdu[2] == (byte)0x02)) { // GET DATA (SIMPLE TLV) switch (apdu[3] & 0x0FF) { case 0x001: return new byte[]{ apdu[3], (byte)0x02, (byte)0x01, (byte)0x00, (byte)0x90, (byte)0x00 }; case 0x002: return new byte[]{ apdu[3], (byte)0x02, (byte)0x12, (byte)0x34, (byte)0x90, (byte)0x00 }; case 0x003: return new byte[]{ apdu[3], (byte)0x06, (byte)0xAA, (byte)0xBB, (byte)0xCC, (byte)0xDD, (byte)0xEE, (byte)0xFF, (byte)0x90, (byte)0x00 }; default: return SW_INCORRECT_P1P2; } } else { return SW_INS_NOT_SUPPORTED; } } return SW_ERR_UNKNOWN; } 

Your HCE application will understand the following APDU command:

  • SELECT APPLICATION (by AID)

     00 A4 04 xx ... 
  • GET DATA for data object 0201

     00 CA 02 01 00 
  • GET DATA for data object 0202

     00 CA 02 02 00 
  • GET DATA for data object 0203

     00 CA 02 03 00 

Other commands will lead to various errors.

+1
source

Source: https://habr.com/ru/post/1269616/


All Articles