changeset 40:4c240a37e7c4

fc-simtool smsp-erase-* command family implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 12 Feb 2021 22:05:38 +0000
parents 2467b7acad1f
children 8cb269f5a902
files simtool/Makefile simtool/dispatch.c simtool/smsp_erase.c
diffstat 3 files changed, 91 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/Makefile	Fri Feb 12 21:54:01 2021 +0000
+++ b/simtool/Makefile	Fri Feb 12 22:05:38 2021 +0000
@@ -4,8 +4,8 @@
 OBJS=	a38.o chv.o curfile.o dispatch.o dumpdir.o grcard1.o grcard2.o hlread.o\
 	main.o pbcommon.o pbdump.o pberase.o pbupd_file.o pbupd_imm.o \
 	pbupd_immhex.o readcmd.o readops.o restorebin.o savebin.o script.o \
-	select.o smsp_common.o smsp_dump.o smsp_restore.o sysmo.o telsum.o \
-	writecmd.o writeops.o
+	select.o smsp_common.o smsp_dump.o smsp_erase.o smsp_restore.o sysmo.o \
+	telsum.o writecmd.o writeops.o
 LIBS=	../libcommon/libcommon.a
 INSTBIN=/opt/freecalypso/bin
 
--- a/simtool/dispatch.c	Fri Feb 12 21:54:01 2021 +0000
+++ b/simtool/dispatch.c	Fri Feb 12 22:05:38 2021 +0000
@@ -39,6 +39,9 @@
 extern int cmd_save_sms_bin();
 extern int cmd_select();
 extern int cmd_smsp_dump();
+extern int cmd_smsp_erase_all();
+extern int cmd_smsp_erase_one();
+extern int cmd_smsp_erase_range();
 extern int cmd_smsp_restore();
 extern int cmd_spn();
 extern int cmd_telecom_sum();
@@ -104,6 +107,9 @@
 	{"select", 1, 1, cmd_select},
 	{"sim-resp", 0, 0, display_sim_resp_in_hex},
 	{"smsp-dump", 0, 1, cmd_smsp_dump},
+	{"smsp-erase-all", 0, 0, cmd_smsp_erase_all},
+	{"smsp-erase-one", 1, 1, cmd_smsp_erase_one},
+	{"smsp-erase-range", 2, 2, cmd_smsp_erase_range},
 	{"smsp-restore", 1, 1, cmd_smsp_restore},
 	{"spn", 0, 0, cmd_spn},
 	{"telecom-sum", 0, 0, cmd_telecom_sum},
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/simtool/smsp_erase.c	Fri Feb 12 22:05:38 2021 +0000
@@ -0,0 +1,83 @@
+/*
+ * This module implements the smsp-erase family of commands.
+ */
+
+#include <sys/types.h>
+#include <string.h>
+#include <strings.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "curfile.h"
+
+cmd_smsp_erase_all(argc, argv)
+	char **argv;
+{
+	int rc;
+	unsigned recno;
+	u_char record[255];
+
+	rc = select_ef_smsp();
+	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);
+}
+
+cmd_smsp_erase_one(argc, argv)
+	char **argv;
+{
+	int rc;
+	unsigned recno;
+	u_char record[255];
+
+	rc = select_ef_smsp();
+	if (rc < 0)
+		return(rc);
+	recno = strtoul(argv[1], 0, 0);
+	if (recno < 1 || recno > curfile_record_count) {
+		fprintf(stderr, "error: specified record number is invalid\n");
+		return(-1);
+	}
+	memset(record, 0xFF, curfile_record_len);
+	return update_rec_op(recno, 0x04, record, curfile_record_len);
+}
+
+cmd_smsp_erase_range(argc, argv)
+	char **argv;
+{
+	int rc;
+	unsigned recno, startrec, endrec;
+	u_char record[255];
+
+	rc = select_ef_smsp();
+	if (rc < 0)
+		return(rc);
+	startrec = strtoul(argv[1], 0, 0);
+	if (startrec < 1 || startrec > curfile_record_count) {
+		fprintf(stderr,
+			"error: specified starting record number is invalid\n");
+		return(-1);
+	}
+	endrec = strtoul(argv[2], 0, 0);
+	if (endrec < 1 || endrec > curfile_record_count) {
+		fprintf(stderr,
+			"error: specified final record number is invalid\n");
+		return(-1);
+	}
+	if (startrec > endrec) {
+		fprintf(stderr, "error: reverse record range specified\n");
+		return(-1);
+	}
+	memset(record, 0xFF, curfile_record_len);
+	for (recno = startrec; recno <= endrec; recno++) {
+		rc = update_rec_op(recno, 0x04, record, curfile_record_len);
+		if (rc < 0)
+			return(rc);
+	}
+	return(0);
+}