I’m working on a Javacard applet, and currently I’m looking into creating a connection from my phone to my sim card. I want to send some data to a specific app on my phone, on demand.
On the smartcard, I open the BIP/TCP server channel on port 12345
as follows:
import static uicc.toolkit.ToolkitConstants.*;
import uicc.toolkit.*;
import javacard.framework.*;
public class NetworkApplet extends Applet implements ToolkitInterface {
static final short TCP_TX_BUFFER = Byte.MAX_VALUE * 2;
static final short PORT_SERVER = 12345;
static final byte IDX_ID_SERVER_CHANNEL = 0;
byte[] ids;
@SuppressWarnings("unused")
public static void install(byte[] bArray, short bOffset, byte bLength) throws SystemException {
NetworkApplet applet = new NetworkApplet(bArray, bOffset, bLength);
applet.register();
applet.setupToolkitRegistry();
}
NetworkApplet(byte[] bArray, short bOffset, byte bLength) {
ids = JCSystem.makeTransientByteArray((short) 2, JCSystem.CLEAR_ON_RESET);
}
void setupToolkitRegistry() {
ToolkitRegistry registry = ToolkitRegistrySystem.getEntry();
// snip
registry.setEvent(EVENT_PROFILE_DOWNLOAD);
}
@Override
public void process(APDU apdu) throws ISOException {
// Unused
}
@Override
public void processToolkit(short event) throws ToolkitException {
switch (event) {
case EVENT_PROFILE_DOWNLOAD:
ids[IDX_ID_SERVER_CHANNEL] = openServerChannel(PORT_SERVER, TCP_TX_BUFFER);
break;
// snip
}
}
private static byte openServerChannel(short port, short txCapacity) {
ProactiveHandler handler = ProactiveHandlerSystem.getTheHandler();
ProactiveResponseHandler responseHandler = ProactiveResponseHandlerSystem.getTheHandler();
handler.init(PRO_CMD_OPEN_CHANNEL, (byte) 0, DEV_ID_TERMINAL);
handler.appendTLV(TAG_BUFFER_SIZE, txCapacity);
handler.appendTLV(TAG_UICC_TERMINAL_TRANSPORT_LEVEL, QUAL_TCP_SERVER, port);
if (handler.send() == RES_CMD_PERF) {
return responseHandler.getChannelIdentifier();
} else {
return 0;
}
}
}
Now I have a tcp client running on my Android (it also has to work on iPhone). I’ve tried connecting it to port 12345
on: 127.0.0.1
, 192.169.0.1
, 192.169.0.2
and localuicc
, but nothing seems to work. I get that my card is on a different subnet, but how do I reach it?