comparison simtool/readef.c @ 171:4d747b86da00

simtool code: readef command implementation split off
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 02 Mar 2021 03:03:49 +0000
parents simtool/readcmd.c@f1836c8d36cb
children e7e0d8c06654
comparison
equal deleted inserted replaced
170:13b8d90eb5c7 171:4d747b86da00
1 /*
2 * This module implements the readef command for dumping the complete
3 * content of SIM files.
4 */
5
6 #include <sys/types.h>
7 #include <ctype.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "simresp.h"
11 #include "curfile.h"
12
13 cmd_readef(argc, argv, outf)
14 char **argv;
15 FILE *outf;
16 {
17 int file_id, rc;
18 unsigned readlen;
19
20 if (isxdigit(argv[1][0]) && isxdigit(argv[1][1]) &&
21 isxdigit(argv[1][2]) && isxdigit(argv[1][3]) && !argv[1][4])
22 file_id = strtoul(argv[1], 0, 16);
23 else
24 file_id = find_symbolic_file_name(argv[1]);
25 if (file_id < 0) {
26 fprintf(stderr,
27 "error: file ID argument is not a hex value or a recognized symbolic name\n");
28 return(-1);
29 }
30 rc = select_op(file_id);
31 if (rc < 0)
32 return(rc);
33 rc = parse_ef_select_response();
34 if (rc < 0)
35 return(rc);
36 if (curfile_structure != 0x00) {
37 fprintf(stderr,
38 "error: readef command is only for transparent EFs\n");
39 return(-1);
40 }
41 if (outf == stdout) {
42 printf("Transparent EF of %u byte(s)\n", curfile_total_size);
43 printf("File status: %02X\n", sim_resp_data[11]);
44 show_access_conditions("UPDATE", sim_resp_data[8] & 0xF);
45 show_access_conditions("READ & SEEK", sim_resp_data[8] >> 4);
46 show_access_conditions("INCREASE", sim_resp_data[9] >> 4);
47 show_access_conditions("INVALIDATE", sim_resp_data[10] & 0xF);
48 show_access_conditions("REHABILITATE", sim_resp_data[10] >> 4);
49 }
50 if (!curfile_total_size)
51 return(0);
52 readlen = curfile_total_size;
53 if (readlen > 256)
54 readlen = 256;
55 rc = readbin_op(0, readlen);
56 if (rc < 0)
57 return(rc);
58 display_sim_resp_in_hex(outf);
59 return(0);
60 }