changeset 135:51d6aaa43a7b

fc-uicc-tool: telecom-sum command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 04 Feb 2021 02:55:31 +0000
parents 69628bcfec17
children a21d348e01db
files uicc/Makefile uicc/dispatch.c uicc/select.c uicc/telsum.c
diffstat 4 files changed, 112 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/uicc/Makefile	Thu Feb 04 02:28:52 2021 +0000
+++ b/uicc/Makefile	Thu Feb 04 02:55:31 2021 +0000
@@ -2,7 +2,7 @@
 CFLAGS=	-O2 -I/usr/include/PCSC
 PROG=	fc-uicc-tool
 OBJS=	apdu.o atr.o cardconnect.o dispatch.o exit.o globals.o hexdump.o \
-	hlread.o main.o names.o readcmd.o readops.o script.o select.o
+	hlread.o main.o names.o readcmd.o readops.o script.o select.o telsum.o
 
 all:	${PROG}
 
--- a/uicc/dispatch.c	Thu Feb 04 02:28:52 2021 +0000
+++ b/uicc/dispatch.c	Thu Feb 04 02:55:31 2021 +0000
@@ -13,6 +13,7 @@
 extern int cmd_readbin();
 extern int cmd_readrec();
 extern int cmd_select();
+extern int cmd_telecom_sum();
 
 extern int display_sim_resp_in_hex();
 extern int good_exit();
@@ -31,6 +32,7 @@
 	{"readrec", 2, 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}
 };
 
--- a/uicc/select.c	Thu Feb 04 02:28:52 2021 +0000
+++ b/uicc/select.c	Thu Feb 04 02:55:31 2021 +0000
@@ -223,3 +223,35 @@
 		*lenp = (tlv[2] << 8) | tlv[3];
 	return(0);
 }
+
+select_resp_get_linear_fixed(rec_len_ret, rec_count_ret)
+	unsigned *rec_len_ret, *rec_count_ret;
+{
+	u_char *tlv;
+	unsigned reclen;
+
+	tlv = extract_select_resp_tag(0x82);
+	if (!tlv)
+		return(-1);
+	if (tlv[1] != 5) {
+bad_file_desc:	fprintf(stderr, "error: file type is not linear fixed EF\n");
+		return(-1);
+	}
+	if (tlv[2] & 0x80)
+		goto bad_file_desc;
+	if ((tlv[2] & 0x38) == 0x38)
+		goto bad_file_desc;
+	if ((tlv[2] & 0x07) != 0x02)
+		goto bad_file_desc;
+	reclen = (tlv[4] << 8) | tlv[5];
+	if (reclen < 1 || reclen > 255) {
+		fprintf(stderr,
+			"error: SELECT response gives invalid record length\n");
+		return(-1);
+	}
+	if (rec_len_ret)
+		*rec_len_ret = reclen;
+	if (rec_count_ret)
+		*rec_count_ret = tlv[6];
+	return(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/uicc/telsum.c	Thu Feb 04 02:55:31 2021 +0000
@@ -0,0 +1,77 @@
+/*
+ * This module implements the telecom-sum (summary info) command.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "file_id.h"
+
+static
+do_phonebook_file(file_id, book_name)
+	unsigned file_id;
+	char *book_name;
+{
+	unsigned record_len, record_count;
+	int rc;
+
+	rc = select_op(file_id);
+	if (rc < 0) {
+		printf("%s not present\n", book_name);
+		return(rc);
+	}
+	rc = select_resp_get_linear_fixed(&record_len, &record_count);
+	if (rc < 0) {
+		fprintf(stderr, "error occurred on SELECT of EF_%s\n",
+			book_name);
+		return(rc);
+	}
+	if (record_len < 14) {
+		fprintf(stderr,
+	"error: EF_%s has record length of %u bytes, less than minimum 14\n",
+			book_name, record_len);
+		return(-1);
+	}
+	printf("%s has %u entries, %u bytes of alpha tag\n", book_name,
+		record_count, record_len - 14);
+	return(0);
+}
+
+static
+do_sms_store()
+{
+	unsigned record_len, record_count;
+	int rc;
+
+	rc = select_op(EF_SMS);
+	if (rc < 0) {
+		printf("EF_SMS not present\n");
+		return(rc);
+	}
+	rc = select_resp_get_linear_fixed(&record_len, &record_count);
+	if (rc < 0) {
+		fprintf(stderr, "error occurred on SELECT of EF_SMS\n");
+		return(rc);
+	}
+	if (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", 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);
+}