diff simtool/plmnsel.c @ 99:d2e800abd257

fc-simtool plmnsel-write command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 17 Feb 2021 22:43:18 +0000
parents 4eb447be01c0
children a75c0aafb367
line wrap: on
line diff
--- 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);
+}