changeset 137:277c66de296f

fc-simtool: added STK test commands
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 22 Feb 2021 00:08:42 +0000
parents 5494795406e0
children 58406ead2497
files simtool/Makefile simtool/dispatch.c simtool/stktest.c
diffstat 3 files changed, 122 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/Makefile	Sun Feb 21 01:05:05 2021 +0000
+++ b/simtool/Makefile	Mon Feb 22 00:08:42 2021 +0000
@@ -6,8 +6,8 @@
 	pbcommon.o pbdump.o pberase.o pbrestore.o pbupd_imm.o pbupd_immhex.o \
 	plmnsel.o pnndump.o readcmd.o readops.o restorebin.o savebin.o script.o\
 	select.o smserase.o smsp_common.o smsp_dump.o smsp_erase.o \
-	smsp_restore.o smsp_set.o sstlist.o sysmo.o telsum.o usersum.o \
-	writecmd.o writeops.o
+	smsp_restore.o smsp_set.o sstlist.o stktest.o sysmo.o telsum.o \
+	usersum.o writecmd.o writeops.o
 LIBS=	../libcommon/libcommon.a
 INSTBIN=/opt/freecalypso/bin
 
--- a/simtool/dispatch.c	Sun Feb 21 01:05:05 2021 +0000
+++ b/simtool/dispatch.c	Mon Feb 22 00:08:42 2021 +0000
@@ -14,12 +14,15 @@
 extern int cmd_change_chv();
 extern int cmd_disable_chv();
 extern int cmd_enable_chv();
+extern int cmd_envelope();
+extern int cmd_envelope_imm();
 extern int cmd_exec();
 extern int cmd_fix_sysmo_msisdn();
 extern int cmd_fplmn_dump();
 extern int cmd_fplmn_erase();
 extern int cmd_fplmn_erase_all();
 extern int cmd_fplmn_write();
+extern int cmd_get_response();
 extern int cmd_grcard1_set_adm();
 extern int cmd_grcard1_set_ki();
 extern int cmd_grcard1_set_pin();
@@ -75,6 +78,7 @@
 extern int cmd_spn();
 extern int cmd_sst();
 extern int cmd_telecom_sum();
+extern int cmd_terminal_profile();
 extern int cmd_uicc_dir();
 extern int cmd_unblock_chv();
 extern int cmd_update_bin();
@@ -119,6 +123,8 @@
 	{"enable-chv1", 1, 1, 0, cmd_enable_chv},
 	{"enable-pin", 1, 1, 0, cmd_enable_chv},
 	{"enable-pin1", 1, 1, 0, cmd_enable_chv},
+	{"envelope", 1, 1, 0, cmd_envelope},
+	{"envelope-imm", 1, 1, 0, cmd_envelope_imm},
 	{"exec", 1, 1, 0, cmd_exec},
 	{"exit", 0, 0, 0, good_exit},
 	{"fix-sysmo-msisdn", 0, 0, 0, cmd_fix_sysmo_msisdn},
@@ -126,6 +132,7 @@
 	{"fplmn-erase", 1, 2, 0, cmd_fplmn_erase},
 	{"fplmn-erase-all", 0, 0, 0, cmd_fplmn_erase_all},
 	{"fplmn-write", 2, 2, 0, cmd_fplmn_write},
+	{"get-response", 1, 1, 1, cmd_get_response},
 	{"grcard1-set-adm1", 2, 2, 0, cmd_grcard1_set_adm},
 	{"grcard1-set-adm2", 2, 2, 0, cmd_grcard1_set_adm},
 	{"grcard1-set-ki", 1, 1, 0, cmd_grcard1_set_ki},
@@ -186,6 +193,7 @@
 	{"spn", 0, 0, 1, cmd_spn},
 	{"sst", 0, 0, 1, cmd_sst},
 	{"telecom-sum", 0, 0, 0, cmd_telecom_sum},
+	{"terminal-profile", 1, 1, 0, cmd_terminal_profile},
 	{"uicc-dir", 0, 0, 1, cmd_uicc_dir},
 	{"unblock-chv1", 2, 2, 0, cmd_unblock_chv},
 	{"unblock-chv2", 2, 2, 0, cmd_unblock_chv},
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/simtool/stktest.c	Mon Feb 22 00:08:42 2021 +0000
@@ -0,0 +1,112 @@
+/*
+ * This module implements some commands for testing SIM Toolkit functionality,
+ * just enough to be able to simulate SMS-PP SIM data download operations.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "simresp.h"
+
+cmd_terminal_profile(argc, argv)
+	char **argv;
+{
+	u_char cmd[260];
+	int rc;
+	unsigned len;
+
+	rc = decode_hex_data_from_string(argv[1], cmd + 5, 1, 255);
+	if (rc < 0)
+		return(rc);
+	len = rc;
+	/* TERMINAL PROFILE command APDU */
+	cmd[0] = 0xA0;
+	cmd[1] = 0x10;
+	cmd[2] = 0;
+	cmd[3] = 0;
+	cmd[4] = len;
+	rc = apdu_exchange(cmd, len + 5);
+	if (rc < 0)
+		return(rc);
+	printf("%04X\n", sim_resp_sw);
+	return(0);
+}
+
+cmd_envelope(argc, argv)
+	char **argv;
+{
+	u_char cmd[260];
+	int rc;
+	unsigned len;
+
+	rc = read_hex_data_file(argv[1], cmd + 5);
+	if (rc < 0)
+		return(rc);
+	len = rc;
+	/* ENVELOPE command APDU */
+	cmd[0] = 0xA0;
+	cmd[1] = 0xC2;
+	cmd[2] = 0;
+	cmd[3] = 0;
+	cmd[4] = len;
+	rc = apdu_exchange(cmd, len + 5);
+	if (rc < 0)
+		return(rc);
+	printf("%04X\n", sim_resp_sw);
+	return(0);
+}
+
+cmd_envelope_imm(argc, argv)
+	char **argv;
+{
+	u_char cmd[260];
+	int rc;
+	unsigned len;
+
+	rc = decode_hex_data_from_string(argv[1], cmd + 5, 1, 255);
+	if (rc < 0)
+		return(rc);
+	len = rc;
+	/* ENVELOPE command APDU */
+	cmd[0] = 0xA0;
+	cmd[1] = 0xC2;
+	cmd[2] = 0;
+	cmd[3] = 0;
+	cmd[4] = len;
+	rc = apdu_exchange(cmd, len + 5);
+	if (rc < 0)
+		return(rc);
+	printf("%04X\n", sim_resp_sw);
+	return(0);
+}
+
+cmd_get_response(argc, argv, outf)
+	char **argv;
+	FILE *outf;
+{
+	u_char cmd[5];
+	int rc;
+	unsigned len;
+
+	len = strtoul(argv[1], 0, 0);
+	if (len < 1 || len > 256) {
+		fprintf(stderr, "error: length argument is out of range\n");
+		return(-1);
+	}
+	/* GET RESPONSE command APDU */
+	cmd[0] = 0xA0;
+	cmd[1] = 0xC0;
+	cmd[2] = 0;
+	cmd[3] = 0;
+	cmd[4] = len;
+	rc = apdu_exchange(cmd, 5);
+	if (rc < 0)
+		return(rc);
+	if (sim_resp_sw != 0x9000) {
+		fprintf(stderr, "bad SW resp to GET RESPONSE: %04X\n",
+			sim_resp_sw);
+		return(-1);
+	}
+	display_sim_resp_in_hex(outf);
+	return(0);
+}