comparison 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
comparison
equal deleted inserted replaced
9:c9ef9e91dd8e 10:ddd767f6e15b
1 /*
2 * This module implements the a38 command for exercising
3 * the SIM's RUN GSM ALGORITHM operation.
4 */
5
6 #include <sys/types.h>
7 #include <ctype.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "simresp.h"
11
12 cmd_a38(argc, argv, outf)
13 char **argv;
14 FILE *outf;
15 {
16 u_char cmd[21];
17 int rc;
18
19 /* RUN GSM ALGORITHM command APDU */
20 cmd[0] = 0xA0;
21 cmd[1] = 0x88;
22 cmd[2] = 0;
23 cmd[3] = 0;
24 cmd[4] = 16;
25 rc = decode_hex_data_from_string(argv[1], cmd + 5, 16, 16);
26 if (rc < 0)
27 return(rc);
28 rc = apdu_exchange(cmd, 21);
29 if (rc < 0)
30 return(rc);
31 if (sim_resp_sw != 0x9F0C) {
32 fprintf(stderr,
33 "error or unexpected SW response to RUN GSM ALGO: %04X\n",
34 sim_resp_sw);
35 return(-1);
36 }
37 /* GET RESPONSE follow-up */
38 cmd[1] = 0xC0;
39 cmd[4] = 12;
40 rc = apdu_exchange(cmd, 5);
41 if (rc < 0)
42 return(rc);
43 if (sim_resp_sw != 0x9000) {
44 fprintf(stderr, "bad SW resp to GET RESPONSE: %04X\n",
45 sim_resp_sw);
46 return(-1);
47 }
48 if (sim_resp_data_len != 12) {
49 fprintf(stderr,
50 "error: GET RESPONSE returned %u bytes, expected 12\n",
51 sim_resp_data_len);
52 return(-1);
53 }
54 fprintf(outf, "SRES: %02X %02X %02X %02X\n", sim_resp_data[0],
55 sim_resp_data[1], sim_resp_data[2], sim_resp_data[3]);
56 fprintf(outf, "Kc: %02X %02X %02X %02X %02X %02X %02X %02X\n",
57 sim_resp_data[4], sim_resp_data[5], sim_resp_data[6],
58 sim_resp_data[7], sim_resp_data[8], sim_resp_data[9],
59 sim_resp_data[10], sim_resp_data[11]);
60 return(0);
61 }