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?