blob: 63f840f2a9c67740c0fdfcd7109f76453c413464 [file] [log] [blame]
Oliver Smith4e5e5162020-02-21 08:47:36 +01001package org.osmocom.IMSIPseudo;
2
Oliver Smith4eee13d2020-02-24 11:28:39 +01003import sim.access.*;
4import sim.toolkit.*;
5import javacard.framework.*;
Oliver Smith4e5e5162020-02-21 08:47:36 +01006
7public class IMSIPseudo extends Applet implements ToolkitInterface, ToolkitConstants {
8 // DON'T DECLARE USELESS INSTANCE VARIABLES! They get saved to the EEPROM,
9 // which has a limited number of write cycles.
Oliver Smith4e5e5162020-02-21 08:47:36 +010010
Oliver Smithca866fe2020-02-24 09:56:30 +010011 private byte STKServicesMenuId;
Oliver Smith1e5cc462020-02-21 15:39:14 +010012 static byte[] LUCounter = new byte[] { '0', 'x', ' ', 'L', 'U' };
Oliver Smithca866fe2020-02-24 09:56:30 +010013
14 /* Main menu */
Oliver Smith2dcbfab2020-02-21 15:40:21 +010015 static byte[] title = new byte[] { 'I', 'M', 'S', 'I', ' ', 'P', 's', 'e', 'u', 'd', 'o', 'n', 'y', 'm',
16 'i', 'z', 'a', 't', 'i', 'o', 'n'};
Oliver Smithca866fe2020-02-24 09:56:30 +010017 static byte[] showLU = new byte[] {'S', 'h', 'o', 'w', ' ', 'L', 'U', ' ', 'c', 'o', 'u', 'n', 't', 'e', 'r'};
18 static byte[] showIMSI = new byte[] {'S', 'h', 'o', 'w', ' ', 'I', 'M', 'S', 'I'};
19 static byte[] changeIMSI = new byte[] {'C', 'h', 'a', 'n', 'g', 'e', ' ', 'I', 'M', 'S', 'I', ' '};
20 private Object[] itemListMain = {title, showLU, showIMSI, changeIMSI};
21
22 /* Change IMSI menu */
23 static byte[] setDigit1 = new byte[] {'S', 'e', 't', ' ', '1', ' ', 'a', 's', ' ', 'l', 'a', 's', 't', ' ',
24 'd', 'i', 'g', 'i', 't'};
25 static byte[] setDigit2 = new byte[] {'S', 'e', 't', ' ', '2', ' ', 'a', 's', ' ', 'l', 'a', 's', 't', ' ',
26 'd', 'i', 'g', 'i', 't'};
27 private Object[] itemListChangeIMSI = {changeIMSI, setDigit1, setDigit2};
Oliver Smith4e5e5162020-02-21 08:47:36 +010028
29 private IMSIPseudo() {
Oliver Smithca866fe2020-02-24 09:56:30 +010030 /* Register menu and trigger on location updates */
Oliver Smith4e5e5162020-02-21 08:47:36 +010031 ToolkitRegistry reg = ToolkitRegistry.getEntry();
Oliver Smithca866fe2020-02-24 09:56:30 +010032 STKServicesMenuId = reg.initMenuEntry(title, (short)0, (short)title.length, PRO_CMD_SELECT_ITEM, false,
33 (byte)0, (short)0);
Oliver Smithe28705a2020-02-21 10:06:14 +010034 reg.setEvent(EVENT_EVENT_DOWNLOAD_LOCATION_STATUS);
Oliver Smith4e5e5162020-02-21 08:47:36 +010035 }
36
Oliver Smith4e5e5162020-02-21 08:47:36 +010037 public static void install(byte[] bArray, short bOffset, byte bLength) {
38 IMSIPseudo applet = new IMSIPseudo();
39 applet.register();
40 }
41
Oliver Smith4e5e5162020-02-21 08:47:36 +010042 public void process(APDU arg0) throws ISOException {
Oliver Smith4e5e5162020-02-21 08:47:36 +010043 if (selectingApplet())
44 return;
45 }
46
Oliver Smith4e5e5162020-02-21 08:47:36 +010047 public void processToolkit(byte event) throws ToolkitException {
48 EnvelopeHandler envHdlr = EnvelopeHandler.getTheHandler();
49
50 if (event == EVENT_MENU_SELECTION) {
51 byte selectedItemId = envHdlr.getItemIdentifier();
52
Oliver Smithca866fe2020-02-24 09:56:30 +010053 if (selectedItemId == STKServicesMenuId) {
54 showMenu(itemListMain, (byte)4);
55 handleMenuResponseMain();
Oliver Smith4e5e5162020-02-21 08:47:36 +010056 }
57 }
Oliver Smithe28705a2020-02-21 10:06:14 +010058
59 if (event == EVENT_EVENT_DOWNLOAD_LOCATION_STATUS) {
Oliver Smith1e5cc462020-02-21 15:39:14 +010060 LUCounter[0]++;
Oliver Smith234ab542020-02-24 08:25:43 +010061 showMsg(LUCounter);
Oliver Smithe28705a2020-02-21 10:06:14 +010062 }
Oliver Smith4e5e5162020-02-21 08:47:36 +010063 }
64
Oliver Smithca866fe2020-02-24 09:56:30 +010065 private void showMenu(Object[] itemList, byte itemCount) {
66 ProactiveHandler proHdlr = ProactiveHandler.getTheHandler();
67 proHdlr.init((byte) PRO_CMD_SELECT_ITEM,(byte)0,DEV_ID_ME);
68
69 for (byte i=(byte)0;i<itemCount;i++) {
70 if (i == 0) {
71 /* Title */
72 proHdlr.appendTLV((byte)(TAG_ALPHA_IDENTIFIER | TAG_SET_CR), (byte[])itemList[i],
73 (short)0, (short)((byte[])itemList[i]).length);
74
75 } else {
76 /* Menu entry */
77 proHdlr.appendTLV((byte)(TAG_ITEM | TAG_SET_CR), (byte)i, (byte[])itemList[i], (short)0,
78 (short)((byte[])itemList[i]).length);
79 }
80 }
81 proHdlr.send();
82 }
83
Oliver Smithcef081c2020-02-24 10:02:14 +010084 private void showMsg(byte[] msg) {
85 ProactiveHandler proHdlr = ProactiveHandler.getTheHandler();
86 proHdlr.initDisplayText((byte)0, DCS_8_BIT_DATA, msg, (short)0, (short)(msg.length));
87 proHdlr.send();
88 return;
89 }
90
Oliver Smithca866fe2020-02-24 09:56:30 +010091 private void handleMenuResponseMain() {
92 ProactiveResponseHandler rspHdlr = ProactiveResponseHandler.getTheHandler();
93
94 switch (rspHdlr.getItemIdentifier()) {
95 case 1: /* Show LU counter */
96 showMsg(LUCounter);
97 break;
98 case 2: /* Show IMSI */
99 /* TODO */
100 break;
101 case 3: /* Change IMSI */
102 showMenu(itemListChangeIMSI, (byte)3);
103 handleMenuResponseChangeIMSI();
104 break;
105 }
106 }
107
108 private void handleMenuResponseChangeIMSI() {
109 /* TODO */
110 }
Oliver Smith4e5e5162020-02-21 08:47:36 +0100111}