FreeCalypso > hg > freecalypso-hwlab
comparison simtool/grcard2.c @ 154:ed34c8b7e2c9
fc-simtool: grcard2-set-pin[12] commands implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 07 Feb 2021 02:29:07 +0000 |
parents | |
children | 804a5b0797c6 |
comparison
equal
deleted
inserted
replaced
153:a63e4c64f1f0 | 154:ed34c8b7e2c9 |
---|---|
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 <pcsclite.h> | |
19 #include <winscard.h> | |
20 #include "globals.h" | |
21 | |
22 cmd_grcard2_set_pin(argc, argv) | |
23 char **argv; | |
24 { | |
25 u_char cmd[13]; | |
26 int rc; | |
27 | |
28 /* Grcard2 proprietary command APDU */ | |
29 cmd[0] = 0xA0; | |
30 cmd[1] = 0xD4; | |
31 cmd[2] = 0x3A; | |
32 switch (argv[0][15]) { | |
33 case '1': | |
34 cmd[3] = 0x01; | |
35 break; | |
36 case '2': | |
37 cmd[3] = 0x02; | |
38 break; | |
39 default: | |
40 fprintf(stderr, "BUG in grcard2-set-pinN command\n"); | |
41 return(-1); | |
42 } | |
43 cmd[4] = 8; | |
44 rc = encode_pin_entry(argv[1], cmd + 5); | |
45 if (rc < 0) | |
46 return(rc); | |
47 rc = apdu_exchange(cmd, 13); | |
48 if (rc < 0) | |
49 return(rc); | |
50 if (sim_resp_sw != 0x9000) { | |
51 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw); | |
52 return(-1); | |
53 } | |
54 return(0); | |
55 } |