Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 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; |
Oliver Smith | ca866fe | 2020-02-24 09:56:30 +0100 | [diff] [blame^] | 9 | import sim.toolkit.ProactiveResponseHandler; |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 10 | import sim.toolkit.ToolkitConstants; |
| 11 | import sim.toolkit.ToolkitException; |
| 12 | import sim.toolkit.ToolkitInterface; |
| 13 | import sim.toolkit.ToolkitRegistry; |
| 14 | |
| 15 | public class IMSIPseudo extends Applet implements ToolkitInterface, ToolkitConstants { |
| 16 | // DON'T DECLARE USELESS INSTANCE VARIABLES! They get saved to the EEPROM, |
| 17 | // which has a limited number of write cycles. |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 18 | |
Oliver Smith | ca866fe | 2020-02-24 09:56:30 +0100 | [diff] [blame^] | 19 | private byte STKServicesMenuId; |
Oliver Smith | 1e5cc46 | 2020-02-21 15:39:14 +0100 | [diff] [blame] | 20 | static byte[] LUCounter = new byte[] { '0', 'x', ' ', 'L', 'U' }; |
Oliver Smith | ca866fe | 2020-02-24 09:56:30 +0100 | [diff] [blame^] | 21 | |
| 22 | /* Main menu */ |
Oliver Smith | 2dcbfab | 2020-02-21 15:40:21 +0100 | [diff] [blame] | 23 | static byte[] title = new byte[] { 'I', 'M', 'S', 'I', ' ', 'P', 's', 'e', 'u', 'd', 'o', 'n', 'y', 'm', |
| 24 | 'i', 'z', 'a', 't', 'i', 'o', 'n'}; |
Oliver Smith | ca866fe | 2020-02-24 09:56:30 +0100 | [diff] [blame^] | 25 | static byte[] showLU = new byte[] {'S', 'h', 'o', 'w', ' ', 'L', 'U', ' ', 'c', 'o', 'u', 'n', 't', 'e', 'r'}; |
| 26 | static byte[] showIMSI = new byte[] {'S', 'h', 'o', 'w', ' ', 'I', 'M', 'S', 'I'}; |
| 27 | static byte[] changeIMSI = new byte[] {'C', 'h', 'a', 'n', 'g', 'e', ' ', 'I', 'M', 'S', 'I', ' '}; |
| 28 | private Object[] itemListMain = {title, showLU, showIMSI, changeIMSI}; |
| 29 | |
| 30 | /* Change IMSI menu */ |
| 31 | static byte[] setDigit1 = new byte[] {'S', 'e', 't', ' ', '1', ' ', 'a', 's', ' ', 'l', 'a', 's', 't', ' ', |
| 32 | 'd', 'i', 'g', 'i', 't'}; |
| 33 | static byte[] setDigit2 = new byte[] {'S', 'e', 't', ' ', '2', ' ', 'a', 's', ' ', 'l', 'a', 's', 't', ' ', |
| 34 | 'd', 'i', 'g', 'i', 't'}; |
| 35 | private Object[] itemListChangeIMSI = {changeIMSI, setDigit1, setDigit2}; |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 36 | |
| 37 | private IMSIPseudo() { |
Oliver Smith | ca866fe | 2020-02-24 09:56:30 +0100 | [diff] [blame^] | 38 | /* Register menu and trigger on location updates */ |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 39 | ToolkitRegistry reg = ToolkitRegistry.getEntry(); |
Oliver Smith | ca866fe | 2020-02-24 09:56:30 +0100 | [diff] [blame^] | 40 | STKServicesMenuId = reg.initMenuEntry(title, (short)0, (short)title.length, PRO_CMD_SELECT_ITEM, false, |
| 41 | (byte)0, (short)0); |
Oliver Smith | e28705a | 2020-02-21 10:06:14 +0100 | [diff] [blame] | 42 | reg.setEvent(EVENT_EVENT_DOWNLOAD_LOCATION_STATUS); |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 43 | } |
| 44 | |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 45 | public static void install(byte[] bArray, short bOffset, byte bLength) { |
| 46 | IMSIPseudo applet = new IMSIPseudo(); |
| 47 | applet.register(); |
| 48 | } |
| 49 | |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 50 | public void process(APDU arg0) throws ISOException { |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 51 | if (selectingApplet()) |
| 52 | return; |
| 53 | } |
| 54 | |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 55 | public void processToolkit(byte event) throws ToolkitException { |
| 56 | EnvelopeHandler envHdlr = EnvelopeHandler.getTheHandler(); |
| 57 | |
| 58 | if (event == EVENT_MENU_SELECTION) { |
| 59 | byte selectedItemId = envHdlr.getItemIdentifier(); |
| 60 | |
Oliver Smith | ca866fe | 2020-02-24 09:56:30 +0100 | [diff] [blame^] | 61 | if (selectedItemId == STKServicesMenuId) { |
| 62 | showMenu(itemListMain, (byte)4); |
| 63 | handleMenuResponseMain(); |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 64 | } |
| 65 | } |
Oliver Smith | e28705a | 2020-02-21 10:06:14 +0100 | [diff] [blame] | 66 | |
| 67 | if (event == EVENT_EVENT_DOWNLOAD_LOCATION_STATUS) { |
Oliver Smith | 1e5cc46 | 2020-02-21 15:39:14 +0100 | [diff] [blame] | 68 | LUCounter[0]++; |
Oliver Smith | 234ab54 | 2020-02-24 08:25:43 +0100 | [diff] [blame] | 69 | showMsg(LUCounter); |
Oliver Smith | e28705a | 2020-02-21 10:06:14 +0100 | [diff] [blame] | 70 | } |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 71 | } |
| 72 | |
Oliver Smith | 234ab54 | 2020-02-24 08:25:43 +0100 | [diff] [blame] | 73 | private void showMsg(byte[] msg) { |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 74 | ProactiveHandler proHdlr = ProactiveHandler.getTheHandler(); |
Oliver Smith | 234ab54 | 2020-02-24 08:25:43 +0100 | [diff] [blame] | 75 | proHdlr.initDisplayText((byte)0, DCS_8_BIT_DATA, msg, (short)0, (short)(msg.length)); |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 76 | proHdlr.send(); |
| 77 | return; |
| 78 | } |
Oliver Smith | ca866fe | 2020-02-24 09:56:30 +0100 | [diff] [blame^] | 79 | |
| 80 | private void showMenu(Object[] itemList, byte itemCount) { |
| 81 | ProactiveHandler proHdlr = ProactiveHandler.getTheHandler(); |
| 82 | proHdlr.init((byte) PRO_CMD_SELECT_ITEM,(byte)0,DEV_ID_ME); |
| 83 | |
| 84 | for (byte i=(byte)0;i<itemCount;i++) { |
| 85 | if (i == 0) { |
| 86 | /* Title */ |
| 87 | proHdlr.appendTLV((byte)(TAG_ALPHA_IDENTIFIER | TAG_SET_CR), (byte[])itemList[i], |
| 88 | (short)0, (short)((byte[])itemList[i]).length); |
| 89 | |
| 90 | } else { |
| 91 | /* Menu entry */ |
| 92 | proHdlr.appendTLV((byte)(TAG_ITEM | TAG_SET_CR), (byte)i, (byte[])itemList[i], (short)0, |
| 93 | (short)((byte[])itemList[i]).length); |
| 94 | } |
| 95 | } |
| 96 | proHdlr.send(); |
| 97 | } |
| 98 | |
| 99 | private void handleMenuResponseMain() { |
| 100 | ProactiveResponseHandler rspHdlr = ProactiveResponseHandler.getTheHandler(); |
| 101 | |
| 102 | switch (rspHdlr.getItemIdentifier()) { |
| 103 | case 1: /* Show LU counter */ |
| 104 | showMsg(LUCounter); |
| 105 | break; |
| 106 | case 2: /* Show IMSI */ |
| 107 | /* TODO */ |
| 108 | break; |
| 109 | case 3: /* Change IMSI */ |
| 110 | showMenu(itemListChangeIMSI, (byte)3); |
| 111 | handleMenuResponseChangeIMSI(); |
| 112 | break; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | private void handleMenuResponseChangeIMSI() { |
| 117 | /* TODO */ |
| 118 | } |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 119 | } |