changeset 98:66c0cb0e9876

fc-simtool: telecom-sum (summary info) command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 24 Jan 2021 22:46:41 +0000
parents 597c4e87a1f4
children 2e35070d289f
files simtool/Makefile simtool/dispatch.c simtool/telsum.c
diffstat 3 files changed, 87 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/Makefile	Sun Jan 24 22:16:33 2021 +0000
+++ b/simtool/Makefile	Sun Jan 24 22:46:41 2021 +0000
@@ -2,7 +2,7 @@
 CFLAGS=	-O2 -I/usr/include/PCSC
 PROG=	fc-simtool
 OBJS=	apdu.o atr.o cardconnect.o dispatch.o globals.o hexdump.o hlread.o \
-	main.o names.o readcmd.o readops.o select.o
+	main.o names.o readcmd.o readops.o select.o telsum.o
 
 all:	${PROG}
 
--- a/simtool/dispatch.c	Sun Jan 24 22:16:33 2021 +0000
+++ b/simtool/dispatch.c	Sun Jan 24 22:46:41 2021 +0000
@@ -18,6 +18,7 @@
 extern int cmd_readef();
 extern int cmd_readrec();
 extern int cmd_select();
+extern int cmd_telecom_sum();
 
 extern int display_sim_resp_in_hex();
 
@@ -43,6 +44,7 @@
 	{"readrec", 1, 2, cmd_readrec},
 	{"select", 1, 1, cmd_select},
 	{"sim-resp", 0, 0, display_sim_resp_in_hex},
+	{"telecom-sum", 0, 0, cmd_telecom_sum},
 	{0, 0, 0, 0}
 };
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/simtool/telsum.c	Sun Jan 24 22:46:41 2021 +0000
@@ -0,0 +1,84 @@
+/*
+ * This module implements the telecom-sum (summary info) command.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <pcsclite.h>
+#include <winscard.h>
+#include "globals.h"
+#include "file_id.h"
+
+static
+do_phonebook_file(file_id, book_name)
+	unsigned file_id;
+	char *book_name;
+{
+	int rc;
+
+	rc = select_op(file_id);
+	if (rc < 0) {
+		printf("%s not present\n", book_name);
+		return(rc);
+	}
+	rc = parse_ef_select_response();
+	if (rc < 0) {
+		fprintf(stderr, "error occurred on SELECT of EF_%s\n",
+			book_name);
+		return(rc);
+	}
+	if (curfile_structure != 0x01) {
+		fprintf(stderr, "error: EF_%s is not linear fixed\n",
+			book_name);
+		return(-1);
+	}
+	if (curfile_record_len < 14) {
+		fprintf(stderr,
+	"error: EF_%s has record length of %u bytes, less than minimum 14\n",
+			book_name, curfile_record_len);
+		return(-1);
+	}
+	printf("%s has %u entries, %u bytes of alpha tag\n", book_name,
+		curfile_record_count, curfile_record_len - 14);
+	return(0);
+}
+
+static
+do_sms_store()
+{
+	int rc;
+
+	rc = select_op(EF_SMS);
+	if (rc < 0) {
+		printf("EF_SMS not present\n");
+		return(rc);
+	}
+	rc = parse_ef_select_response();
+	if (rc < 0) {
+		fprintf(stderr, "error occurred on SELECT of EF_SMS\n");
+		return(rc);
+	}
+	if (curfile_structure != 0x01 || curfile_record_len != 176) {
+		fprintf(stderr,
+		"error: EF_SMS is not linear fixed with 176-byte records\n");
+		return(-1);
+	}
+	printf("SMS store has %u entries\n", curfile_record_count);
+	return(0);
+}
+
+cmd_telecom_sum()
+{
+	int rc;
+
+	rc = select_op(DF_TELECOM);
+	if (rc < 0)
+		return(rc);
+	do_phonebook_file(EF_ADN, "ADN");
+	do_phonebook_file(EF_FDN, "FDN");
+	do_phonebook_file(EF_SDN, "SDN");
+	do_phonebook_file(EF_MSISDN, "MSISDN");
+	do_sms_store();
+	return(0);
+}