blob: f418846093a83f93bf8b5ce79c119ae3de3af72a [file] [log] [blame]
Oliver Smith4e5e5162020-02-21 08:47:36 +01001package org.osmocom.IMSIPseudo;
2
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
14public 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' };
Oliver Smith8f586422020-02-21 08:55:57 +010022 static byte[] menuItemText = new byte[] { 'I', 'M', 'S', 'I', ' ', 'P', 's', 'e', 'u', 'd', 'o', 'n', 'y', 'm',
23 'i', 'z', 'a', 't', 'i', 'o', 'n'};
Oliver Smith4e5e5162020-02-21 08:47:36 +010024
25 private IMSIPseudo() {
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 IMSIPseudo applet = new IMSIPseudo();
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}