diff simtool/grcard2ki.c @ 96:a5cfe5135701

simtool: grcard2.c split into grcard2ki.c and grcard2pins.c
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 05 May 2021 03:55:23 +0000
parents simtool/grcard2.c@4ebd67176b73
children 9f1cc3174e45
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/simtool/grcard2ki.c	Wed May 05 03:55:23 2021 +0000
@@ -0,0 +1,76 @@
+/*
+ * This module implements special commands for the grcard.cn card model
+ * which is known in the Osmocom community as GrcardSIM2:
+ *
+ * https://osmocom.org/projects/cellular-infrastructure/wiki/GrcardSIM2
+ *
+ * FreeCalypso Community SIM model FCSIM1 is GrcardSIM2, and so are
+ * historical sysmoSIM-GR2 and 30C3 cards.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include "simresp.h"
+#include "curfile.h"
+#include "file_id.h"
+
+static
+select_ef_weki()
+{
+	int rc;
+
+	rc = select_op(DF_GSM);
+	if (rc < 0)
+		return(rc);
+	rc = select_op(0x0001);		/* proprietary EF */
+	if (rc < 0)
+		return(rc);
+	rc = parse_ef_select_response();
+	if (rc < 0)
+		return(rc);
+	if (curfile_structure != 0x00 || curfile_total_size != 35) {
+		fprintf(stderr,
+			"error: EF_WEKI is not a transparent EF of 35 bytes\n");
+		return(-1);
+	}
+	return(0);
+}
+
+cmd_grcard2_set_comp128(argc, argv)
+	char **argv;
+{
+	int rc;
+	unsigned code;
+	u_char magic_byte;
+
+	if (argv[1][0] < '1' || argv[1][0] > '3' || argv[1][1]) {
+		fprintf(stderr, "error: invalid argument\n");
+		return(-1);
+	}
+	code = argv[1][0] - '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;
+	magic_byte |= code;
+	return update_bin_op(2, &magic_byte, 1);
+}
+
+cmd_grcard2_set_ki(argc, argv)
+	char **argv;
+{
+	u_char ki[16];
+	int rc;
+
+	rc = decode_hex_data_from_string(argv[1], ki, 16, 16);
+	if (rc < 0)
+		return(rc);
+	rc = select_ef_weki();
+	if (rc < 0)
+		return(rc);
+	return update_bin_op(3, ki, 16);
+}