sim-applet: start with hello-stk

Import source from here: https://git.osmocom.org/sim/hello-stk
diff --git a/sim-applet/.gitignore b/sim-applet/.gitignore
new file mode 100644
index 0000000..567609b
--- /dev/null
+++ b/sim-applet/.gitignore
@@ -0,0 +1 @@
+build/
diff --git a/sim-applet/Makefile b/sim-applet/Makefile
new file mode 100644
index 0000000..8942300
--- /dev/null
+++ b/sim-applet/Makefile
@@ -0,0 +1,12 @@
+SIMTOOLS_DIR    = ../sim-tools
+
+APPLET_AID      = 0xd0:0x70:0x02:0xca:0x44:0x90:0x01:0x01
+APPLET_NAME     = org.toorcamp.HelloSTK.HelloSTK
+PACKAGE_AID     = 0xd0:0x70:0x02:0xCA:0x44:0x90:0x01
+PACKAGE_NAME    = org.toorcamp.HelloSTK
+PACKAGE_VERSION = 1.0
+
+SOURCES = \
+	src/org/toorcamp/HelloSTK/HelloSTK.java
+
+include $(SIMTOOLS_DIR)/javacard/makefiles/applet-project.mk
diff --git a/sim-applet/README.md b/sim-applet/README.md
index b5bd474..09f5cfb 100644
--- a/sim-applet/README.md
+++ b/sim-applet/README.md
@@ -1,2 +1,8 @@
-TODO:
-* put SIM applet here, based on https://git.osmocom.org/sim/hello-stk
+# Hello World SIM Toolkit Program
+
+This is the source code to a very simple *Hello World* Java SIM Toolkit
+application.  You typically install it using the tools from the
+<http://git.osmocom.org/sim/sim-tools/> repository.
+
+For more information see
+<https://osmocom.org/projects/cellular-infrastructure/wiki/Shadysimpy>
diff --git a/sim-applet/src/org/toorcamp/HelloSTK/HelloSTK.java b/sim-applet/src/org/toorcamp/HelloSTK/HelloSTK.java
new file mode 100755
index 0000000..6658251
--- /dev/null
+++ b/sim-applet/src/org/toorcamp/HelloSTK/HelloSTK.java
@@ -0,0 +1,70 @@
+package org.toorcamp.HelloSTK;

+

+import javacard.framework.APDU;

+import javacard.framework.Applet;

+import javacard.framework.ISOException;

+

+import sim.toolkit.EnvelopeHandler;

+import sim.toolkit.ProactiveHandler;

+import sim.toolkit.ToolkitConstants;

+import sim.toolkit.ToolkitException;

+import sim.toolkit.ToolkitInterface;

+import sim.toolkit.ToolkitRegistry;

+

+public class HelloSTK extends Applet implements ToolkitInterface, ToolkitConstants {

+	// DON'T DECLARE USELESS INSTANCE VARIABLES! They get saved to the EEPROM,

+	// which has a limited number of write cycles.

+	private byte helloMenuItem;

+	

+	static byte[] welcomeMsg = new byte[] { 'W', 'e', 'l', 'c', 'o', 'm', 'e', ' ',

+                                            't', 'o', ' ', 'T', 'o', 'o', 'r', 'C',

+                                            'a', 'm', 'p', ' ', '2', '0', '1', '2' };

+	

+	static byte[] menuItemText = new byte[] { 'H', 'e', 'l', 'l', 'o', ',', ' ', 'S', 'T', 'K'};

+	

+	private HelloSTK() {

+		// This is the interface to the STK applet registry (which is separate

+		// from the JavaCard applet registry!)

+		ToolkitRegistry reg = ToolkitRegistry.getEntry();

+	

+		// Define the applet Menu Entry

+		helloMenuItem = reg.initMenuEntry(menuItemText, (short)0, (short)menuItemText.length,

+				PRO_CMD_SELECT_ITEM, false, (byte)0, (short)0);

+	}

+	

+	// This method is called by the card when the applet is installed. You must

+	// instantiate your applet and register it here.

+	public static void install(byte[] bArray, short bOffset, byte bLength) {

+		HelloSTK applet = new HelloSTK();

+		applet.register();

+	}

+	

+	// This processes APDUs sent directly to the applet. For STK applets, this

+	// interface isn't really used.

+	public void process(APDU arg0) throws ISOException {

+		// ignore the applet select command dispached to the process

+		if (selectingApplet())

+			return;

+	}

+

+	// This processes STK events.

+	public void processToolkit(byte event) throws ToolkitException {

+		EnvelopeHandler envHdlr = EnvelopeHandler.getTheHandler();

+

+		if (event == EVENT_MENU_SELECTION) {

+			byte selectedItemId = envHdlr.getItemIdentifier();

+

+			if (selectedItemId == helloMenuItem) {

+				showHello();

+			}

+		}

+	}

+	

+	private void showHello() {

+		ProactiveHandler proHdlr = ProactiveHandler.getTheHandler();

+		proHdlr.initDisplayText((byte)0, DCS_8_BIT_DATA, welcomeMsg, (short)0, 

+				(short)(welcomeMsg.length));

+		proHdlr.send();

+		return;

+	}

+}