changeset 33:c83ec3bd9d67

fc-simtool sws-pin1-{dis,en}able implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 17 Mar 2021 01:14:19 +0000
parents d0be3802410a
children e0a6111705b3
files simtool/chvfunc.c simtool/cmdtab.c simtool/sws.c
diffstat 3 files changed, 88 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/chvfunc.c	Wed Mar 17 00:49:50 2021 +0000
+++ b/simtool/chvfunc.c	Wed Mar 17 01:14:19 2021 +0000
@@ -33,3 +33,57 @@
 	}
 	return(0);
 }
+
+disable_chv_func(p2, pin)
+	unsigned p2;
+	char *pin;
+{
+	u_char cmd[13];
+	int rc;
+
+	/* DISABLE CHV command APDU */
+	cmd[0] = 0xA0;
+	cmd[1] = 0x26;
+	cmd[2] = 0x00;
+	cmd[3] = p2;
+	cmd[4] = 8;
+	rc = encode_pin_entry(pin, cmd + 5);
+	if (rc < 0)
+		return(rc);
+	rc = apdu_exchange(cmd, 13);
+	if (rc < 0)
+		return(rc);
+	if (sim_resp_sw != 0x9000 && sim_resp_sw != 0x9808) {
+		fprintf(stderr, "bad SW response to DISABLE CHV: %04X\n",
+			sim_resp_sw);
+		return(-1);
+	}
+	return(0);
+}
+
+enable_chv_func(p2, pin)
+	unsigned p2;
+	char *pin;
+{
+	u_char cmd[13];
+	int rc;
+
+	/* ENABLE CHV command APDU */
+	cmd[0] = 0xA0;
+	cmd[1] = 0x28;
+	cmd[2] = 0x00;
+	cmd[3] = p2;
+	cmd[4] = 8;
+	rc = encode_pin_entry(pin, cmd + 5);
+	if (rc < 0)
+		return(rc);
+	rc = apdu_exchange(cmd, 13);
+	if (rc < 0)
+		return(rc);
+	if (sim_resp_sw != 0x9000 && sim_resp_sw != 0x9808) {
+		fprintf(stderr, "bad SW response to ENABLE CHV: %04X\n",
+			sim_resp_sw);
+		return(-1);
+	}
+	return(0);
+}
--- a/simtool/cmdtab.c	Wed Mar 17 00:49:50 2021 +0000
+++ b/simtool/cmdtab.c	Wed Mar 17 01:14:19 2021 +0000
@@ -93,6 +93,8 @@
 extern int cmd_sws_auth_pin1();
 extern int cmd_sws_auth_pin2();
 extern int cmd_sws_lookup();
+extern int cmd_sws_pin1_disable();
+extern int cmd_sws_pin1_enable();
 extern int cmd_telecom_sum();
 extern int cmd_terminal_profile();
 extern int cmd_uicc_dir();
@@ -224,6 +226,8 @@
 	{"sws-auth-pin1", 0, 0, 0, cmd_sws_auth_pin1},
 	{"sws-auth-pin2", 0, 0, 0, cmd_sws_auth_pin2},
 	{"sws-lookup", 1, 18, 1, cmd_sws_lookup},
+	{"sws-pin1-disable", 0, 0, 0, cmd_sws_pin1_disable},
+	{"sws-pin1-enable", 0, 0, 0, cmd_sws_pin1_enable},
 	{"telecom-sum", 0, 0, 0, cmd_telecom_sum},
 	{"terminal-profile", 1, 1, 0, cmd_terminal_profile},
 	{"uicc-dir", 0, 0, 1, cmd_uicc_dir},
--- a/simtool/sws.c	Wed Mar 17 00:49:50 2021 +0000
+++ b/simtool/sws.c	Wed Mar 17 01:14:19 2021 +0000
@@ -92,3 +92,33 @@
 		return(-1);
 	return verify_chv_func(0x02, pin);
 }
+
+cmd_sws_pin1_disable()
+{
+	int rc;
+	struct dbread_state dbs;
+	char *pin;
+
+	rc = lookup_sws_card(&dbs);
+	if (rc < 0)
+		return(rc);
+	pin = dbread_find_key_req(&dbs, "PIN1");
+	if (!pin)
+		return(-1);
+	return disable_chv_func(0x01, pin);
+}
+
+cmd_sws_pin1_enable()
+{
+	int rc;
+	struct dbread_state dbs;
+	char *pin;
+
+	rc = lookup_sws_card(&dbs);
+	if (rc < 0)
+		return(rc);
+	pin = dbread_find_key_req(&dbs, "PIN1");
+	if (!pin)
+		return(-1);
+	return enable_chv_func(0x01, pin);
+}