diff simtool/miscadm.c @ 210:9797417ececa

fc-simtool write-acc command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Mar 2021 06:26:20 +0000
parents 2545dd27ca38
children 31cd62f91522
line wrap: on
line diff
--- a/simtool/miscadm.c	Sun Mar 07 06:06:23 2021 +0000
+++ b/simtool/miscadm.c	Sun Mar 07 06:26:20 2021 +0000
@@ -6,6 +6,7 @@
 
 #include <sys/types.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include "curfile.h"
 #include "file_id.h"
 
@@ -135,3 +136,42 @@
 	pack_reversed_nibbles(nibbles, binrec + 1, 8);
 	return write_imsi_bin(binrec);
 }
+
+static
+write_acc_bin(binrec)
+	u_char *binrec;
+{
+	int rc;
+
+	rc = select_op(DF_GSM);
+	if (rc < 0)
+		return(rc);
+	rc = select_op(EF_ACC);
+	if (rc < 0)
+		return(rc);
+	rc = parse_ef_select_response();
+	if (rc < 0)
+		return(rc);
+	if (curfile_structure != 0x00 || curfile_total_size != 2) {
+		fprintf(stderr,
+			"error: EF_ACC is not a transparent EF of 2 bytes\n");
+		return(-1);
+	}
+	return update_bin_op(0, binrec, 2);
+}
+
+cmd_write_acc(argc, argv)
+	char **argv;
+{
+	unsigned acc;
+	u_char binrec[2];
+
+	acc = strtoul(argv[1], 0, 16);
+	if (acc > 0xFFFF) {
+		fprintf(stderr, "error: ACC argument is out of range\n");
+		return(-1);
+	}
+	binrec[0] = acc >> 8;
+	binrec[1] = acc;
+	return write_acc_bin(binrec);
+}