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