annotate simtool/getresp.c @ 175:eb660497f888

scripts/grcard2-read-all added to collection
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 02 Mar 2021 04:46:21 +0000
parents c2889812788e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
137
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
144
60411fd4b803 simtool code: cmd_get_response() factored out of stktest.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 141
diff changeset
2 * This module implements an elementary GET RESPONSE command
137
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
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 #include <sys/types.h>
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdlib.h>
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include "simresp.h"
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 cmd_get_response(argc, argv, outf)
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 char **argv;
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 FILE *outf;
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[5];
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 len = strtoul(argv[1], 0, 0);
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 if (len < 1 || len > 256) {
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 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
21 return(-1);
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 }
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 /* GET RESPONSE command APDU */
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 cmd[0] = 0xA0;
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 cmd[1] = 0xC0;
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 cmd[2] = 0;
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 cmd[3] = 0;
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 cmd[4] = len;
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 rc = apdu_exchange(cmd, 5);
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 if (rc < 0)
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 return(rc);
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (sim_resp_sw != 0x9000) {
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 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
34 sim_resp_sw);
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 return(-1);
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 }
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 display_sim_resp_in_hex(outf);
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 return(0);
277c66de296f fc-simtool: added STK test commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
145
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
40
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
41 get_response_op()
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
42 {
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
43 u_char cmd[5];
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
44 int rc;
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
45 unsigned expect_resp_len;
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
46
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
47 expect_resp_len = sim_resp_sw & 0xFF;
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
48 /* GET RESPONSE command APDU */
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
49 cmd[0] = 0xA0;
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
50 cmd[1] = 0xC0;
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
51 cmd[2] = 0;
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
52 cmd[3] = 0;
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
53 cmd[4] = expect_resp_len;
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
54 rc = apdu_exchange(cmd, 5);
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
55 if (rc < 0)
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
56 return(rc);
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
57 if (sim_resp_sw != 0x9000) {
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
58 fprintf(stderr, "bad SW resp to GET RESPONSE: %04X\n",
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
59 sim_resp_sw);
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
60 return(-1);
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
61 }
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
62 if (sim_resp_data_len != expect_resp_len) {
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
63 fprintf(stderr,
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
64 "error: GET RESPONSE returned %u bytes, expected %u\n",
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
65 sim_resp_data_len, expect_resp_len);
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
66 return(-1);
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
67 }
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
68 return(0);
c2889812788e fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 144
diff changeset
69 }