comparison simtool/stktest.c @ 137:277c66de296f

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