Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 1 | package org.osmocom.IMSIPseudo; |
| 2 | |
Oliver Smith | 4eee13d | 2020-02-24 11:28:39 +0100 | [diff] [blame^] | 3 | import sim.access.*; |
| 4 | import sim.toolkit.*; |
| 5 | import javacard.framework.*; |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 6 | |
| 7 | public 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 Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 10 | |
Oliver Smith | ca866fe | 2020-02-24 09:56:30 +0100 | [diff] [blame] | 11 | private byte STKServicesMenuId; |
Oliver Smith | 1e5cc46 | 2020-02-21 15:39:14 +0100 | [diff] [blame] | 12 | static byte[] LUCounter = new byte[] { '0', 'x', ' ', 'L', 'U' }; |
Oliver Smith | ca866fe | 2020-02-24 09:56:30 +0100 | [diff] [blame] | 13 | |
| 14 | /* Main menu */ |
Oliver Smith | 2dcbfab | 2020-02-21 15:40:21 +0100 | [diff] [blame] | 15 | 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 Smith | ca866fe | 2020-02-24 09:56:30 +0100 | [diff] [blame] | 17 | 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 Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 28 | |
| 29 | private IMSIPseudo() { |
Oliver Smith | ca866fe | 2020-02-24 09:56:30 +0100 | [diff] [blame] | 30 | /* Register menu and trigger on location updates */ |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 31 | ToolkitRegistry reg = ToolkitRegistry.getEntry(); |
Oliver Smith | ca866fe | 2020-02-24 09:56:30 +0100 | [diff] [blame] | 32 | STKServicesMenuId = reg.initMenuEntry(title, (short)0, (short)title.length, PRO_CMD_SELECT_ITEM, false, |
| 33 | (byte)0, (short)0); |
Oliver Smith | e28705a | 2020-02-21 10:06:14 +0100 | [diff] [blame] | 34 | reg.setEvent(EVENT_EVENT_DOWNLOAD_LOCATION_STATUS); |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 35 | } |
| 36 | |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 37 | public static void install(byte[] bArray, short bOffset, byte bLength) { |
| 38 | IMSIPseudo applet = new IMSIPseudo(); |
| 39 | applet.register(); |
| 40 | } |
| 41 | |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 42 | public void process(APDU arg0) throws ISOException { |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 43 | if (selectingApplet()) |
| 44 | return; |
| 45 | } |
| 46 | |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 47 | 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 Smith | ca866fe | 2020-02-24 09:56:30 +0100 | [diff] [blame] | 53 | if (selectedItemId == STKServicesMenuId) { |
| 54 | showMenu(itemListMain, (byte)4); |
| 55 | handleMenuResponseMain(); |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 56 | } |
| 57 | } |
Oliver Smith | e28705a | 2020-02-21 10:06:14 +0100 | [diff] [blame] | 58 | |
| 59 | if (event == EVENT_EVENT_DOWNLOAD_LOCATION_STATUS) { |
Oliver Smith | 1e5cc46 | 2020-02-21 15:39:14 +0100 | [diff] [blame] | 60 | LUCounter[0]++; |
Oliver Smith | 234ab54 | 2020-02-24 08:25:43 +0100 | [diff] [blame] | 61 | showMsg(LUCounter); |
Oliver Smith | e28705a | 2020-02-21 10:06:14 +0100 | [diff] [blame] | 62 | } |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 63 | } |
| 64 | |
Oliver Smith | ca866fe | 2020-02-24 09:56:30 +0100 | [diff] [blame] | 65 | 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 Smith | cef081c | 2020-02-24 10:02:14 +0100 | [diff] [blame] | 84 | 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 Smith | ca866fe | 2020-02-24 09:56:30 +0100 | [diff] [blame] | 91 | 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 Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 111 | } |