changeset 44:f4eb1e83b4b3

fc-simtool smsp-set command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 12 Feb 2021 23:48:01 +0000
parents 52ec2d3eb851
children 5bca197e7495
files simtool/Makefile simtool/dispatch.c simtool/smsp_set.c
diffstat 3 files changed, 141 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/Makefile	Fri Feb 12 23:36:47 2021 +0000
+++ b/simtool/Makefile	Fri Feb 12 23:48:01 2021 +0000
@@ -5,7 +5,7 @@
 	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 smserase.o smsp_common.o smsp_dump.o smsp_erase.o \
-	smsp_restore.o sysmo.o telsum.o writecmd.o writeops.o
+	smsp_restore.o smsp_set.o sysmo.o telsum.o writecmd.o writeops.o
 LIBS=	../libcommon/libcommon.a
 INSTBIN=/opt/freecalypso/bin
 
--- a/simtool/dispatch.c	Fri Feb 12 23:36:47 2021 +0000
+++ b/simtool/dispatch.c	Fri Feb 12 23:48:01 2021 +0000
@@ -46,6 +46,7 @@
 extern int cmd_smsp_erase_one();
 extern int cmd_smsp_erase_range();
 extern int cmd_smsp_restore();
+extern int cmd_smsp_set();
 extern int cmd_spn();
 extern int cmd_telecom_sum();
 extern int cmd_uicc_dir();
@@ -117,6 +118,7 @@
 	{"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},
+	{"smsp-set", 2, 6, cmd_smsp_set},
 	{"spn", 0, 0, cmd_spn},
 	{"telecom-sum", 0, 0, cmd_telecom_sum},
 	{"uicc-dir", 0, 0, cmd_uicc_dir},
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/simtool/smsp_set.c	Fri Feb 12 23:48:01 2021 +0000
@@ -0,0 +1,138 @@
+/*
+ * This module implements the user-oriented smsp-set and smsp-set-tag commands.
+ */
+
+#include <sys/types.h>
+#include <ctype.h>
+#include <string.h>
+#include <strings.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "curfile.h"
+
+static
+set_param_da(arg, fixp)
+	char *arg;
+	u_char *fixp;
+{
+	int rc;
+
+	rc = encode_phone_number_arg(arg, fixp + 1, 1);
+	if (rc < 0)
+		return(rc);
+	fixp[0] &= 0xFE;
+	return(0);
+}
+
+static
+set_param_sc(arg, fixp)
+	char *arg;
+	u_char *fixp;
+{
+	int rc;
+
+	rc = encode_phone_number_arg(arg, fixp + 13, 0);
+	if (rc < 0)
+		return(rc);
+	fixp[0] &= 0xFD;
+	return(0);
+}
+
+static
+set_param_pid(arg, fixp)
+	char *arg;
+	u_char *fixp;
+{
+	char *endp;
+
+	if (!isdigit(*arg)) {
+inv:		fprintf(stderr, "error: invalid PID= parameter\n");
+		return(-1);
+	}
+	fixp[25] = strtoul(arg, &endp, 0);
+	if (*endp)
+		goto inv;
+	fixp[0] &= 0xFB;
+	return(0);
+}
+
+static
+set_param_dcs(arg, fixp)
+	char *arg;
+	u_char *fixp;
+{
+	char *endp;
+
+	if (!isdigit(*arg)) {
+inv:		fprintf(stderr, "error: invalid DCS= parameter\n");
+		return(-1);
+	}
+	fixp[26] = strtoul(arg, &endp, 0);
+	if (*endp)
+		goto inv;
+	fixp[0] &= 0xF7;
+	return(0);
+}
+
+static
+set_param_vp(arg, fixp)
+	char *arg;
+	u_char *fixp;
+{
+	char *endp;
+
+	if (!isdigit(*arg)) {
+inv:		fprintf(stderr, "error: invalid VP= parameter\n");
+		return(-1);
+	}
+	fixp[27] = strtoul(arg, &endp, 0);
+	if (*endp)
+		goto inv;
+	fixp[0] &= 0xEF;
+	return(0);
+}
+
+static
+set_param(arg, fixp)
+	char *arg;
+	u_char *fixp;
+{
+	if (!strncasecmp(arg, "DA=", 3))
+		return set_param_da(arg + 3, fixp);
+	if (!strncasecmp(arg, "SC=", 3))
+		return set_param_sc(arg + 3, fixp);
+	if (!strncasecmp(arg, "PID=", 4))
+		return set_param_pid(arg + 4, fixp);
+	if (!strncasecmp(arg, "DCS=", 4))
+		return set_param_dcs(arg + 4, fixp);
+	if (!strncasecmp(arg, "VP=", 3))
+		return set_param_vp(arg + 3, fixp);
+	fprintf(stderr, "error: non-understood parameter \"%s\"\n", arg);
+	return(-1);
+}
+
+cmd_smsp_set(argc, argv)
+	char **argv;
+{
+	int rc;
+	unsigned recno;
+	u_char record[255], *fixp;
+	char **ap;
+
+	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);
+	fixp = record + curfile_record_len - 28;
+	for (ap = argv + 2; *ap; ap++) {
+		rc = set_param(*ap, fixp);
+		if (rc < 0)
+			return(rc);
+	}
+	return update_rec_op(recno, 0x04, record, curfile_record_len);
+}