×
Namespaces

Variants
Actions
Revision as of 11:25, 23 July 2013 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

NFC Secure Element Example Java Card for Emulator

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Code ExampleTested with
Devices(s): Nokia 6131 Emulator
CompatibilityArticle
Created: geri-m (01 May 2008)
Last edited: hamishwillee (23 Jul 2013)

Warning.pngWarning: This example was created for the NFC implementation provided on Series 40 devices, and may include use of features not yet available for NFC on Symbian devices.

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() {
}
}
This page was last modified on 23 July 2013, at 11:25.
89 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×