Our Online Store have the new products: RFID antenna board. Currently it can work with JC10M24R and JCOP4 card chips.
Compared with normal cards, the antenna board module has a smaller size and fixed holes, which is easy to integrate in the IOT(Internet Of Things) project.

Process SELECT command in Android NFC CardService processCommand

JavaCard Applet Development Related Questions and Answers.
User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Process SELECT command in Android NFC CardService processCommand

Post by UNKNwYSHSA » Fri Aug 28, 2015 4:38 am

I write code on android platform, emulate a card using jCardSim, use the NFC interface for communication. Code as follows:

Code: Select all

package com.example.jcardsim_nfc;

import javacard.framework.AID;
import javacard.framework.ISO7816;

import com.licel.jcardsim.base.Simulator;
import com.licel.jcardsim.samples.HelloWorldApplet;

import android.content.Intent;
import android.nfc.cardemulation.HostApduService;
import android.os.Bundle;

public class CardService extends HostApduService {
   private Simulator _theSimulator;
   private AID _theAppletAID;
   
   @Override
   public byte[] processCommandApdu(byte[] commandApdu, Bundle extras) {
      // TODO Auto-generated method stub
      Intent broadcastIntent = new Intent("APDU_LOG_CHANGING");
      broadcastIntent.putExtra("commandApdu", commandApdu);
      sendBroadcast(broadcastIntent);
      
      if (_theSimulator != null) {
         if ((commandApdu[ISO7816.OFFSET_INS] == (byte) 0xA4) && (commandApdu[ISO7816.OFFSET_P1] == 0x04) && (commandApdu[ISO7816.OFFSET_P2] == 0x00)) {
            if (_theSimulator.selectApplet(_theAppletAID)) {
               return new byte[] { (byte) 0x90, 0x00 };
            } else {
               return new byte[] { 0x6F, 0x00 };
            }
            
         } else {
            byte[] rspApdu = _theSimulator.transmitCommand(commandApdu);
            
            Intent broadcastIntent2 = new Intent("APDU_LOG_CHANGING");
            broadcastIntent2.putExtra("rspApdu", rspApdu);
            sendBroadcast(broadcastIntent2);
            
            return rspApdu;
         }
      }
      
      return null;
   }

   @Override
   public void onDeactivated(int reason) {
      // TODO Auto-generated method stub

      Intent broadcastIntent = new Intent("DEBUG_INFO");
      broadcastIntent.putExtra("debugInfo", "CardService deactivated;");
      sendBroadcast(broadcastIntent);
   }
   
   @Override
   public void onCreate() {
      // TODO Auto-generated method stub
      super.onCreate();
      
      _theSimulator = new Simulator();
      byte[] aidBytes = new byte[] {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09};
      _theAppletAID = new AID(aidBytes, (short)0, (byte)aidBytes.length);
      _theSimulator.installApplet(_theAppletAID, HelloWorldApplet.class);
      
      Intent broadcastIntent = new Intent("DEBUG_INFO");
      broadcastIntent.putExtra("debugInfo", "CardService created;");
      sendBroadcast(broadcastIntent);
   }

}

I can transmit apdu normally. But i always feel bad processing of SELECT instruction. How do you think?
sense and simplicity

predators
Posts: 21
Joined: Wed Aug 19, 2015 7:18 am
Points :12
Contact:

Re: Process SELECT command in Android NFC CardService processCommand

Post by predators » Wed Nov 04, 2015 8:34 am

The method you are using is the only method that I know.

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 55 guests

JavaCard OS : Disclaimer