Example usage for android.nfc.tech NfcA getAtqa

List of usage examples for android.nfc.tech NfcA getAtqa

Introduction

In this page you can find the example usage for android.nfc.tech NfcA getAtqa.

Prototype

public byte[] getAtqa() 

Source Link

Document

Return the ATQA/SENS_RES bytes from tag discovery.

Usage

From source file:de.syss.MifareClassicTool.Common.java

/**
 * Check if the tag and the device support the Mifare Classic technology.
 * @param tag The tag to check./* www  .j  a  v a  2 s  .  c  om*/
 * @param context The context of the package manager.
 * @return
 * <ul>
 * <li>0 - Device and tag support Mifare Classic.</li>
 * <li>-1 - Device does not support Mifare Classic.</li>
 * <li>-2 - Tag does not support Mifare Classic.</li>
 * <li>-3 - Error (tag or context is null).</li>
 * </ul>
 */
public static int checkMifareClassicSupport(Tag tag, Context context) {
    if (tag == null || context == null) {
        // Error.
        return -3;
    }

    if (Arrays.asList(tag.getTechList()).contains(MifareClassic.class.getName())) {
        // Device and tag support Mifare Classic.
        return 0;

        // This is no longer valid. There are some devices (e.g. LG's F60)
        // that have this system feature but no Mifare Classic support.
        // (The F60 has a Broadcom NFC controller.)
        /*
        } else if (context.getPackageManager().hasSystemFeature(
        "com.nxp.mifare")){
            // Tag does not support Mifare Classic.
            return -2;
        */

    } else {
        // Check if device does not support Mifare Classic.
        // For doing so, check if the ATQA + SAK of the tag indicate that
        // it's a Mifare Classic tag.
        // See: http://www.nxp.com/documents/application_note/AN10833.pdf
        // (Table 5 and 6)
        // 0x28 is for some emulated tags.
        NfcA nfca = NfcA.get(tag);
        byte[] atqa = nfca.getAtqa();
        if (atqa[1] == 0
                && (atqa[0] == 4 || atqa[0] == (byte) 0x44 || atqa[0] == 2 || atqa[0] == (byte) 0x42)) {
            // ATQA says it is most likely a Mifare Classic tag.
            byte sak = (byte) nfca.getSak();
            if (sak == 8 || sak == 9 || sak == (byte) 0x18 || sak == (byte) 0x88 || sak == (byte) 0x28) {
                // SAK says it is most likely a Mifare Classic tag.
                // --> Device does not support Mifare Classic.
                return -1;
            }
        }
        // Nope, it's not the device (most likely).
        // The tag does not support Mifare Classic.
        return -2;
    }
}

From source file:net.zjy.zxcardumper.Common.java

/**
 * Check if the tag and the device support the MIFARE Classic technology.
 * @param tag The tag to check./* ww w. j  av a2  s  .com*/
 * @param context The context of the package manager.
 * @return
 * <ul>
 * <li>0 - Device and tag support MIFARE Classic.</li>
 * <li>-1 - Device does not support MIFARE Classic.</li>
 * <li>-2 - Tag does not support MIFARE Classic.</li>
 * <li>-3 - Error (tag or context is null).</li>
 * </ul>
 */
public static int checkMifareClassicSupport(Tag tag, Context context) {
    if (tag == null || context == null) {
        // Error.
        return -3;
    }

    if (Arrays.asList(tag.getTechList()).contains(MifareClassic.class.getName())) {
        // Device and tag support MIFARE Classic.
        return 0;

        // This is no longer valid. There are some devices (e.g. LG's F60)
        // that have this system feature but no MIFARE Classic support.
        // (The F60 has a Broadcom NFC controller.)
        /*
        } else if (context.getPackageManager().hasSystemFeature(
        "com.nxp.mifare")){
            // Tag does not support MIFARE Classic.
            return -2;
        */

    } else {
        // Check if device does not support MIFARE Classic.
        // For doing so, check if the ATQA + SAK of the tag indicate that
        // it's a MIFARE Classic tag.
        // See: http://www.nxp.com/documents/application_note/AN10833.pdf
        // (Table 5 and 6)
        // 0x28 is for some emulated tags.
        NfcA nfca = NfcA.get(tag);
        byte[] atqa = nfca.getAtqa();
        if (atqa[1] == 0
                && (atqa[0] == 4 || atqa[0] == (byte) 0x44 || atqa[0] == 2 || atqa[0] == (byte) 0x42)) {
            // ATQA says it is most likely a MIFARE Classic tag.
            byte sak = (byte) nfca.getSak();
            if (sak == 8 || sak == 9 || sak == (byte) 0x18 || sak == (byte) 0x88 || sak == (byte) 0x28) {
                // SAK says it is most likely a MIFARE Classic tag.
                // --> Device does not support MIFARE Classic.
                return -1;
            }
        }
        // Nope, it's not the device (most likely).
        // The tag does not support MIFARE Classic.
        return -2;
    }
}