Search code examples
androidnfcemv

Android/NFC: read ATR from Smartcard (EMV)


I got an EMV Smartcard wich I want to communicate with with my Mobile phone. The communication itself works without problems via IsoDep, but I can't figure out how I can get the ATR. As far as I know the intent should contain the ATR, can someone please tell me the code I need therefore?

Or if this is not possible maybe someone knows how to warm reset the card with a command like SELECT where the answer is the ATR.


Solution

  • Contactless cards do not have an ATR. You may be interested in the historical bytes of the ATS (Answer to Select), though. You can retrieve these by calling getHistoricalBytes():

    Tag tag = (Tag) intent.getParcelableExtra(NfcAdapter.EXTRA_TAG));
    IsoDep iso = IsoDep.get(tag);
    NfcA nfcA = NfcA.get(tag);
    if (nfcA == null || iso == null)
       return; // not an IsoDep+NfcA tag
    byte[] histBytes = iso.getHistoricalBytes();
    ...
    

    Keep in mind that this only works for ISO 14443 Type A tags (NfcA). For Type B tags (NfcB), you may want to investigate getHiLayerResponse().