comparison simtool/a38.c @ 1:2071b28cd0c7

simtool: first refactored version
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 11 Feb 2021 23:04:28 +0000
parents
children e17940d7ce35
comparison
equal deleted inserted replaced
0:f7145c77b7fb 1:2071b28cd0c7
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)
13 char **argv;
14 {
15 u_char cmd[21];
16 int rc;
17
18 /* RUN GSM ALGORITHM command APDU */
19 cmd[0] = 0xA0;
20 cmd[1] = 0x88;
21 cmd[2] = 0;
22 cmd[3] = 0;
23 cmd[4] = 16;
24 rc = decode_hex_data_from_string(argv[1], cmd + 5, 16, 16);
25 if (rc < 0)
26 return(rc);
27 rc = apdu_exchange(cmd, 21);
28 if (rc < 0)
29 return(rc);
30 if (sim_resp_sw != 0x9F0C) {
31 fprintf(stderr,
32 "error or unexpected SW response to RUN GSM ALGO: %04X\n",
33 sim_resp_sw);
34 return(-1);
35 }
36 /* GET RESPONSE follow-up */
37 cmd[1] = 0xC0;
38 cmd[4] = 12;
39 rc = apdu_exchange(cmd, 5);
40 if (rc < 0)
41 return(rc);
42 if (sim_resp_sw != 0x9000) {
43 fprintf(stderr, "bad SW resp to GET RESPONSE: %04X\n",
44 sim_resp_sw);
45 return(-1);
46 }
47 if (sim_resp_data_len != 12) {
48 fprintf(stderr,
49 "error: GET RESPONSE returned %u bytes, expected 12\n",
50 sim_resp_data_len);
51 return(-1);
52 }
53 printf("SRES: %02X %02X %02X %02X\n", sim_resp_data[0],
54 sim_resp_data[1], sim_resp_data[2], sim_resp_data[3]);
55 printf("Kc: %02X %02X %02X %02X %02X %02X %02X %02X\n",
56 sim_resp_data[4], sim_resp_data[5], sim_resp_data[6],
57 sim_resp_data[7], sim_resp_data[8], sim_resp_data[9],
58 sim_resp_data[10], sim_resp_data[11]);
59 return(0);
60 }