Using a Nexus 4 and the latest Android API level 18 to communicate with a Mifare DESFire EV1 AES tag is giving me a headache. Following the NXP native protocol in order to write and read this type of tag, these steps must be followed:
- Select application
- Authenticate
- Write or Read
To do it so, I use Android's IsoDep class which provides access to ISO 14443-4 properties and I/O operations. The very weird thing about it is that once I send the select application native command I get an unexpected response. Imagine I have the AID F4013D
so I send:
-> 5AF4013D
<- 6E00
All possible responses must be one byte length (success 0x00
or error_code) and never two or more. Thus, the 0x6E
before the success response is absolutely unexpected. It does not happen always, and when it does not and works fine, the select application and authentication processes work fine. However once authenticated the write command does not have a correct behavior, all write commands finishes with a 0xAF
from the PICC instead of a success 0x00
. It seems like the PICC expect some extra data when it should not (I send the correct length payload). If I send any other command I get a 0xCA
(Command Aborted) error code.
-> 5AF4013D
<- 00 /*Success*/
-> AA01
<- AFA8394ED57A5E83106B4EE72FD2BB0CC4
-> AF148F525E1DDE0AD6AB60B4B615552475C91F2E8D89B8523E4465113DD5BD19C6
<- 0066D255C93F2F492AFE3715C88964F1BD /*Authentication success*/
-> 3D02000000030000222222 /*Write 3 bytes to file nº2*/
<- AF /*Unexpected, 0x00 was expected*/
As it is normal, if I send these type of commands with a personal reader (non Android NFC) it always works fine. It seems that something in the Android NFC API is going strange, when it should just be a raw data transporter which never interprets or modifies data.
I have also tried with ISO 7816-4 APDU structure with the same result. As a curiosity, with a Galaxy Nexus does not happen the select application strange response, but yes the write command one always.
(1)
If I'm not wrong, the PICC will always response in a communication type you establish by the first command. In my case, if I send a5AF4013D
command it will be native and no wrapped communication. In this scenario the answer will always be 1 byte long. In case of Android had stablished a previous contact with the PICC in wrapped format (apart from being an huge error),IMHO It would never understand my native command, and less answer with a success.(2)
That would make sense, but I have set the communication settings to plain since the beginning. – Haemal