changeset 93:d4150123ca45

fc-simtool: some refactoring of SELECT response parsing
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 24 Jan 2021 20:25:04 +0000
parents 0ead9444a698
children b84df973cd8b
files simtool/globals.c simtool/globals.h simtool/select.c
diffstat 3 files changed, 16 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/globals.c	Sun Jan 24 19:59:10 2021 +0000
+++ b/simtool/globals.c	Sun Jan 24 20:25:04 2021 +0000
@@ -7,4 +7,5 @@
 char *reader_name_buf;
 u_char sim_resp_data[258];
 unsigned sim_resp_data_len, sim_resp_sw;
-unsigned curfile_record_len;
+unsigned curfile_total_size, curfile_structure;
+unsigned curfile_record_len, curfile_record_count;
--- a/simtool/globals.h	Sun Jan 24 19:59:10 2021 +0000
+++ b/simtool/globals.h	Sun Jan 24 20:25:04 2021 +0000
@@ -5,4 +5,5 @@
 extern char *reader_name_buf;
 extern u_char sim_resp_data[];
 extern unsigned sim_resp_data_len, sim_resp_sw;
-extern unsigned curfile_record_len;
+extern unsigned curfile_total_size, curfile_structure;
+extern unsigned curfile_record_len, curfile_record_count;
--- a/simtool/select.c	Sun Jan 24 19:59:10 2021 +0000
+++ b/simtool/select.c	Sun Jan 24 20:25:04 2021 +0000
@@ -83,7 +83,6 @@
 	char **argv;
 {
 	int file_id, rc;
-	unsigned file_size;
 
 	if (isxdigit(argv[1][0]) && isxdigit(argv[1][1]) &&
 	    isxdigit(argv[1][2]) && isxdigit(argv[1][3]) && !argv[1][4])
@@ -128,9 +127,10 @@
 		break;
 	case 0x04:
 		printf("File type: EF\n");
-		file_size = (sim_resp_data[2] << 8) | sim_resp_data[3];
-		printf("File size: %u\n", file_size);
-		switch (sim_resp_data[13]) {
+		curfile_total_size = (sim_resp_data[2] << 8) | sim_resp_data[3];
+		printf("File size: %u\n", curfile_total_size);
+		curfile_structure = sim_resp_data[13];
+		switch (curfile_structure) {
 		case 0x00:
 			printf("Structure: transparent\n");
 			break;
@@ -148,13 +148,18 @@
 			}
 			printf("Record length: %u\n", sim_resp_data[14]);
 			curfile_record_len = sim_resp_data[14];
-			if (file_size % curfile_record_len == 0)
+			if (curfile_record_len &&
+			    curfile_total_size % curfile_record_len == 0) {
+				curfile_record_count =
+					curfile_total_size / curfile_record_len;
 				printf("Number of records: %u\n",
-					file_size / curfile_record_len);
+					curfile_record_count);
+			} else
+				curfile_record_count = 0;
 			break;
 		default:
 			printf("Structure: %02X (unknown)\n",
-				sim_resp_data[13]);
+				curfile_structure);
 		}
 		printf("File status: %02X\n", sim_resp_data[11]);
 		show_access_conditions("UPDATE", sim_resp_data[8] & 0xF);