changeset 99:d2e800abd257

fc-simtool plmnsel-write command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 17 Feb 2021 22:43:18 +0000
parents 6ba14a9247d2
children a75c0aafb367
files libcommon/plmncodes.c simtool/dispatch.c simtool/plmnsel.c
diffstat 3 files changed, 59 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libcommon/plmncodes.c	Wed Feb 17 21:31:32 2021 +0000
+++ b/libcommon/plmncodes.c	Wed Feb 17 22:43:18 2021 +0000
@@ -3,6 +3,8 @@
  */
 
 #include <sys/types.h>
+#include <ctype.h>
+#include <stdio.h>
 
 decode_plmn_3bytes(bin, asc, space_pad)
 	u_char *bin;
@@ -23,3 +25,36 @@
 			asc[6] = '\0';
 	}
 }
+
+encode_plmn_3bytes(asc, bin)
+	char *asc;
+	u_char *bin;
+{
+	u_char mcc[3], mnc[3];
+
+	if (!isxdigit(asc[0]) || !isxdigit(asc[1]) || !isxdigit(asc[2])) {
+inv:		fprintf(stderr, "error: invalid MCC-MNC argument\n");
+		return(-1);
+	}
+	mcc[0] = decode_hex_digit(asc[0]);
+	mcc[1] = decode_hex_digit(asc[1]);
+	mcc[2] = decode_hex_digit(asc[2]);
+	asc += 3;
+	if (*asc == '-')
+		asc++;
+	if (!isxdigit(asc[0]) || !isxdigit(asc[1]))
+		goto inv;
+	mnc[0] = decode_hex_digit(asc[0]);
+	mnc[1] = decode_hex_digit(asc[1]);
+	asc += 2;
+	if (*asc == '\0')
+		mnc[2] = 0xF;
+	else if (isxdigit(asc[0]) && asc[1] == '\0')
+		mnc[2] = decode_hex_digit(*asc);
+	else
+		goto inv;
+	bin[0] = (mcc[1] << 4) | mcc[0];
+	bin[1] = (mnc[2] << 4) | mcc[2];
+	bin[2] = (mnc[1] << 4) | mnc[0];
+	return(0);
+}
--- a/simtool/dispatch.c	Wed Feb 17 21:31:32 2021 +0000
+++ b/simtool/dispatch.c	Wed Feb 17 22:43:18 2021 +0000
@@ -40,6 +40,7 @@
 extern int cmd_pb_update_imm();
 extern int cmd_pb_update_imm_hex();
 extern int cmd_plmnsel_dump();
+extern int cmd_plmnsel_write();
 extern int cmd_pnn_dump();
 extern int cmd_readbin();
 extern int cmd_readef();
@@ -131,6 +132,7 @@
 	{"pb-update-imm", 3, 4, cmd_pb_update_imm},
 	{"pb-update-imm-hex", 4, 4, cmd_pb_update_imm_hex},
 	{"plmnsel-dump", 0, 0, cmd_plmnsel_dump},
+	{"plmnsel-write", 2, 2, cmd_plmnsel_write},
 	{"pnn-dump", 0, 0, cmd_pnn_dump},
 	{"quit", 0, 0, good_exit},
 	{"readbin", 2, 2, cmd_readbin},
--- a/simtool/plmnsel.c	Wed Feb 17 21:31:32 2021 +0000
+++ b/simtool/plmnsel.c	Wed Feb 17 22:43:18 2021 +0000
@@ -4,6 +4,7 @@
 
 #include <sys/types.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include "simresp.h"
 #include "curfile.h"
 #include "file_id.h"
@@ -88,3 +89,24 @@
 		putchar('\n');
 	return(0);
 }
+
+cmd_plmnsel_write(argc, argv)
+	char **argv;
+{
+	int rc;
+	unsigned idx;
+	u_char rec[3];
+
+	rc = select_ef_plmnsel();
+	if (rc < 0)
+		return(rc);
+	idx = strtoul(argv[1], 0, 0);
+	if (idx >= curfile_total_size / 3) {
+		fprintf(stderr, "error: specified index is out of range\n");
+		return(-1);
+	}
+	rc = encode_plmn_3bytes(argv[2], rec);
+	if (rc < 0)
+		return(rc);
+	return update_bin_op(idx * 3, rec, 3);
+}