ip696
ip696

Reputation: 7104

How can I make SELECT command from concret AID on Smart Card with Android NFC

I try read data from smart card by NFC and Android.

I have smart card with application. Application has AID(Application ID) A0000006581010

I need make SELECT command and read result.

I write method:

private static final String SAMPLE_LOYALTY_CARD_AID = "F222222222";

private void performTransaction(Intent nfcIntent) {
        Tag tagFromIntent = nfcIntent.getParcelableExtra(EXTRA_TAG);
        NfcA mNfc = NfcA.get(tagFromIntent);
        try {
            mNfc.connect();

            //I can read ID
            byte[] id = mNfc.getTag().getId();

            //I tried create SELECT command
            byte[] selCommand = BuildSelectApdu(SAMPLE_LOYALTY_CARD_AID);
            //I try send command to card
            byte[] result = mNfc.transceive(selCommand);
            //I get result == {106, -126}
        } catch (IOException e) {
            Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
        } finally {
            if (mNfc != null) {
                try {
                    mNfc.close();
                } catch (IOException e) {
                    Log.v("tag", "error closing the tag");
                }
            }
        }
    }

How can I make SELECT command from concret AID on Smart Card?

Upvotes: 0

Views: 2556

Answers (1)

mictter
mictter

Reputation: 1418

SELECT is a standard APDU command, you can find a specification that defines it from Global Platform. Building it from an AID is quite mechanical:

00A40400 + AID lenght in hexadecimal + AID + 00

For example, for your AID of A0000006581010 the SELECT command is:

00A4040007A000000658101000

Upvotes: 4

Related Questions