blob: 249806b87924cae090c3cff6ffe4b980002aede6 [file] [log] [blame]
Oliver Smith7528b382020-02-21 08:43:25 +01001package org.osmocom.IMSIPseudo;
Oliver Smith537fba02020-02-19 12:12:52 +01002
3import javacard.framework.APDU;
4import javacard.framework.Applet;
5import javacard.framework.ISOException;
6
7import sim.toolkit.EnvelopeHandler;
8import sim.toolkit.ProactiveHandler;
9import sim.toolkit.ToolkitConstants;
10import sim.toolkit.ToolkitException;
11import sim.toolkit.ToolkitInterface;
12import sim.toolkit.ToolkitRegistry;
13
Oliver Smith7528b382020-02-21 08:43:25 +010014public class IMSIPseudo extends Applet implements ToolkitInterface, ToolkitConstants {
Oliver Smith537fba02020-02-19 12:12:52 +010015 // 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' };
Oliver Smith537fba02020-02-19 12:12:52 +010022 static byte[] menuItemText = new byte[] { 'H', 'e', 'l', 'l', 'o', ',', ' ', 'S', 'T', 'K'};
23
Oliver Smith7528b382020-02-21 08:43:25 +010024 private IMSIPseudo() {
Oliver Smith537fba02020-02-19 12:12:52 +010025 // 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) {
Oliver Smith7528b382020-02-21 08:43:25 +010037 IMSIPseudo applet = new IMSIPseudo();
Oliver Smith537fba02020-02-19 12:12:52 +010038 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}