Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 16:47, 1 May 2008.

NFC Secure Element Example Java Card for Emulator

From Forum Nokia Wiki

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.

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");
    }
 
 
}
 
Powered by MediaWiki