FreeCalypso > hg > fc-pcsc-tools
annotate simtool/stktest.c @ 179:efe944a5c4e3
doc/Brute-force-search: update for data directory rename
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 02 Mar 2021 05:20:19 +0000 |
parents | 60411fd4b803 |
children |
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 |
141
a1aa8ee2da85
read_hex_data_file(): add maxlen argument
Mychaela Falconia <falcon@freecalypso.org>
parents:
137
diff
changeset
|
42 rc = read_hex_data_file(argv[1], cmd + 5, 255); |
137
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 } |