简体   繁体   中英

Getting TagLostException when sending SELECT PPSE command

I'm getting a tag lost exception when sending SELECT PPSE command using the tag's transceive method.

The intent is passed to readTag and the method is getting the tag from the intent but calling the transceive method for the SELECT PPSE command APDU results in a tag lost exception instead of getting the Response APDU message:

public void readTag(Intent intent) {
    String action = intent.getAction();
    if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) {
        System.out.println("Got the tag");
        Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        NfcA mfc = NfcA.get(tagFromIntent);
        System.out.println(mfc);
        try {
            mfc.connect();
            System.out.println(mfc.getTag());
            System.out.println(mfc.getClass());
            byte[] ATQA = mfc.getAtqa();
            System.out.println(getHexString(ATQA));
            System.out.println(mfc.getMaxTransceiveLength());
            mfc.setTimeout(500000);

            String value = "00A404000e325041592e5359532e444446303100"; //PPSE APDU value
            String hex = value.toString();
            byte[] data = HexToByte(hex);
            byte[] response = mfc.transceive(data); //sending request
            System.out.println(getHexString(response));
            mfc.close();
        } catch(Exception e) {
            Toast.makeText(getBaseContext(), e.getMessage(),
                           Toast.LENGTH_SHORT).show();
        }
    }
}

The tag technology NfcA (and also NfcB ) is for communicating using ISO 14443-3 proprietary command sets. APDUs are typically sent on top of ISO-DEP / T=CL (ISO 14443-4 transmission protocol), so you would want to use IsoDep tag technology instead of NfcA .

Also you might want to use a slightly lower timeout value. Typically a value in the order of 1 to 10 seconds should be enough (by far) -- unless you trigger some complex operations on the smartcard.

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