changeset 218:f376ba028311

fc-simtool opl-erase and opl-write implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Mar 2021 18:42:57 +0000
parents 52c0da56e979
children ac41c42ce806
files simtool/Makefile simtool/dispatch.c simtool/oplprog.c
diffstat 3 files changed, 94 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/Makefile	Sun Mar 07 18:18:29 2021 +0000
+++ b/simtool/Makefile	Sun Mar 07 18:42:57 2021 +0000
@@ -3,12 +3,12 @@
 PROG=	fc-simtool
 OBJS=	a38.o bfsearch.o chv.o chvext.o curfile.o dispatch.o dumpdir.o \
 	erasefile.o fplmn.o getresp.o grcard1.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 \
-	pnnprog.o readcmd.o readef.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 sstprog.o stktest.o sysmo.o \
-	telsum.o usersum.o writecmd.o writeops.o
+	inval_rehab.o lndwrite.o main.o miscadm.o opldump.o oplprog.o \
+	pbcommon.o pbdump.o pberase.o pbrestore.o pbupd_imm.o pbupd_immhex.o \
+	plmnsel.o pnndump.o pnnprog.o readcmd.o readef.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 sstprog.o stktest.o \
+	sysmo.o telsum.o usersum.o writecmd.o writeops.o
 LIBS=	../libcommon/libcommon.a ../libutil/libutil.a
 INSTBIN=/opt/freecalypso/bin
 
--- a/simtool/dispatch.c	Sun Mar 07 18:18:29 2021 +0000
+++ b/simtool/dispatch.c	Sun Mar 07 18:42:57 2021 +0000
@@ -47,6 +47,8 @@
 extern int cmd_lnd_restore();
 extern int cmd_lnd_write();
 extern int cmd_opl_dump();
+extern int cmd_opl_erase();
+extern int cmd_opl_write();
 extern int cmd_pb_dump();
 extern int cmd_pb_dump_rec();
 extern int cmd_pb_erase();
@@ -177,6 +179,8 @@
 	{"lnd-restore", 1, 1, 0, cmd_lnd_restore},
 	{"lnd-write", 1, 2, 0, cmd_lnd_write},
 	{"opl-dump", 0, 0, 1, cmd_opl_dump},
+	{"opl-erase", 1, 2, 0, cmd_opl_erase},
+	{"opl-write", 5, 5, 0, cmd_opl_write},
 	{"pb-dump", 1, 1, 1, cmd_pb_dump},
 	{"pb-dump-rec", 2, 3, 1, cmd_pb_dump_rec},
 	{"pb-erase", 1, 1, 0, cmd_pb_erase},
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/simtool/oplprog.c	Sun Mar 07 18:42:57 2021 +0000
@@ -0,0 +1,84 @@
+/*
+ * This module implements functions for admin programming of EF_OPL.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "curfile.h"
+
+cmd_opl_write(argc, argv)
+	char **argv;
+{
+	int rc;
+	unsigned recno, lac;
+	u_char record[255];
+
+	rc = select_ef_opl();
+	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);
+	}
+	rc = encode_plmn_3bytes(argv[2], record);
+	if (rc < 0) {
+		fprintf(stderr, "error: invalid MCC-MNC argument\n");
+		return(rc);
+	}
+	lac = strtoul(argv[3], 0, 16);
+	record[3] = lac >> 8;
+	record[4] = lac;
+	lac = strtoul(argv[4], 0, 16);
+	record[5] = lac >> 8;
+	record[6] = lac;
+	record[7] = strtoul(argv[5], 0, 0);
+	if (curfile_record_len > 8)
+		memset(record + 8, 0xFF, curfile_record_len - 8);
+	return update_rec_op(recno, 0x04, record, curfile_record_len);
+}
+
+cmd_opl_erase(argc, argv)
+	char **argv;
+{
+	int rc;
+	unsigned recno, startrec, endrec;
+	u_char record[255];
+
+	rc = select_ef_opl();
+	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);
+	}
+	if (!argv[2])
+		endrec = startrec;
+	else if (!strcmp(argv[2], "end"))
+		endrec = curfile_record_count;
+	else {
+		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);
+}