comparison simtool/grcard2.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 * I, Mother Mychaela, am hoping to get some SIM cards from Grcard
3 * that follow the protocol which the Osmocom community has nicknamed
4 * GrcardSIM2:
5 *
6 * https://osmocom.org/projects/cellular-infrastructure/wiki/GrcardSIM2
7 *
8 * I haven't got these cards yet and may not get them for a long time,
9 * hence the following code has been written blindly, untested.
10 * If anyone in the community happens to have a sysmoSIM-GR2 card
11 * that was once (aeons ago) sold by Sysmocom, please test this code!
12 */
13
14 #include <sys/types.h>
15 #include <ctype.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include "simresp.h"
19
20 cmd_grcard2_set_pin(argc, argv)
21 char **argv;
22 {
23 u_char cmd[13];
24 int rc;
25
26 /* Grcard2 proprietary command APDU */
27 cmd[0] = 0xA0;
28 cmd[1] = 0xD4;
29 cmd[2] = 0x3A;
30 switch (argv[0][15]) {
31 case '1':
32 cmd[3] = 0x01;
33 break;
34 case '2':
35 cmd[3] = 0x02;
36 break;
37 default:
38 fprintf(stderr, "BUG in grcard2-set-pinN command\n");
39 return(-1);
40 }
41 cmd[4] = 8;
42 rc = encode_pin_entry(argv[1], cmd + 5);
43 if (rc < 0)
44 return(rc);
45 rc = apdu_exchange(cmd, 13);
46 if (rc < 0)
47 return(rc);
48 if (sim_resp_sw != 0x9000) {
49 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
50 return(-1);
51 }
52 return(0);
53 }
54
55 cmd_grcard2_set_puk(argc, argv)
56 char **argv;
57 {
58 u_char cmd[13];
59 int rc;
60
61 /* Grcard2 proprietary command APDU */
62 cmd[0] = 0xA0;
63 cmd[1] = 0xD4;
64 cmd[2] = 0x3B;
65 switch (argv[0][15]) {
66 case '1':
67 cmd[3] = 0x00;
68 break;
69 case '2':
70 cmd[3] = 0x02;
71 break;
72 default:
73 fprintf(stderr, "BUG in grcard2-set-pukN command\n");
74 return(-1);
75 }
76 cmd[4] = 8;
77 rc = encode_pin_entry(argv[1], cmd + 5);
78 if (rc < 0)
79 return(rc);
80 rc = apdu_exchange(cmd, 13);
81 if (rc < 0)
82 return(rc);
83 if (sim_resp_sw != 0x9000) {
84 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
85 return(-1);
86 }
87 return(0);
88 }
89
90 cmd_grcard2_set_adm(argc, argv)
91 char **argv;
92 {
93 u_char cmd[13];
94 int rc;
95
96 /* Grcard2 proprietary command APDU */
97 cmd[0] = 0xA0;
98 cmd[1] = 0xD4;
99 cmd[2] = 0x3A;
100 cmd[3] = 0x05;
101 cmd[4] = 8;
102 rc = encode_pin_entry(argv[1], cmd + 5);
103 if (rc < 0)
104 return(rc);
105 rc = apdu_exchange(cmd, 13);
106 if (rc < 0)
107 return(rc);
108 if (sim_resp_sw != 0x9000) {
109 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
110 return(-1);
111 }
112 return(0);
113 }
114
115 cmd_grcard2_set_super(argc, argv)
116 char **argv;
117 {
118 u_char cmd[13];
119 int rc;
120
121 /* Grcard2 proprietary command APDU */
122 cmd[0] = 0xA0;
123 cmd[1] = 0xD4;
124 cmd[2] = 0x3A;
125 cmd[3] = 0x0B;
126 cmd[4] = 8;
127 rc = encode_pin_entry(argv[1], cmd + 5);
128 if (rc < 0)
129 return(rc);
130 rc = apdu_exchange(cmd, 13);
131 if (rc < 0)
132 return(rc);
133 if (sim_resp_sw != 0x9000) {
134 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
135 return(-1);
136 }
137 return(0);
138 }