changeset 198:3bde063234aa

fc-simtool plmnsel-write-list command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Mar 2021 02:48:12 +0000
parents 3ddbc3fea5f0
children 7ecc08e55d39
files libutil/Makefile libutil/plmnlist.c simtool/dispatch.c simtool/plmnsel.c
diffstat 4 files changed, 88 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libutil/Makefile	Sun Mar 07 02:36:27 2021 +0000
+++ b/libutil/Makefile	Sun Mar 07 02:48:12 2021 +0000
@@ -3,8 +3,8 @@
 OBJS=	alpha_decode.o alpha_fromfile.o alpha_valid.o decimal_str.o \
 	filesearch.o gsm7_decode.o gsm7_encode.o gsm7_encode_table.o \
 	gsm7_unpack.o hexdigits.o hexread.o hexstr.o iccid_luhn.o nibbles2asc.o\
-	number_decode.o number_encode.o pinentry.o plmncodes.o revnibbles.o \
-	shorthand.o
+	number_decode.o number_encode.o pinentry.o plmncodes.o plmnlist.o \
+	revnibbles.o shorthand.o
 LIB=	libutil.a
 
 all:	${LIB}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libutil/plmnlist.c	Sun Mar 07 02:48:12 2021 +0000
@@ -0,0 +1,69 @@
+/*
+ * This module implements a function for reading PLMN lists from files.
+ */
+
+#include <sys/types.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+
+extern FILE *open_script_input_file();
+
+read_plmn_list_from_file(filename, buf, ef_len)
+	char *filename;
+	u_char *buf;
+	unsigned ef_len;
+{
+	FILE *inf;
+	int lineno, rc;
+	char linebuf[1024], *cp, *np;
+	u_char *dp, *endp;
+
+	inf = open_script_input_file(filename);
+	if (!inf) {
+		perror(filename);
+		return(-1);
+	}
+	dp = buf;
+	endp = buf + ef_len;
+	for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) {
+		if (!index(linebuf, '\n')) {
+			fprintf(stderr,
+				"%s line %d: too long or missing newline\n",
+				filename, lineno);
+			fclose(inf);
+			return(-1);
+		}
+		for (cp = linebuf; ; ) {
+			while (isspace(*cp))
+				cp++;
+			if (*cp == '\0' || *cp == '#')
+				break;
+			for (np = cp; *cp && !isspace(*cp); cp++)
+				;
+			if (*cp)
+				*cp++ = '\0';
+			if (dp >= endp) {
+				fprintf(stderr,
+			"%s line %d: number of PLMN codes exceeds EF size\n",
+					filename, lineno);
+				fclose(inf);
+				return(-1);
+			}
+			rc = encode_plmn_3bytes(np, dp);
+			if (rc < 0) {
+				fprintf(stderr, "%s line %d: invalid MCC-MNC\n",
+					filename, lineno);
+				fclose(inf);
+				return(-1);
+			}
+			dp += 3;
+		}
+	}
+	fclose(inf);
+	while (dp < endp)
+		*dp++ = 0xFF;
+	return(0);
+}
--- a/simtool/dispatch.c	Sun Mar 07 02:36:27 2021 +0000
+++ b/simtool/dispatch.c	Sun Mar 07 02:48:12 2021 +0000
@@ -59,6 +59,7 @@
 extern int cmd_plmnsel_erase();
 extern int cmd_plmnsel_erase_all();
 extern int cmd_plmnsel_write();
+extern int cmd_plmnsel_write_list();
 extern int cmd_pnn_dump();
 extern int cmd_readbin();
 extern int cmd_readef();
@@ -181,6 +182,7 @@
 	{"plmnsel-erase", 1, 2, 0, cmd_plmnsel_erase},
 	{"plmnsel-erase-all", 0, 0, 0, cmd_plmnsel_erase_all},
 	{"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},
 	{"quit", 0, 0, 0, good_exit},
 	{"readbin", 2, 2, 1, cmd_readbin},
--- a/simtool/plmnsel.c	Sun Mar 07 02:36:27 2021 +0000
+++ b/simtool/plmnsel.c	Sun Mar 07 02:48:12 2021 +0000
@@ -117,6 +117,21 @@
 	return update_bin_op(idx * 3, rec, 3);
 }
 
+cmd_plmnsel_write_list(argc, argv)
+	char **argv;
+{
+	int rc;
+	u_char buf[255];
+
+	rc = select_ef_plmnsel();
+	if (rc < 0)
+		return(rc);
+	rc = read_plmn_list_from_file(argv[1], buf, curfile_total_size);
+	if (rc < 0)
+		return(rc);
+	return update_bin_op(0, buf, curfile_total_size);
+}
+
 cmd_plmnsel_erase(argc, argv)
 	char **argv;
 {