changeset 97:9f1cc3174e45

grcard2-set-comp128: allow optional setting of upper 6 bits
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 05 May 2021 04:05:57 +0000
parents a5cfe5135701
children 2972f00622c7
files simtool/cmdtab.c simtool/grcard2ki.c
diffstat 2 files changed, 18 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/cmdtab.c	Wed May 05 03:55:23 2021 +0000
+++ b/simtool/cmdtab.c	Wed May 05 04:05:57 2021 +0000
@@ -167,7 +167,7 @@
 	{"grcard1-set-pin2", 2, 2, 0, cmd_grcard1_set_pin},
 	{"grcard2-set-adm5", 1, 1, 0, cmd_grcard2_set_adm5},
 	{"grcard2-set-adm5-hex", 1, 1, 0, cmd_grcard2_set_adm5_hex},
-	{"grcard2-set-comp128", 1, 1, 0, cmd_grcard2_set_comp128},
+	{"grcard2-set-comp128", 1, 2, 0, cmd_grcard2_set_comp128},
 	{"grcard2-set-ki", 1, 1, 0, cmd_grcard2_set_ki},
 	{"grcard2-set-pin1", 1, 1, 0, cmd_grcard2_set_pin},
 	{"grcard2-set-pin2", 1, 1, 0, cmd_grcard2_set_pin},
--- a/simtool/grcard2ki.c	Wed May 05 03:55:23 2021 +0000
+++ b/simtool/grcard2ki.c	Wed May 05 04:05:57 2021 +0000
@@ -40,22 +40,32 @@
 	char **argv;
 {
 	int rc;
-	unsigned code;
+	unsigned code, upper;
 	u_char magic_byte;
 
 	if (argv[1][0] < '1' || argv[1][0] > '3' || argv[1][1]) {
-		fprintf(stderr, "error: invalid argument\n");
+		fprintf(stderr, "error: invalid COMP128 version argument\n");
 		return(-1);
 	}
 	code = argv[1][0] - '1';
+	if (argv[2]) {
+		upper = strtoul(argv[2], 0, 16);
+		if ((upper & 3) || (upper > 0xFC)) {
+			fprintf(stderr, "error: invalid upper bits argument\n");
+			return(-1);
+		}
+	}
 	rc = select_ef_weki();
 	if (rc < 0)
 		return(rc);
-	rc = readbin_op(2, 1);
-	if (rc < 0)
-		return(rc);
-	magic_byte = sim_resp_data[0];
-	magic_byte &= 0xFC;
+	if (argv[2])
+		magic_byte = upper;
+	else {
+		rc = readbin_op(2, 1);
+		if (rc < 0)
+			return(rc);
+		magic_byte = sim_resp_data[0] & 0xFC;
+	}
 	magic_byte |= code;
 	return update_bin_op(2, &magic_byte, 1);
 }