changeset 149:451ed3bbfe96

fc-simtool: grcard1-set-adm[12] commands implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Feb 2021 00:01:55 +0000
parents 1232dea1d66a
children 54e33e9238b6
files simtool/dispatch.c simtool/grcard1.c
diffstat 2 files changed, 43 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/dispatch.c	Sat Feb 06 23:52:53 2021 +0000
+++ b/simtool/dispatch.c	Sun Feb 07 00:01:55 2021 +0000
@@ -14,6 +14,7 @@
 extern int cmd_enable_chv();
 extern int cmd_exec();
 extern int cmd_fix_sysmo_msisdn();
+extern int cmd_grcard1_set_adm();
 extern int cmd_grcard1_set_pin();
 extern int cmd_iccid();
 extern int cmd_imsi();
@@ -63,6 +64,8 @@
 	{"exec", 1, 1, cmd_exec},
 	{"exit", 0, 0, good_exit},
 	{"fix-sysmo-msisdn", 0, 0, cmd_fix_sysmo_msisdn},
+	{"grcard1-set-adm1", 2, 2, cmd_grcard1_set_adm},
+	{"grcard1-set-adm2", 2, 2, cmd_grcard1_set_adm},
 	{"grcard1-set-pin1", 2, 2, cmd_grcard1_set_pin},
 	{"grcard1-set-pin2", 2, 2, cmd_grcard1_set_pin},
 	{"iccid", 0, 0, cmd_iccid},
--- a/simtool/grcard1.c	Sat Feb 06 23:52:53 2021 +0000
+++ b/simtool/grcard1.c	Sun Feb 07 00:01:55 2021 +0000
@@ -50,3 +50,43 @@
 	}
 	return(0);
 }
+
+cmd_grcard1_set_adm(argc, argv)
+	char **argv;
+{
+	u_char cmd[23];
+	int rc;
+
+	/* Grcard1 proprietary command APDU */
+	cmd[0] = 0x80;
+	cmd[1] = 0xD4;
+	cmd[2] = 0x01;
+	switch (argv[0][15]) {
+	case '1':
+		cmd[3] = 0x04;
+		break;
+	case '2':
+		cmd[3] = 0x05;
+		break;
+	default:
+		fprintf(stderr, "BUG in grcard1-set-admN command\n");
+		return(-1);
+	}
+	cmd[4] = 18;
+	cmd[5] = 0x03;
+	cmd[6] = 0x00;
+	rc = encode_pin_entry(argv[1], cmd + 7);
+	if (rc < 0)
+		return(rc);
+	rc = encode_pin_entry(argv[2], cmd + 15);
+	if (rc < 0)
+		return(rc);
+	rc = apdu_exchange(cmd, 23);
+	if (rc < 0)
+		return(rc);
+	if (sim_resp_sw != 0x9000) {
+		fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
+		return(-1);
+	}
+	return(0);
+}