FreeCalypso > hg > freecalypso-hwlab
annotate uicc/readcmd.c @ 176:fb2f6497ba53 default tip
doc/Linux-DTR-RTS-flaw: point to new location of this article
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 11 Dec 2023 19:37:20 +0000 |
parents | 19b96c52348f |
children |
rev | line source |
---|---|
133
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <sys/types.h> |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <stdio.h> |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <stdlib.h> |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <pcsclite.h> |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <winscard.h> |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include "globals.h" |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 cmd_readbin(argc, argv) |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 char **argv; |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 { |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 unsigned offset, len; |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 int rc; |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 offset = strtoul(argv[1], 0, 0); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 if (offset > 0x7FFF) { |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 fprintf(stderr, "error: offset argument is out of range\n"); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 return(-1); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 } |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 len = strtoul(argv[2], 0, 0); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 if (len < 1 || len > 256) { |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 fprintf(stderr, "error: length argument is out of range\n"); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 return(-1); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 } |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 rc = readbin_op(offset, len); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (rc < 0) |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 return(rc); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 display_sim_resp_in_hex(); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 return(0); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 } |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 cmd_readrec(argc, argv) |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 char **argv; |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 { |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 unsigned recno, len; |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 int rc; |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 recno = strtoul(argv[1], 0, 0); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 if (recno < 1 || recno > 255) { |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 fprintf(stderr, |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 "error: record number argument is out of range\n"); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 return(-1); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 } |
144
429a8f80426e
fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
43 if (argv[2]) { |
429a8f80426e
fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
44 len = strtoul(argv[2], 0, 0); |
429a8f80426e
fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
45 if (len < 1 || len > 255) { |
429a8f80426e
fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
46 fprintf(stderr, |
429a8f80426e
fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
47 "error: length argument is out of range\n"); |
429a8f80426e
fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
48 return(-1); |
429a8f80426e
fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
49 } |
429a8f80426e
fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
50 } else { |
429a8f80426e
fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
51 if (!last_sel_file_record_len) { |
429a8f80426e
fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
52 fprintf(stderr, |
429a8f80426e
fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
53 "error: no current file record length is available\n"); |
429a8f80426e
fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
54 return(-1); |
429a8f80426e
fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
55 } |
429a8f80426e
fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
56 len = last_sel_file_record_len; |
133
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 } |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 rc = readrec_op(recno, 0x04, len); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 if (rc < 0) |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 return(rc); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 display_sim_resp_in_hex(); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 return(0); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 } |
160
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
64 |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
65 cmd_readef(argc, argv) |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
66 char **argv; |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
67 { |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
68 int file_id, rc; |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
69 unsigned file_len, readlen; |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
70 |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
71 if (isxdigit(argv[1][0]) && isxdigit(argv[1][1]) && |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
72 isxdigit(argv[1][2]) && isxdigit(argv[1][3]) && !argv[1][4]) |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
73 file_id = strtoul(argv[1], 0, 16); |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
74 else |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
75 file_id = find_symbolic_file_name(argv[1]); |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
76 if (file_id < 0) { |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
77 fprintf(stderr, |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
78 "error: file ID argument is not a hex value or a recognized symbolic name\n"); |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
79 return(-1); |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
80 } |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
81 rc = select_op(file_id); |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
82 if (rc < 0) |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
83 return(rc); |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
84 rc = select_resp_get_transparent(&file_len); |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
85 if (rc < 0) |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
86 return(rc); |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
87 printf("Transparent EF of %u byte(s)\n", file_len); |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
88 if (!file_len) |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
89 return(0); |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
90 readlen = file_len; |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
91 if (readlen > 256) |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
92 readlen = 256; |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
93 rc = readbin_op(0, readlen); |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
94 if (rc < 0) |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
95 return(rc); |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
96 display_sim_resp_in_hex(); |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
97 return(0); |
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
98 } |