changeset 159:a5e2b6e3bdf7

fc-uicc-tool: fix-sysmo-msisdn command ported over
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Feb 2021 04:07:24 +0000
parents 65a2a96386cd
children 19b96c52348f
files uicc/Makefile uicc/dispatch.c uicc/sysmo.c
diffstat 3 files changed, 68 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/uicc/Makefile	Sun Feb 07 04:00:27 2021 +0000
+++ b/uicc/Makefile	Sun Feb 07 04:07:24 2021 +0000
@@ -4,7 +4,7 @@
 OBJS=	alpha_decode.o alpha_valid.o apdu.o atr.o cardconnect.o dispatch.o \
 	dumpdir.o exit.o globals.o hexdump.o hexread.o hexstr.o hlread.o main.o\
 	names.o pbcommon.o pbdump.o pberase.o pbupdate.o readcmd.o readops.o \
-	script.o select.o telsum.o writecmd.o writeops.o
+	script.o select.o sysmo.o telsum.o writecmd.o writeops.o
 INSTBIN=/opt/freecalypso/bin
 
 all:	${PROG}
--- a/uicc/dispatch.c	Sun Feb 07 04:00:27 2021 +0000
+++ b/uicc/dispatch.c	Sun Feb 07 04:07:24 2021 +0000
@@ -10,6 +10,7 @@
 
 extern int cmd_dir();
 extern int cmd_exec();
+extern int cmd_fix_sysmo_msisdn();
 extern int cmd_iccid();
 extern int cmd_pb_dump();
 extern int cmd_pb_dump_rec();
@@ -42,6 +43,7 @@
 	{"dir", 0, 0, cmd_dir},
 	{"exec", 1, 1, cmd_exec},
 	{"exit", 0, 0, good_exit},
+	{"fix-sysmo-msisdn", 0, 0, cmd_fix_sysmo_msisdn},
 	{"iccid", 0, 0, cmd_iccid},
 	{"pb-dump", 1, 2, cmd_pb_dump},
 	{"pb-dump-rec", 2, 3, cmd_pb_dump_rec},
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/uicc/sysmo.c	Sun Feb 07 04:07:24 2021 +0000
@@ -0,0 +1,65 @@
+/*
+ * This module implements special commands for programmable and
+ * semi-programmable (made-up term for the version without ADM keys)
+ * SIM cards made by Sysmocom.
+ */
+
+#include <sys/types.h>
+#include <string.h>
+#include <strings.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <pcsclite.h>
+#include <winscard.h>
+#include "globals.h"
+#include "file_id.h"
+
+cmd_fix_sysmo_msisdn()
+{
+	int rc;
+	unsigned n;
+	u_char newrec[34];
+	unsigned record_len, record_count;
+
+	rc = select_op(FILEID_MF);
+	if (rc < 0)
+		return(rc);
+	rc = select_op(DF_TELECOM);
+	if (rc < 0)
+		return(rc);
+	rc = select_op(EF_MSISDN);
+	if (rc < 0)
+		return(rc);
+	rc = select_resp_get_linear_fixed(&record_len, &record_count);
+	if (rc < 0)
+		return(rc);
+	if (record_len != 34) {
+		fprintf(stderr,
+		"error: expected EF_MSISDN record length of 34 bytes, got %u\n",
+			record_len);
+		return(-1);
+	}
+	rc = readrec_op(1, 0x04, 34);
+	if (rc < 0)
+		return(rc);
+	for (n = 0; n < 18; n++) {
+		if (sim_resp_data[n] != 0xFF) {
+			fprintf(stderr,
+		"error: non-FF data in the first 18 bytes of alpha tag area\n");
+			return(-1);
+		}
+	}
+	if (sim_resp_data[18] == 0xFF && sim_resp_data[19] == 0xFF) {
+		printf(
+		"last 2 bytes of alpha tag area are clear - already fixed?\n");
+		return(0);
+	}
+	if (sim_resp_data[18] != 0x07 || sim_resp_data[19] != 0x91) {
+		fprintf(stderr,
+	"error: bytes 18 & 19 don't match expected bogus programming\n");
+		return(-1);
+	}
+	memset(newrec, 0xFF, 34);
+	memcpy(newrec + 20, sim_resp_data + 18, 8);
+	return update_rec_op(1, 0x04, newrec, 34);
+}