changeset 215:3a2f43460582

fc-simtool pnn-write command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Mar 2021 08:35:57 +0000
parents 8b1eecb56cb5
children cd66e13eccf3
files simtool/Makefile simtool/dispatch.c simtool/pnnprog.c
diffstat 3 files changed, 73 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/Makefile	Sun Mar 07 08:07:07 2021 +0000
+++ b/simtool/Makefile	Sun Mar 07 08:35:57 2021 +0000
@@ -5,10 +5,10 @@
 	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 \
-	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
+	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 08:07:07 2021 +0000
+++ b/simtool/dispatch.c	Sun Mar 07 08:35:57 2021 +0000
@@ -62,6 +62,7 @@
 extern int cmd_plmnsel_write();
 extern int cmd_plmnsel_write_list();
 extern int cmd_pnn_dump();
+extern int cmd_pnn_write();
 extern int cmd_readbin();
 extern int cmd_readef();
 extern int cmd_readrec();
@@ -190,6 +191,7 @@
 	{"plmnsel-write", 2, 2, 0, cmd_plmnsel_write},
 	{"plmnsel-write-list", 1, 1, 0, cmd_plmnsel_write_list},
 	{"pnn-dump", 0, 0, 1, cmd_pnn_dump},
+	{"pnn-write", 2, 3, 0, cmd_pnn_write},
 	{"quit", 0, 0, 0, good_exit},
 	{"readbin", 2, 2, 1, cmd_readbin},
 	{"readef", 1, 1, 1, cmd_readef},
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/simtool/pnnprog.c	Sun Mar 07 08:35:57 2021 +0000
@@ -0,0 +1,67 @@
+/*
+ * This module implements functions for admin programming of EF_PNN.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "curfile.h"
+
+static u_char *
+add_field(dp, bytes_avail, namearg, type)
+	u_char *dp;
+	char *namearg;
+	unsigned bytes_avail, type;
+{
+	u_char gsm7_buf[289];
+	unsigned nsept, noct;
+	int rc;
+
+	if (bytes_avail < 4) {
+		fprintf(stderr,
+			"error: PNN record is too short for name element\n");
+		return(0);
+	}
+	rc = qstring_arg_to_gsm7(namearg, gsm7_buf, (bytes_avail-3) * 8 / 7);
+	if (rc < 0)
+		return(0);
+	nsept = rc;
+	gsm7_buf[nsept] = 0;
+	noct = (nsept * 7 + 7) / 8;
+	*dp++ = type;
+	*dp++ = noct + 1;
+	*dp++ = 0x80 | (nsept & 7);
+	gsm7_pack(gsm7_buf, dp, noct);
+	dp += noct;
+	return dp;
+}
+
+cmd_pnn_write(argc, argv)
+	char **argv;
+{
+	int rc;
+	unsigned recno;
+	u_char record[255], *dp, *endp;
+
+	rc = select_ef_pnn();
+	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);
+	}
+	dp = record;
+	endp = record + curfile_record_len;
+	dp = add_field(dp, endp - dp, argv[2], 0x43);
+	if (!dp)
+		return(-1);
+	if (argv[3]) {
+		dp = add_field(dp, endp - dp, argv[3], 0x45);
+		if (!dp)
+			return(-1);
+	}
+	while (dp < endp)
+		*dp++ = 0xFF;
+	return update_rec_op(recno, 0x04, record, curfile_record_len);
+}