comparison 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
comparison
equal deleted inserted replaced
143:be1a759453ef 144:60411fd4b803
1 /*
2 * This module implements an elementary GET RESPONSE command
3 */
4
5 #include <sys/types.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include "simresp.h"
9
10 cmd_get_response(argc, argv, outf)
11 char **argv;
12 FILE *outf;
13 {
14 u_char cmd[5];
15 int rc;
16 unsigned len;
17
18 len = strtoul(argv[1], 0, 0);
19 if (len < 1 || len > 256) {
20 fprintf(stderr, "error: length argument is out of range\n");
21 return(-1);
22 }
23 /* GET RESPONSE command APDU */
24 cmd[0] = 0xA0;
25 cmd[1] = 0xC0;
26 cmd[2] = 0;
27 cmd[3] = 0;
28 cmd[4] = len;
29 rc = apdu_exchange(cmd, 5);
30 if (rc < 0)
31 return(rc);
32 if (sim_resp_sw != 0x9000) {
33 fprintf(stderr, "bad SW resp to GET RESPONSE: %04X\n",
34 sim_resp_sw);
35 return(-1);
36 }
37 display_sim_resp_in_hex(outf);
38 return(0);
39 }