comparison simtool/grcard1.c @ 1:2071b28cd0c7

simtool: first refactored version
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 11 Feb 2021 23:04:28 +0000
parents
children 744fabd6bd3f
comparison
equal deleted inserted replaced
0:f7145c77b7fb 1:2071b28cd0c7
1 /*
2 * This module implements a few special commands for those very few
3 * incredibly lucky people on Earth who have no-longer-available
4 * sysmoSIM-GR1 cards, or any other branded variant of the same card
5 * from Grcard.
6 */
7
8 #include <sys/types.h>
9 #include <ctype.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include "simresp.h"
13
14 cmd_grcard1_set_pin(argc, argv)
15 char **argv;
16 {
17 u_char cmd[21];
18 int rc;
19
20 /* Grcard1 proprietary command APDU */
21 cmd[0] = 0x80;
22 cmd[1] = 0xD4;
23 cmd[2] = 0x00;
24 switch (argv[0][15]) {
25 case '1':
26 cmd[3] = 0x01;
27 break;
28 case '2':
29 cmd[3] = 0x02;
30 break;
31 default:
32 fprintf(stderr, "BUG in grcard1-set-pinN command\n");
33 return(-1);
34 }
35 cmd[4] = 16;
36 rc = encode_pin_entry(argv[1], cmd + 5);
37 if (rc < 0)
38 return(rc);
39 rc = encode_pin_entry(argv[2], cmd + 13);
40 if (rc < 0)
41 return(rc);
42 rc = apdu_exchange(cmd, 21);
43 if (rc < 0)
44 return(rc);
45 if (sim_resp_sw != 0x9000) {
46 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
47 return(-1);
48 }
49 return(0);
50 }
51
52 cmd_grcard1_set_adm(argc, argv)
53 char **argv;
54 {
55 u_char cmd[23];
56 int rc;
57
58 /* Grcard1 proprietary command APDU */
59 cmd[0] = 0x80;
60 cmd[1] = 0xD4;
61 cmd[2] = 0x01;
62 switch (argv[0][15]) {
63 case '1':
64 cmd[3] = 0x04;
65 break;
66 case '2':
67 cmd[3] = 0x05;
68 break;
69 default:
70 fprintf(stderr, "BUG in grcard1-set-admN command\n");
71 return(-1);
72 }
73 cmd[4] = 18;
74 cmd[5] = 0x03;
75 cmd[6] = 0x00;
76 rc = encode_pin_entry(argv[1], cmd + 7);
77 if (rc < 0)
78 return(rc);
79 rc = encode_pin_entry(argv[2], cmd + 15);
80 if (rc < 0)
81 return(rc);
82 rc = apdu_exchange(cmd, 23);
83 if (rc < 0)
84 return(rc);
85 if (sim_resp_sw != 0x9000) {
86 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
87 return(-1);
88 }
89 return(0);
90 }
91
92 cmd_grcard1_set_ki(argc, argv)
93 char **argv;
94 {
95 u_char cmd[21];
96 int rc;
97
98 /* Grcard1 proprietary command APDU */
99 cmd[0] = 0x80;
100 cmd[1] = 0xD4;
101 cmd[2] = 0x02;
102 cmd[3] = 0x00;
103 cmd[4] = 16;
104 rc = decode_hex_data_from_string(argv[1], cmd + 5, 16, 16);
105 if (rc < 0)
106 return(rc);
107 rc = apdu_exchange(cmd, 21);
108 if (rc < 0)
109 return(rc);
110 if (sim_resp_sw != 0x9000) {
111 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
112 return(-1);
113 }
114 return(0);
115 }