This is the code for the JAR file in order to emulate a smartcard (JavaCard) in the Nokia 6131 Emulator (no other emulator is supporting this example!). Click in the emulator on Internal Secure Card => Edit => and then chose the JAR compiled out of this code. Download appropriate NetBeans Project: File:TicketEmulation6131.zip.
package at.nfcresearch.wima.examples;
import com.nokia.phone.sdk.concept.srv.modules.nfc.cards.SecureCard;
public class TicketSmartCard extends SecureCard {
// Command (APDU INS) for increading the value in the wallet
private final static byte INS_INC = 0x01;
// Command (APDU INS) for decreading the value in the wallet
private final static byte INS_DEC = 0x02;
// command (APDU INS) for reading the value in the wallet
private final static byte INS_READ = 0x03;
// variable holding the amount stored in the wallet.
private byte value = (byte) 0x20;
private static byte APDU_OK[] = {(byte) 0x90, 0x00};
private static byte APDU_NOT_OK[] = {0x69, 0x00};
public TicketSmartCard() {
super();
}
public byte[] exchangeData(byte[] buf) {
byte cmd = buf[1];
switch (cmd) {
case INS_INC:
if (value < 0xff) {
value++;
}
return APDU_OK;
case INS_DEC:
if (value > 0x00) {
value--;
}
return APDU_OK;
case INS_READ:
byte[] outBuffer = {value, APDU_OK[0], APDU_OK[1]};
return outBuffer;
}
return APDU_NOT_OK;
}
// Implemeation of Interface SecureCard
public void createCardUID() {
setCardUID("abcd");
}
// Implemeation of Interface SecureCard
public void initSecureCard() {
System.out.println("InnerCard initialized");
}
}
And here is the code for the Nokia 6212 SDk
/**
* @author Gerald Madlmayr
* NFC Research Lab Hagenberg, www.nfc-research.at
* @version 1.0
*
* Simulation of a SmartCard for the Emulator
*/
package at.nfcresearch.wima.examples;
import com.nokia.nfcsdk.nfcmgr.plugin.ISmartCardPluginData;
import com.nokia.nfcsdk.nfcmgr.plugin.SmartCardPlugin;
public class TicketSmartCard extends SmartCardPlugin {
// Command (APDU INS) for increading the value in the wallet
private final static byte INS_INC = 0x01;
// Command (APDU INS) for decreading the value in the wallet
private final static byte INS_DEC = 0x02;
// command (APDU INS) for reading the value in the wallet
private final static byte INS_READ = 0x03;
// variable holding the amount stored in the wallet.
private byte value = (byte) 0x20;
private static byte APDU_OK[] = {(byte)0x90, 0x00};
private static byte APDU_NOT_OK[] = {0x69, 0x00};
public TicketSmartCard() {
}
public byte[] exchangeData(byte[] buf) throws Exception {
byte cmd = buf[1];
switch(cmd) {
case INS_INC:
if (value < 0xff)
value++;
return APDU_OK;
case INS_DEC:
if (value > 0x00)
value--;
return APDU_OK;
case INS_READ:
byte[] outBuffer = {value, APDU_OK[0], APDU_OK[1]};
return outBuffer;
}
return APDU_NOT_OK;
}
public String getName() {
return "TicketSmartCard";
}
public void initialize(ISmartCardPluginData data) throws Exception {
super.initialize(data);
}
public void uninitialize() {
}
}
No related wiki articles found