changeset 210:9797417ececa

fc-simtool write-acc command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Mar 2021 06:26:20 +0000
parents eb16c8841486
children 31cd62f91522
files simtool/dispatch.c simtool/miscadm.c
diffstat 2 files changed, 42 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/dispatch.c	Sun Mar 07 06:06:23 2021 +0000
+++ b/simtool/dispatch.c	Sun Mar 07 06:26:20 2021 +0000
@@ -99,6 +99,7 @@
 extern int cmd_verify_ext();
 extern int cmd_verify_hex();
 extern int cmd_verify_sjs1_adm1();
+extern int cmd_write_acc();
 extern int cmd_write_iccid();
 extern int cmd_write_iccid_sh18();
 extern int cmd_write_iccid_sh19();
@@ -232,6 +233,7 @@
 	{"verify-pin1", 1, 1, 0, cmd_verify_chv},
 	{"verify-pin2", 1, 1, 0, cmd_verify_chv},
 	{"verify-sjs1-adm1", 1, 1, 0, cmd_verify_sjs1_adm1},
+	{"write-acc", 1, 1, 0, cmd_write_acc},
 	{"write-iccid", 1, 1, 0, cmd_write_iccid},
 	{"write-iccid-sh18", 1, 1, 0, cmd_write_iccid_sh18},
 	{"write-iccid-sh19", 1, 1, 0, cmd_write_iccid_sh19},
--- 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);
+}