简体   繁体   中英

TagLostException IsoDep Android Java card

I'm working with a Java card using Android IsoDep. I have already set the timeout to 50000 milliseconds. I also calculated the duration the NFC connection was opened and it was just over 6 seconds.
I put the card on my table and put my phone on top of it and I didn't touch either through the process so there is no chance the card could be removed physically.

Any idea why this is happening?

My code:

try {
    if (nfc.isConnected()) {
        DLog.w(TAG, "exchange() - connected");

        byte[] resp = nfc.transceive(apdu);

        // ...
    } else {
        // ...
        close();
    }
} catch (TagLostException e) {
    DLog.e(TAG, "card was removed", e);
    close();
    // ...
}
catch (IOException e) {
    close();
    // ...
}  

The exception:

01-08 09:54:54.721: E/IsoDepSecureHandler(11221): android.nfc.TagLostException: Tag was lost.
01-08 09:54:54.721: E/IsoDepSecureHandler(11221):   at android.nfc.TransceiveResult.getResponseOrThrow(TransceiveResult.java:48)
01-08 09:54:54.721: E/IsoDepSecureHandler(11221):   at android.nfc.tech.BasicTagTechnology.transceive(BasicTagTechnology.java:151)
01-08 09:54:54.721: E/IsoDepSecureHandler(11221):   at android.nfc.tech.IsoDep.transceive(IsoDep.java:172)

The particular command that it failed to execute is 80460000400000271020363630303030303030353138323133303134333666383639383063022b100141000100000000000000000036364ed930284231adbc6c525e9f0abd

However, the same command was executed just fine when I use a contactless reader that connect to my phone. Note that the command can only executed as long as I don't repeat the process and generate new security parameters (some other APDU commands were sent to the card prior to this one). Once new the security parameters are generated, the above command does not work anymore; therefore, 6982 will be returned.

tbellenger suggested adding 00 to the end of the command but that doesn't work, even with the smartcard reader as 6985 is returned.

Try adding '00' to the end of your APDU. This is sometimes required. Don't modify 'LC' from '40' - just add the zero byte. I think this is required in T=CL or T=1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM