FreeCalypso > hg > freecalypso-hwlab
annotate simtool/readcmd.c @ 92:0ead9444a698
fc-simtool: read operation functions factored out
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 24 Jan 2021 19:59:10 +0000 |
parents | 226b231d00f3 |
children | 5f826e428641 |
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 } |