# HG changeset patch # User Mychaela Falconia # Date 1614656021 0 # Node ID e70964adcbba9b420571d1faf15c682c674f17c7 # Parent e7e0d8c06654cfc03c637466b89ee2e93f9cb870 fc-simtool readef extended to fully dump all files diff -r e7e0d8c06654 -r e70964adcbba simtool/readef.c --- a/simtool/readef.c Tue Mar 02 03:18:21 2021 +0000 +++ b/simtool/readef.c Tue Mar 02 03:33:41 2021 +0000 @@ -10,6 +10,77 @@ #include "simresp.h" #include "curfile.h" +static void +hexdump_with_offset(outf, extoff) + FILE *outf; + unsigned extoff; +{ + unsigned off, cc, n, c; + + for (off = 0; off < sim_resp_data_len; off += cc) { + fprintf(outf, "%04X:", extoff + off); + cc = 16; + if (sim_resp_data_len - off < cc) + cc = sim_resp_data_len - off; + for (n = 0; n < 16; n++) { + if (n == 0 || n == 8) + putc(' ', outf); + putc(' ', outf); + if (n < cc) + fprintf(outf, "%02X", sim_resp_data[off + n]); + else { + putc(' ', outf); + putc(' ', outf); + } + } + putc(' ', outf); + putc(' ', outf); + for (n = 0; n < cc; n++) { + c = sim_resp_data[off + n]; + if (c < 0x20 || c > 0x7E) + c = '.'; + putc(c, outf); + } + putc('\n', outf); + } +} + +static +readef_transparent(outf) + FILE *outf; +{ + unsigned off, cc; + int rc; + + for (off = 0; off < curfile_total_size; off += cc) { + cc = curfile_total_size - off; + if (cc > 256) + cc = 256; + rc = readbin_op(off, cc); + if (rc < 0) + return(rc); + hexdump_with_offset(outf, off); + } + return(0); +} + +static +readef_records(outf) + FILE *outf; +{ + unsigned recno; + int rc; + + for (recno = 1; recno <= curfile_record_count; recno++) { + fprintf(outf, "Record #%u:\n", recno); + rc = readrec_op(recno, 0x04, curfile_record_len); + if (rc < 0) + return(rc); + display_sim_resp_in_hex(outf); + } + return(0); +} + cmd_readef(argc, argv, outf) char **argv; FILE *outf; @@ -33,26 +104,24 @@ rc = parse_ef_select_response(); if (rc < 0) return(rc); - if (curfile_structure != 0x00) { - fprintf(stderr, - "error: readef command is only for transparent EFs\n"); - return(-1); - } - fprintf(outf, "Transparent EF of %u byte(s)\n", curfile_total_size); - fprintf(outf, "File status: %02X\n", sim_resp_data[11]); show_access_conditions(outf, "UPDATE", sim_resp_data[8] & 0xF); show_access_conditions(outf, "READ & SEEK", sim_resp_data[8] >> 4); show_access_conditions(outf, "INCREASE", sim_resp_data[9] >> 4); show_access_conditions(outf, "INVALIDATE", sim_resp_data[10] & 0xF); show_access_conditions(outf, "REHABILITATE", sim_resp_data[10] >> 4); - if (!curfile_total_size) - return(0); - readlen = curfile_total_size; - if (readlen > 256) - readlen = 256; - rc = readbin_op(0, readlen); - if (rc < 0) - return(rc); - display_sim_resp_in_hex(outf); - return(0); + fprintf(outf, "File status: %02X\n", sim_resp_data[11]); + switch (curfile_structure) { + case 0x00: + fprintf(outf, "Transparent EF of %u byte(s)\n", + curfile_total_size); + return readef_transparent(outf); + case 0x01: + fprintf(outf, "%u records of %u bytes (linear fixed)\n", + curfile_record_count, curfile_record_len); + return readef_records(outf); + case 0x03: + fprintf(outf, "%u records of %u bytes (cyclic)\n", + curfile_record_count, curfile_record_len); + return readef_records(outf); + } }