changeset 112:87d459d9797a

fc-simtool: pb-erase command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 26 Jan 2021 03:32:20 +0000
parents 5bfb5a7262c1
children 7e7eab9ea7c5
files simtool/Makefile simtool/dispatch.c simtool/pberase.c
diffstat 3 files changed, 35 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/Makefile	Tue Jan 26 03:22:26 2021 +0000
+++ b/simtool/Makefile	Tue Jan 26 03:32:20 2021 +0000
@@ -3,8 +3,8 @@
 PROG=	fc-simtool
 OBJS=	alpha_decode.o alpha_valid.o apdu.o atr.o cardconnect.o chv.o \
 	dispatch.o globals.o hexdump.o hexread.o hlread.o main.o names.o \
-	pbcommon.o pbdump.o pbupdate.o readcmd.o readops.o saverestore.o \
-	select.o telsum.o writecmd.o writeops.o
+	pbcommon.o pbdump.o pberase.o pbupdate.o readcmd.o readops.o \
+	saverestore.o select.o telsum.o writecmd.o writeops.o
 INSTBIN=/opt/freecalypso/bin
 
 all:	${PROG}
--- a/simtool/dispatch.c	Tue Jan 26 03:22:26 2021 +0000
+++ b/simtool/dispatch.c	Tue Jan 26 03:32:20 2021 +0000
@@ -18,6 +18,7 @@
 extern int cmd_iccid();
 extern int cmd_imsi();
 extern int cmd_pb_dump();
+extern int cmd_pb_erase();
 extern int cmd_pb_update();
 extern int cmd_readbin();
 extern int cmd_readef();
@@ -60,6 +61,7 @@
 	{"iccid", 0, 0, cmd_iccid},
 	{"imsi", 0, 0, cmd_imsi},
 	{"pb-dump", 1, 2, cmd_pb_dump},
+	{"pb-erase", 1, 1, cmd_pb_erase},
 	{"pb-update", 2, 2, cmd_pb_update},
 	{"quit", 0, 0, cmd_exit},
 	{"readbin", 2, 2, cmd_readbin},
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/simtool/pberase.c	Tue Jan 26 03:32:20 2021 +0000
@@ -0,0 +1,31 @@
+/*
+ * This module implements the pb-erase command.
+ */
+
+#include <sys/types.h>
+#include <string.h>
+#include <strings.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <pcsclite.h>
+#include <winscard.h>
+#include "globals.h"
+
+cmd_pb_erase(argc, argv)
+	char **argv;
+{
+	int rc;
+	unsigned recno;
+	u_char record[255];
+
+	rc = phonebook_op_common(argv[1]);
+	if (rc < 0)
+		return(rc);
+	memset(record, 0xFF, curfile_record_len);
+	for (recno = 1; recno <= curfile_record_count; recno++) {
+		rc = update_rec_op(recno, 0x04, record, curfile_record_len);
+		if (rc < 0)
+			return(rc);
+	}
+	return(0);
+}