FreeCalypso > hg > fc-pcsc-tools
annotate simtool/getresp.c @ 144:60411fd4b803
simtool code: cmd_get_response() factored out of stktest.c
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 25 Feb 2021 05:44:27 +0000 |
parents | simtool/stktest.c@a1aa8ee2da85 |
children | c2889812788e |
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 } |