changeset 124:d0d1c0b35831

fc-simtool: add low-level cur-ef-{inval,rehab} commands
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 20 Feb 2021 19:05:48 +0000
parents 09a66626647d
children e5d534fa5924
files simtool/Makefile simtool/dispatch.c simtool/inval_rehab.c
diffstat 3 files changed, 62 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/Makefile	Sat Feb 20 04:11:48 2021 +0000
+++ b/simtool/Makefile	Sat Feb 20 19:05:48 2021 +0000
@@ -2,11 +2,12 @@
 CFLAGS=	-O2 -I/usr/include/PCSC -I../libcommon
 PROG=	fc-simtool
 OBJS=	a38.o chv.o chvext.o curfile.o dispatch.o dumpdir.o fplmn.o grcard1.o \
-	grcard2.o hlread.o lndwrite.o main.o miscadm.o opldump.o 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
+	grcard2.o hlread.o inval_rehab.o lndwrite.o main.o miscadm.o opldump.o \
+	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
 LIBS=	../libcommon/libcommon.a
 INSTBIN=/opt/freecalypso/bin
 
--- a/simtool/dispatch.c	Sat Feb 20 04:11:48 2021 +0000
+++ b/simtool/dispatch.c	Sat Feb 20 19:05:48 2021 +0000
@@ -84,6 +84,8 @@
 extern int cmd_write_iccid();
 extern int cmd_write_imsi();
 
+extern int current_ef_inval();
+extern int current_ef_rehab();
 extern int good_exit();
 extern int retrieve_atr();
 
@@ -101,6 +103,8 @@
 	{"change-chv2", 2, 2, 0, cmd_change_chv},
 	{"change-pin1", 2, 2, 0, cmd_change_chv},
 	{"change-pin2", 2, 2, 0, cmd_change_chv},
+	{"cur-ef-inval", 0, 0, 0, current_ef_inval},
+	{"cur-ef-rehab", 0, 0, 0, current_ef_rehab},
 	{"disable-chv", 1, 1, 0, cmd_disable_chv},
 	{"disable-chv1", 1, 1, 0, cmd_disable_chv},
 	{"disable-pin", 1, 1, 0, cmd_disable_chv},
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/simtool/inval_rehab.c	Sat Feb 20 19:05:48 2021 +0000
@@ -0,0 +1,52 @@
+/*
+ * This module implements the rarely-used INVALIDATE and REHABILITATE
+ * SIM protocol commands.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include "simresp.h"
+
+current_ef_inval()
+{
+	u_char cmd[5];
+	int rc;
+
+	/* INVALIDATE command APDU */
+	cmd[0] = 0xA0;
+	cmd[1] = 0x04;
+	cmd[2] = 0;
+	cmd[3] = 0;
+	cmd[4] = 0;
+	rc = apdu_exchange(cmd, 5);
+	if (rc < 0)
+		return(rc);
+	if (sim_resp_sw != 0x9000) {
+		fprintf(stderr, "bad SW response to INVALIDATE: %04X\n",
+			sim_resp_sw);
+		return(-1);
+	}
+	return(0);
+}
+
+current_ef_rehab()
+{
+	u_char cmd[5];
+	int rc;
+
+	/* REHABILITATE command APDU */
+	cmd[0] = 0xA0;
+	cmd[1] = 0x44;
+	cmd[2] = 0;
+	cmd[3] = 0;
+	cmd[4] = 0;
+	rc = apdu_exchange(cmd, 5);
+	if (rc < 0)
+		return(rc);
+	if (sim_resp_sw != 0x9000) {
+		fprintf(stderr, "bad SW response to REHABILITATE: %04X\n",
+			sim_resp_sw);
+		return(-1);
+	}
+	return(0);
+}