Search code examples
androidarduinonfchcepn532

Emulate Mifare EV2 Card with HCE


So the problem I'm having is the following: I'm trying to emulate the EV2 Card on Android devices using the HCE service by the Android. I have a PN532 (Adafruit) board and a firmware is already installed on it and it uses DESfire native command set. So, processApduCommand() is never called because the command received by the phone is not in APDU format (ISO 7816 - 4). So how much of the native DESfire command set can I implement using the APDU protocol? How can I proceed from here? Thank you all in advance.


Solution

  • You won't be able to emulate a Mifare DESfire native command set, you will only be able to emulate the ISO 7816 - 4 commands and ISO/IEC 7816-4 wrapped native command set.

    You need to change how the PN532 (Adafruit) board sends the commands by wrapping them in ISO 7816 - 4 commands first.

    Wrapping example https://ridrix.wordpress.com/2009/09/19/mifare-desfire-communication-example/

    cls ins          p1 p2 lc [data] le
    90  [native ins] 00 00 lc [data] 00
    
    SW1 SW2
    91  [native status code]
    

    Of course you need to do the AID select commands first to select the AID you are emulating with your HCE implementation.