changeset 53:4eb447be01c0

fc-simtool plmnsel-dump implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 13 Feb 2021 06:26:52 +0000
parents 2f697a8c5196
children 2d1679c7975b
files libcommon/Makefile libcommon/plmncodes.c simtool/Makefile simtool/dispatch.c simtool/plmnsel.c
diffstat 5 files changed, 122 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libcommon/Makefile	Sat Feb 13 05:33:46 2021 +0000
+++ b/libcommon/Makefile	Sat Feb 13 06:26:52 2021 +0000
@@ -4,7 +4,7 @@
 	cardconnect.o chkblank.o dumpdirfunc.o exit.o globalopts.o \
 	gsm7_decode.o gsm7_encode.o gsm7_encode_table.o gsm7_unpack.o hexdump.o\
 	hexread.o hexstr.o names.o number_decode.o number_encode.o pinentry.o \
-	revnibbles.o
+	plmncodes.o revnibbles.o
 LIB=	libcommon.a
 
 all:	${LIB}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libcommon/plmncodes.c	Sat Feb 13 06:26:52 2021 +0000
@@ -0,0 +1,25 @@
+/*
+ * This module implements some functions for working with MCC-MNC PLMN codes.
+ */
+
+#include <sys/types.h>
+
+decode_plmn_3bytes(bin, asc, space_pad)
+	u_char *bin;
+	char *asc;
+{
+	asc[0] = encode_hex_digit(bin[0] & 0xF);
+	asc[1] = encode_hex_digit(bin[0] >> 4);
+	asc[2] = encode_hex_digit(bin[1] & 0xF);
+	asc[3] = '-';
+	asc[4] = encode_hex_digit(bin[2] & 0xF);
+	asc[5] = encode_hex_digit(bin[2] >> 4);
+	asc[6] = encode_hex_digit(bin[1] >> 4);
+	asc[7] = '\0';
+	if (asc[6] == 'F') {
+		if (space_pad)
+			asc[6] = ' ';
+		else
+			asc[6] = '\0';
+	}
+}
--- a/simtool/Makefile	Sat Feb 13 05:33:46 2021 +0000
+++ b/simtool/Makefile	Sat Feb 13 06:26:52 2021 +0000
@@ -3,10 +3,10 @@
 PROG=	fc-simtool
 OBJS=	a38.o chv.o chvext.o curfile.o dispatch.o dumpdir.o grcard1.o grcard2.o\
 	hlread.o main.o pbcommon.o pbdump.o pberase.o pbupd_file.o pbupd_imm.o \
-	pbupd_immhex.o pnndump.o readcmd.o readops.o restorebin.o savebin.o \
-	script.o select.o smserase.o smsp_common.o smsp_dump.o smsp_erase.o \
-	smsp_restore.o smsp_set.o sstdump.o sysmo.o telsum.o writecmd.o \
-	writeops.o
+	pbupd_immhex.o plmnsel.o pnndump.o readcmd.o readops.o restorebin.o \
+	savebin.o script.o select.o smserase.o smsp_common.o smsp_dump.o \
+	smsp_erase.o smsp_restore.o smsp_set.o sstdump.o sysmo.o telsum.o \
+	writecmd.o writeops.o
 LIBS=	../libcommon/libcommon.a
 INSTBIN=/opt/freecalypso/bin
 
--- a/simtool/dispatch.c	Sat Feb 13 05:33:46 2021 +0000
+++ b/simtool/dispatch.c	Sat Feb 13 06:26:52 2021 +0000
@@ -31,6 +31,7 @@
 extern int cmd_pb_update();
 extern int cmd_pb_update_imm();
 extern int cmd_pb_update_imm_hex();
+extern int cmd_plmnsel_dump();
 extern int cmd_pnn_dump();
 extern int cmd_readbin();
 extern int cmd_readef();
@@ -105,6 +106,7 @@
 	{"pb-update", 2, 2, cmd_pb_update},
 	{"pb-update-imm", 3, 4, cmd_pb_update_imm},
 	{"pb-update-imm-hex", 4, 4, cmd_pb_update_imm_hex},
+	{"plmnsel-dump", 0, 0, cmd_plmnsel_dump},
 	{"pnn-dump", 0, 0, cmd_pnn_dump},
 	{"quit", 0, 0, good_exit},
 	{"readbin", 2, 2, cmd_readbin},
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/simtool/plmnsel.c	Sat Feb 13 06:26:52 2021 +0000
@@ -0,0 +1,90 @@
+/*
+ * This module implements commands for working with EF_PLMNsel.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include "simresp.h"
+#include "curfile.h"
+#include "file_id.h"
+
+static
+select_ef_plmnsel()
+{
+	int rc;
+
+	rc = select_op(DF_GSM);
+	if (rc < 0)
+		return(rc);
+	rc = select_op(EF_PLMNsel);
+	if (rc < 0)
+		return(rc);
+	rc = parse_ef_select_response();
+	if (rc < 0)
+		return(rc);
+	if (curfile_structure != 0x00) {
+		fprintf(stderr, "error: EF_PLMNsel is not transparent\n");
+		return(-1);
+	}
+	if (curfile_total_size < 24) {
+		fprintf(stderr,
+		"error: EF_PLMNsel is shorter than spec minimum of 24 bytes\n");
+		return(-1);
+	}
+	if (curfile_total_size > 255) {
+		fprintf(stderr,
+		"error: EF_PLMNsel is longer than our 255 byte limit\n");
+		return(-1);
+	}
+	if (curfile_total_size % 3) {
+		fprintf(stderr,
+		"error: EF_PLMNsel length is not a multiple of 3 bytes\n");
+		return(-1);
+	}
+	return(0);
+}
+
+cmd_plmnsel_dump()
+{
+	int rc, gap_flag;
+	u_char *dp, *endp;
+	char ascbuf[8];
+	unsigned idx, linelen;
+
+	rc = select_ef_plmnsel();
+	if (rc < 0)
+		return(rc);
+	rc = readbin_op(0, curfile_total_size);
+	if (rc < 0)
+		return(rc);
+	dp = sim_resp_data;
+	endp = sim_resp_data + sim_resp_data_len;
+	gap_flag = 0;
+	linelen = 0;
+	for (idx = 0; dp < endp; idx++, dp += 3) {
+		if (dp[0] == 0xFF && dp[1] == 0xFF && dp[2] == 0xFF) {
+			gap_flag = 1;
+			continue;
+		}
+		if (gap_flag) {
+			if (linelen) {
+				putchar('\n');
+				linelen = 0;
+			}
+			printf("GAP, continuing at index %u:\n", idx);
+			gap_flag = 0;
+		}
+		if (linelen >= 10) {
+			putchar('\n');
+			linelen = 0;
+		}
+		decode_plmn_3bytes(dp, ascbuf, 1);
+		if (linelen)
+			putchar(' ');
+		fputs(ascbuf, stdout);
+		linelen++;
+	}
+	if (linelen)
+		putchar('\n');
+	return(0);
+}