FreeCalypso > hg > fc-pcsc-tools
annotate simtool/stktest.c @ 139:c13ed9194ecd
fc-uicc-tool create-file implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 24 Feb 2021 17:08:37 +0000 |
parents | 277c66de296f |
children | a1aa8ee2da85 |
rev | line source |
---|---|
137
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements some commands for testing SIM Toolkit functionality, |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * just enough to be able to simulate SMS-PP SIM data download operations. |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include "simresp.h" |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 cmd_terminal_profile(argc, argv) |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 char **argv; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 { |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 u_char cmd[260]; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 int rc; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 unsigned len; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 rc = decode_hex_data_from_string(argv[1], cmd + 5, 1, 255); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 if (rc < 0) |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 return(rc); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 len = rc; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 /* TERMINAL PROFILE command APDU */ |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 cmd[0] = 0xA0; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 cmd[1] = 0x10; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 cmd[2] = 0; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 cmd[3] = 0; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 cmd[4] = len; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 rc = apdu_exchange(cmd, len + 5); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 if (rc < 0) |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 return(rc); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 printf("%04X\n", sim_resp_sw); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 return(0); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 } |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 cmd_envelope(argc, argv) |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 char **argv; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 { |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 u_char cmd[260]; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 int rc; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 unsigned len; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 rc = read_hex_data_file(argv[1], cmd + 5); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 if (rc < 0) |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 return(rc); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 len = rc; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 /* ENVELOPE command APDU */ |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 cmd[0] = 0xA0; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 cmd[1] = 0xC2; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 cmd[2] = 0; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 cmd[3] = 0; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 cmd[4] = len; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 rc = apdu_exchange(cmd, len + 5); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 if (rc < 0) |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 return(rc); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 printf("%04X\n", sim_resp_sw); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 return(0); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 } |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 cmd_envelope_imm(argc, argv) |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 char **argv; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 { |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 u_char cmd[260]; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 int rc; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 unsigned len; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 rc = decode_hex_data_from_string(argv[1], cmd + 5, 1, 255); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 if (rc < 0) |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 return(rc); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 len = rc; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 /* ENVELOPE command APDU */ |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 cmd[0] = 0xA0; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 cmd[1] = 0xC2; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 cmd[2] = 0; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 cmd[3] = 0; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 cmd[4] = len; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 rc = apdu_exchange(cmd, len + 5); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 if (rc < 0) |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 return(rc); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 printf("%04X\n", sim_resp_sw); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 return(0); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 } |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 cmd_get_response(argc, argv, outf) |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 char **argv; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 FILE *outf; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 { |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 u_char cmd[5]; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 int rc; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 unsigned len; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 len = strtoul(argv[1], 0, 0); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 if (len < 1 || len > 256) { |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 fprintf(stderr, "error: length argument is out of range\n"); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 return(-1); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 } |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 /* GET RESPONSE command APDU */ |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 cmd[0] = 0xA0; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 cmd[1] = 0xC0; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 cmd[2] = 0; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 cmd[3] = 0; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 cmd[4] = len; |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 rc = apdu_exchange(cmd, 5); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 if (rc < 0) |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 return(rc); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 if (sim_resp_sw != 0x9000) { |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 fprintf(stderr, "bad SW resp to GET RESPONSE: %04X\n", |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 sim_resp_sw); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 return(-1); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 } |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 display_sim_resp_in_hex(outf); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 return(0); |
277c66de296f
fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 } |