FreeCalypso > hg > freecalypso-hwlab
annotate simtool/readcmd.c @ 115:0dcd666292e4
fc-simtool: pb-erase-one command implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 28 Jan 2021 02:56:10 +0000 |
parents | 5f826e428641 |
children |
rev | line source |
---|---|
90
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <sys/types.h> |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <stdio.h> |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <stdlib.h> |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <pcsclite.h> |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <winscard.h> |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include "globals.h" |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 cmd_readbin(argc, argv) |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 char **argv; |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 { |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 unsigned offset, len; |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 int rc; |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 offset = strtoul(argv[1], 0, 0); |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 if (offset > 0xFFFF) { |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 fprintf(stderr, "error: offset argument is out of range\n"); |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 return(-1); |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 } |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 len = strtoul(argv[2], 0, 0); |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 if (len < 1 || len > 256) { |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 fprintf(stderr, "error: length argument is out of range\n"); |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 return(-1); |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 } |
92
0ead9444a698
fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
91
diff
changeset
|
24 rc = readbin_op(offset, len); |
90
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (rc < 0) |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 return(rc); |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 display_sim_resp_in_hex(); |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 return(0); |
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 } |
91
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
30 |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
31 cmd_readrec(argc, argv) |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
32 char **argv; |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
33 { |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
34 unsigned recno, len; |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
35 int rc; |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
36 |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
37 recno = strtoul(argv[1], 0, 0); |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
38 if (recno < 1 || recno > 255) { |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
39 fprintf(stderr, |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
40 "error: record number argument is out of range\n"); |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
41 return(-1); |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
42 } |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
43 if (argv[2]) { |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
44 len = strtoul(argv[2], 0, 0); |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
45 if (len < 1 || len > 255) { |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
46 fprintf(stderr, |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
47 "error: length argument is out of range\n"); |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
48 return(-1); |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
49 } |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
50 } else { |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
51 if (!curfile_record_len) { |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
52 fprintf(stderr, |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
53 "error: no current file record length is available\n"); |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
54 return(-1); |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
55 } |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
56 len = curfile_record_len; |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
57 } |
92
0ead9444a698
fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
91
diff
changeset
|
58 rc = readrec_op(recno, 0x04, len); |
91
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
59 if (rc < 0) |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
60 return(rc); |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
61 display_sim_resp_in_hex(); |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
62 return(0); |
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
63 } |
95
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
64 |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
65 cmd_readef(argc, argv) |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
66 char **argv; |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
67 { |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
68 int file_id, rc; |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
69 unsigned readlen; |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
70 |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
71 if (isxdigit(argv[1][0]) && isxdigit(argv[1][1]) && |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
72 isxdigit(argv[1][2]) && isxdigit(argv[1][3]) && !argv[1][4]) |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
73 file_id = strtoul(argv[1], 0, 16); |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
74 else |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
75 file_id = find_symbolic_file_name(argv[1]); |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
76 if (file_id < 0) { |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
77 fprintf(stderr, |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
78 "error: file ID argument is not a hex value or a recognized symbolic name\n"); |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
79 return(-1); |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
80 } |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
81 rc = select_op(file_id); |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
82 if (rc < 0) |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
83 return(rc); |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
84 rc = parse_ef_select_response(); |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
85 if (rc < 0) |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
86 return(rc); |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
87 if (curfile_structure != 0x00) { |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
88 fprintf(stderr, |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
89 "error: readef command is only for transparent EFs\n"); |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
90 return(-1); |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
91 } |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
92 printf("Transparent EF of %u byte(s)\n", curfile_total_size); |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
93 printf("File status: %02X\n", sim_resp_data[11]); |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
94 show_access_conditions("UPDATE", sim_resp_data[8] & 0xF); |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
95 show_access_conditions("READ & SEEK", sim_resp_data[8] >> 4); |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
96 show_access_conditions("INCREASE", sim_resp_data[9] >> 4); |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
97 show_access_conditions("INVALIDATE", sim_resp_data[10] & 0xF); |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
98 show_access_conditions("REHABILITATE", sim_resp_data[10] >> 4); |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
99 if (!curfile_total_size) |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
100 return(0); |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
101 readlen = curfile_total_size; |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
102 if (readlen > 256) |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
103 readlen = 256; |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
104 rc = readbin_op(0, readlen); |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
105 if (rc < 0) |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
106 return(rc); |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
107 display_sim_resp_in_hex(); |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
108 return(0); |
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
109 } |