comparison libcommon/apducmd.c @ 57:bccf028921bb

apdu-checksw command added to both fc-simtool and fc-uicc-tool
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 22 Mar 2021 23:58:11 +0000
parents c9ef9e91dd8e
children
comparison
equal deleted inserted replaced
56:b9fc7022f9ac 57:bccf028921bb
3 * for users to manually send arbitrary APDUs. 3 * for users to manually send arbitrary APDUs.
4 */ 4 */
5 5
6 #include <sys/types.h> 6 #include <sys/types.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <stdlib.h>
8 #include "simresp.h" 9 #include "simresp.h"
9 10
10 cmd_apdu(argc, argv) 11 cmd_apdu(argc, argv)
11 char **argv; 12 char **argv;
12 { 13 {
22 if (rc < 0) 23 if (rc < 0)
23 return(rc); 24 return(rc);
24 printf("%04X\n", sim_resp_sw); 25 printf("%04X\n", sim_resp_sw);
25 return(0); 26 return(0);
26 } 27 }
28
29 cmd_apdu_checksw(argc, argv)
30 char **argv;
31 {
32 u_char cmd[260];
33 int rc;
34 unsigned len, expect_sw;
35
36 rc = decode_hex_data_from_string(argv[1], cmd, 5, 260);
37 if (rc < 0)
38 return(rc);
39 len = rc;
40 expect_sw = strtoul(argv[2], 0, 16);
41 rc = apdu_exchange(cmd, len);
42 if (rc < 0)
43 return(rc);
44 if (sim_resp_sw == expect_sw)
45 return(0);
46 else {
47 fprintf(stderr,
48 "SW response mismatch: expected %04X, got %04X\n",
49 expect_sw, sim_resp_sw);
50 return(-1);
51 }
52 }