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; |
| 9 | import sim.toolkit.ToolkitConstants; |
| 10 | import sim.toolkit.ToolkitException; |
| 11 | import sim.toolkit.ToolkitInterface; |
| 12 | import sim.toolkit.ToolkitRegistry; |
| 13 | |
| 14 | public 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 | |
Oliver Smith | 1e5cc46 | 2020-02-21 15:39:14 +0100 | [diff] [blame^] | 19 | static byte[] LUCounter = new byte[] { '0', 'x', ' ', 'L', 'U' }; |
Oliver Smith | 8f58642 | 2020-02-21 08:55:57 +0100 | [diff] [blame] | 20 | static byte[] menuItemText = new byte[] { 'I', 'M', 'S', 'I', ' ', 'P', 's', 'e', 'u', 'd', 'o', 'n', 'y', 'm', |
| 21 | 'i', 'z', 'a', 't', 'i', 'o', 'n'}; |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 22 | |
| 23 | private IMSIPseudo() { |
| 24 | // This is the interface to the STK applet registry (which is separate |
| 25 | // from the JavaCard applet registry!) |
| 26 | ToolkitRegistry reg = ToolkitRegistry.getEntry(); |
| 27 | |
| 28 | // Define the applet Menu Entry |
| 29 | helloMenuItem = reg.initMenuEntry(menuItemText, (short)0, (short)menuItemText.length, |
| 30 | PRO_CMD_SELECT_ITEM, false, (byte)0, (short)0); |
Oliver Smith | e28705a | 2020-02-21 10:06:14 +0100 | [diff] [blame] | 31 | reg.setEvent(EVENT_EVENT_DOWNLOAD_LOCATION_STATUS); |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 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) { |
| 37 | IMSIPseudo applet = new IMSIPseudo(); |
Oliver Smith | e28705a | 2020-02-21 10:06:14 +0100 | [diff] [blame] | 38 | |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 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 | } |
Oliver Smith | e28705a | 2020-02-21 10:06:14 +0100 | [diff] [blame] | 61 | |
| 62 | if (event == EVENT_EVENT_DOWNLOAD_LOCATION_STATUS) { |
Oliver Smith | 1e5cc46 | 2020-02-21 15:39:14 +0100 | [diff] [blame^] | 63 | LUCounter[0]++; |
Oliver Smith | e28705a | 2020-02-21 10:06:14 +0100 | [diff] [blame] | 64 | showHello(); |
| 65 | } |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | private void showHello() { |
| 69 | ProactiveHandler proHdlr = ProactiveHandler.getTheHandler(); |
Oliver Smith | 1e5cc46 | 2020-02-21 15:39:14 +0100 | [diff] [blame^] | 70 | proHdlr.initDisplayText((byte)0, DCS_8_BIT_DATA, LUCounter, (short)0, |
| 71 | (short)(LUCounter.length)); |
Oliver Smith | 4e5e516 | 2020-02-21 08:47:36 +0100 | [diff] [blame] | 72 | proHdlr.send(); |
| 73 | return; |
| 74 | } |
| 75 | } |