changeset 106:dcfec53643c5

EF_DIR dump commands support output redirection
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 19 Feb 2021 06:24:06 +0000
parents 16481db543e8
children f1836c8d36cb
files libcommon/dumpdirfunc.c simtool/dispatch.c simtool/dumpdir.c uicc/dispatch.c uicc/dumpdir.c
diffstat 5 files changed, 41 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/libcommon/dumpdirfunc.c	Fri Feb 19 06:07:49 2021 +0000
+++ b/libcommon/dumpdirfunc.c	Fri Feb 19 06:24:06 2021 +0000
@@ -7,80 +7,86 @@
 #include "simresp.h"
 
 static void
-dump_aid(tlv)
+dump_aid(tlv, outf)
 	u_char *tlv;
+	FILE *outf;
 {
 	unsigned reclen, n;
 
 	reclen = tlv[1];
-	printf(" AID:");
+	fputs(" AID:", outf);
 	for (n = 0; n < reclen; n++)
-		printf(" %02X", tlv[n+2]);
-	putchar('\n');
+		fprintf(outf, " %02X", tlv[n+2]);
+	putc('\n', outf);
 }
 
 static void
-dump_label(tlv)
+dump_label(tlv, outf)
 	u_char *tlv;
+	FILE *outf;
 {
 	int rc;
 	unsigned textlen;
 
-	printf(" Label: ");
+	fputs(" Label: ", outf);
 	rc = validate_alpha_field(tlv + 2, tlv[1], &textlen);
 	if (rc < 0) {
-		printf("malformed\n");
+		fputs("malformed\n", outf);
 		return;
 	}
-	print_alpha_field(tlv + 2, textlen, stdout);
-	putchar('\n');
+	print_alpha_field(tlv + 2, textlen, outf);
+	putc('\n', outf);
 }
 
 static void
-dump_unknown_tlv(tlv)
+dump_unknown_tlv(tlv, outf)
 	u_char *tlv;
+	FILE *outf;
 {
 	unsigned reclen, n;
 
 	reclen = tlv[1] + 2;
-	printf(" TLV:");
+	fputs(" TLV:", outf);
 	for (n = 0; n < reclen; n++)
-		printf(" %02X", tlv[n]);
-	putchar('\n');
+		fprintf(outf, " %02X", tlv[n]);
+	putc('\n', outf);
 }
 
 void
-dump_efdir_record()
+dump_efdir_record(outf)
+	FILE *outf;
 {
 	unsigned totlen, reclen;
 	u_char *dp, *endp;
 
 	if (sim_resp_data[0] != 0x61) {
-		printf(" bad: first byte != 0x61\n");
+		fprintf(outf, " bad: first byte != 0x61\n");
 		return;
 	}
 	totlen = sim_resp_data[1];
 	if (totlen < 3 || totlen > 0x7F) {
-		printf(" bad: global length byte 0x%02X is invalid\n", totlen);
+		fprintf(outf, " bad: global length byte 0x%02X is invalid\n",
+			totlen);
 		return;
 	}
 	if (totlen + 2 > sim_resp_data_len) {
-		printf(" bad: TLV global length exceeds EF record length\n");
+		fprintf(outf,
+			" bad: TLV global length exceeds EF record length\n");
 		return;
 	}
 	dp = sim_resp_data + 2;
 	endp = sim_resp_data + 2 + totlen;
 	while (dp < endp) {
 		if (endp - dp < 2) {
-trunc_error:		printf(" bad: truncated TLV record\n");
+trunc_error:		fprintf(outf, " bad: truncated TLV record\n");
 			return;
 		}
 		if ((dp[0] & 0x1F) == 0x1F) {
-			printf(" bad: extended tag not supported\n");
+			fprintf(outf, " bad: extended tag not supported\n");
 			return;
 		}
 		if (dp[1] & 0x80) {
-			printf(" bad: extended length not supported\n");
+			fprintf(outf, " bad: extended length not supported\n");
 			return;
 		}
 		reclen = dp[1] + 2;
@@ -88,13 +94,13 @@
 			goto trunc_error;
 		switch (dp[0]) {
 		case 0x4F:
-			dump_aid(dp);
+			dump_aid(dp, outf);
 			break;
 		case 0x50:
-			dump_label(dp);
+			dump_label(dp, outf);
 			break;
 		default:
-			dump_unknown_tlv(dp);
+			dump_unknown_tlv(dp, outf);
 		}
 		dp += reclen;
 	}
--- a/simtool/dispatch.c	Fri Feb 19 06:07:49 2021 +0000
+++ b/simtool/dispatch.c	Fri Feb 19 06:24:06 2021 +0000
@@ -169,7 +169,7 @@
 	{"spn", 0, 0, 0, cmd_spn},
 	{"sst", 0, 0, 0, cmd_sst},
 	{"telecom-sum", 0, 0, 0, cmd_telecom_sum},
-	{"uicc-dir", 0, 0, 0, cmd_uicc_dir},
+	{"uicc-dir", 0, 0, 1, cmd_uicc_dir},
 	{"unblock-chv1", 2, 2, 0, cmd_unblock_chv},
 	{"unblock-chv2", 2, 2, 0, cmd_unblock_chv},
 	{"unblock-pin1", 2, 2, 0, cmd_unblock_chv},
--- a/simtool/dumpdir.c	Fri Feb 19 06:07:49 2021 +0000
+++ b/simtool/dumpdir.c	Fri Feb 19 06:24:06 2021 +0000
@@ -7,7 +7,9 @@
 #include "curfile.h"
 #include "file_id.h"
 
-cmd_uicc_dir()
+cmd_uicc_dir(argc, argv, outf)
+	char **argv;
+	FILE *outf;
 {
 	int rc;
 	unsigned recno;
@@ -35,8 +37,8 @@
 			return(rc);
 		if (check_simresp_all_blank())
 			continue;
-		printf("Record #%u:\n", recno);
-		dump_efdir_record();
+		fprintf(outf, "Record #%u:\n", recno);
+		dump_efdir_record(outf);
 	}
 	return(0);
 }
--- a/uicc/dispatch.c	Fri Feb 19 06:07:49 2021 +0000
+++ b/uicc/dispatch.c	Fri Feb 19 06:24:06 2021 +0000
@@ -34,7 +34,7 @@
 	int (*func)();
 } cmdtab[] = {
 	{"atr", 0, 0, 0, retrieve_atr},
-	{"dir", 0, 0, 0, cmd_dir},
+	{"dir", 0, 0, 1, cmd_dir},
 	{"exec", 1, 1, 0, cmd_exec},
 	{"exit", 0, 0, 0, good_exit},
 	{"iccid", 0, 0, 0, cmd_iccid},
--- a/uicc/dumpdir.c	Fri Feb 19 06:07:49 2021 +0000
+++ b/uicc/dumpdir.c	Fri Feb 19 06:24:06 2021 +0000
@@ -6,7 +6,9 @@
 #include <stdio.h>
 #include "file_id.h"
 
-cmd_dir()
+cmd_dir(argc, argv, outf)
+	char **argv;
+	FILE *outf;
 {
 	int rc;
 	unsigned record_len, record_count;
@@ -31,8 +33,8 @@
 			return(rc);
 		if (check_simresp_all_blank())
 			continue;
-		printf("Record #%u:\n", recno);
-		dump_efdir_record();
+		fprintf(outf, "Record #%u:\n", recno);
+		dump_efdir_record(outf);
 	}
 	return(0);
 }