diff simtool/hlread.c @ 184:8d073ff62c48

fc-simtool: imsi command does higher-level parsing, the old version is now imsi-raw
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 06 Mar 2021 05:44:17 +0000
parents 2aa92dfcb4b5
children 43b57865fdb5
line wrap: on
line diff
--- a/simtool/hlread.c	Sat Mar 06 05:24:26 2021 +0000
+++ b/simtool/hlread.c	Sat Mar 06 05:44:17 2021 +0000
@@ -44,6 +44,51 @@
 	FILE *outf;
 {
 	int rc;
+	char buf[17], *endp;
+
+	rc = select_op(DF_GSM);
+	if (rc < 0)
+		return(rc);
+	rc = select_op(EF_IMSI);
+	if (rc < 0)
+		return(rc);
+	rc = parse_ef_select_response();
+	if (rc < 0)
+		return(rc);
+	if (curfile_structure != 0x00 || curfile_total_size != 9) {
+		fprintf(stderr, "error: expected transparent EF of 9 bytes\n");
+		return(-1);
+	}
+	rc = readbin_op(0, 9);
+	if (rc < 0)
+		return(rc);
+	if (sim_resp_data[0] < 1 || sim_resp_data[0] > 8) {
+malformed:	fprintf(stderr, "error: malformed EF_IMSI record\n");
+		return(-1);
+	}
+	decode_reversed_nibbles(sim_resp_data + 1, sim_resp_data[0], buf);
+	endp = buf + (sim_resp_data[0] << 1);
+	switch (buf[0]) {
+	case '1':
+		if (sim_resp_data[0] == 1)
+			goto malformed;
+		*--endp = '\0';
+		break;
+	case '9':
+		*endp = '\0';
+		break;
+	default:
+		goto malformed;
+	}
+	fprintf(outf, "%s\n", buf + 1);
+	return(0);
+}
+
+cmd_imsi_raw(argc, argv, outf)
+	char **argv;
+	FILE *outf;
+{
+	int rc;
 	char buf[17];
 
 	rc = select_op(DF_GSM);