annotate simtool/a38.c @ 174:4f5abad5dd40

doc/Unbuffered-FT2232x-JTAG: update for fc-usbser-tools
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 11 Sep 2023 07:23:18 +0000
parents 250d172662ca
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
127
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements the a38 command for exercising
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * the SIM's RUN GSM ALGORITHM operation.
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <ctype.h>
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <pcsclite.h>
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <winscard.h>
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "globals.h"
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 cmd_a38(argc, argv)
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 char **argv;
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 {
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 u_char cmd[21];
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 int rc;
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 /* RUN GSM ALGORITHM command APDU */
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 cmd[0] = 0xA0;
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 cmd[1] = 0x88;
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 cmd[2] = 0;
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 cmd[3] = 0;
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 cmd[4] = 16;
152
250d172662ca fc-simtool a38 command: use generalized hex string parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents: 127
diff changeset
26 rc = decode_hex_data_from_string(argv[1], cmd + 5, 16, 16);
127
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (rc < 0)
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 return(rc);
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 rc = apdu_exchange(cmd, 21);
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 if (rc < 0)
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 return(rc);
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (sim_resp_sw != 0x9F0C) {
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 fprintf(stderr,
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 "error or unexpected SW response to RUN GSM ALGO: %04X\n",
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 sim_resp_sw);
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 return(-1);
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 }
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 /* GET RESPONSE follow-up */
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 cmd[1] = 0xC0;
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 cmd[4] = 12;
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 rc = apdu_exchange(cmd, 5);
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 if (rc < 0)
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 return(rc);
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 if (sim_resp_sw != 0x9000) {
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 fprintf(stderr, "bad SW resp to GET RESPONSE: %04X\n",
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 sim_resp_sw);
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 return(-1);
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 if (sim_resp_data_len != 12) {
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 fprintf(stderr,
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 "error: GET RESPONSE returned %u bytes, expected 12\n",
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 sim_resp_data_len);
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 return(-1);
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 printf("SRES: %02X %02X %02X %02X\n", sim_resp_data[0],
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 sim_resp_data[1], sim_resp_data[2], sim_resp_data[3]);
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 printf("Kc: %02X %02X %02X %02X %02X %02X %02X %02X\n",
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 sim_resp_data[4], sim_resp_data[5], sim_resp_data[6],
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 sim_resp_data[7], sim_resp_data[8], sim_resp_data[9],
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 sim_resp_data[10], sim_resp_data[11]);
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 return(0);
141489d31667 fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 }