annotate simtool/a38.c @ 10:ddd767f6e15b

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