Project

General

Profile

« Previous | Next » 

Revision 7528b38c

Added by osmith about 4 years ago

sim-applet: rename to org.osmocom.IMSIPseudo

View differences:

sim-applet/Makefile
1 1
SIMTOOLS_DIR    = ../../sim-tools
2 2

  
3 3
APPLET_AID      = 0xd0:0x70:0x02:0xca:0x44:0x90:0x01:0x01
4
APPLET_NAME     = org.toorcamp.HelloSTK.HelloSTK
4
APPLET_NAME     = org.osmocom.IMSIPseudo.IMSIPseudo
5 5
PACKAGE_AID     = 0xd0:0x70:0x02:0xCA:0x44:0x90:0x01
6
PACKAGE_NAME    = org.toorcamp.HelloSTK
6
PACKAGE_NAME    = org.osmocom.IMSIPseudo
7 7
PACKAGE_VERSION = 1.0
8 8

  
9 9
SOURCES = \
10
	src/org/toorcamp/HelloSTK/HelloSTK.java
10
	src/org/osmocom/IMSIPseudo/IMSIPseudo.java
11 11

  
12 12
include $(SIMTOOLS_DIR)/javacard/makefiles/applet-project.mk
sim-applet/src/org/osmocom/IMSIPseudo/IMSIPseudo.java
1
package org.osmocom.IMSIPseudo;
2

  
3
import javacard.framework.APDU;
4
import javacard.framework.Applet;
5
import javacard.framework.ISOException;
6

  
7
import sim.toolkit.EnvelopeHandler;
8
import sim.toolkit.ProactiveHandler;
9
import sim.toolkit.ToolkitConstants;
10
import sim.toolkit.ToolkitException;
11
import sim.toolkit.ToolkitInterface;
12
import sim.toolkit.ToolkitRegistry;
13

  
14
public class IMSIPseudo extends Applet implements ToolkitInterface, ToolkitConstants {
15
	// DON'T DECLARE USELESS INSTANCE VARIABLES! They get saved to the EEPROM,
16
	// which has a limited number of write cycles.
17
	private byte helloMenuItem;
18
	
19
	static byte[] welcomeMsg = new byte[] { 'W', 'e', 'l', 'c', 'o', 'm', 'e', ' ',
20
                                            't', 'o', ' ', 'T', 'o', 'o', 'r', 'C',
21
                                            'a', 'm', 'p', ' ', '2', '0', '1', '2' };
22
	static byte[] menuItemText = new byte[] { 'H', 'e', 'l', 'l', 'o', ',', ' ', 'S', 'T', 'K'};
23
	
24
	private IMSIPseudo() {
25
		// This is the interface to the STK applet registry (which is separate
26
		// from the JavaCard applet registry!)
27
		ToolkitRegistry reg = ToolkitRegistry.getEntry();
28
	
29
		// Define the applet Menu Entry
30
		helloMenuItem = reg.initMenuEntry(menuItemText, (short)0, (short)menuItemText.length,
31
				PRO_CMD_SELECT_ITEM, false, (byte)0, (short)0);
32
	}
33
	
34
	// This method is called by the card when the applet is installed. You must
35
	// instantiate your applet and register it here.
36
	public static void install(byte[] bArray, short bOffset, byte bLength) {
37
		IMSIPseudo applet = new IMSIPseudo();
38
		applet.register();
39
	}
40
	
41
	// This processes APDUs sent directly to the applet. For STK applets, this
42
	// interface isn't really used.
43
	public void process(APDU arg0) throws ISOException {
44
		// ignore the applet select command dispached to the process
45
		if (selectingApplet())
46
			return;
47
	}
48

  
49
	// This processes STK events.
50
	public void processToolkit(byte event) throws ToolkitException {
51
		EnvelopeHandler envHdlr = EnvelopeHandler.getTheHandler();
52

  
53
		if (event == EVENT_MENU_SELECTION) {
54
			byte selectedItemId = envHdlr.getItemIdentifier();
55

  
56
			if (selectedItemId == helloMenuItem) {
57
				showHello();
58
			}
59
		}
60
	}
61
	
62
	private void showHello() {
63
		ProactiveHandler proHdlr = ProactiveHandler.getTheHandler();
64
		proHdlr.initDisplayText((byte)0, DCS_8_BIT_DATA, welcomeMsg, (short)0, 
65
				(short)(welcomeMsg.length));
66
		proHdlr.send();
67
		return;
68
	}
69
}
sim-applet/src/org/toorcamp/HelloSTK/HelloSTK.java
1
package org.toorcamp.HelloSTK;
2

  
3
import javacard.framework.APDU;
4
import javacard.framework.Applet;
5
import javacard.framework.ISOException;
6

  
7
import sim.toolkit.EnvelopeHandler;
8
import sim.toolkit.ProactiveHandler;
9
import sim.toolkit.ToolkitConstants;
10
import sim.toolkit.ToolkitException;
11
import sim.toolkit.ToolkitInterface;
12
import sim.toolkit.ToolkitRegistry;
13

  
14
public class HelloSTK extends Applet implements ToolkitInterface, ToolkitConstants {
15
	// DON'T DECLARE USELESS INSTANCE VARIABLES! They get saved to the EEPROM,
16
	// which has a limited number of write cycles.
17
	private byte helloMenuItem;
18
	
19
	static byte[] welcomeMsg = new byte[] { 'W', 'e', 'l', 'c', 'o', 'm', 'e', ' ',
20
                                            't', 'o', ' ', 'T', 'o', 'o', 'r', 'C',
21
                                            'a', 'm', 'p', ' ', '2', '0', '1', '2' };
22
	
23
	static byte[] menuItemText = new byte[] { 'H', 'e', 'l', 'l', 'o', ',', ' ', 'S', 'T', 'K'};
24
	
25
	private HelloSTK() {
26
		// This is the interface to the STK applet registry (which is separate
27
		// from the JavaCard applet registry!)
28
		ToolkitRegistry reg = ToolkitRegistry.getEntry();
29
	
30
		// Define the applet Menu Entry
31
		helloMenuItem = reg.initMenuEntry(menuItemText, (short)0, (short)menuItemText.length,
32
				PRO_CMD_SELECT_ITEM, false, (byte)0, (short)0);
33
	}
34
	
35
	// This method is called by the card when the applet is installed. You must
36
	// instantiate your applet and register it here.
37
	public static void install(byte[] bArray, short bOffset, byte bLength) {
38
		HelloSTK applet = new HelloSTK();
39
		applet.register();
40
	}
41
	
42
	// This processes APDUs sent directly to the applet. For STK applets, this
43
	// interface isn't really used.
44
	public void process(APDU arg0) throws ISOException {
45
		// ignore the applet select command dispached to the process
46
		if (selectingApplet())
47
			return;
48
	}
49

  
50
	// This processes STK events.
51
	public void processToolkit(byte event) throws ToolkitException {
52
		EnvelopeHandler envHdlr = EnvelopeHandler.getTheHandler();
53

  
54
		if (event == EVENT_MENU_SELECTION) {
55
			byte selectedItemId = envHdlr.getItemIdentifier();
56

  
57
			if (selectedItemId == helloMenuItem) {
58
				showHello();
59
			}
60
		}
61
	}
62
	
63
	private void showHello() {
64
		ProactiveHandler proHdlr = ProactiveHandler.getTheHandler();
65
		proHdlr.initDisplayText((byte)0, DCS_8_BIT_DATA, welcomeMsg, (short)0, 
66
				(short)(welcomeMsg.length));
67
		proHdlr.send();
68
		return;
69
	}
70
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 48.8 MB)