FreeCalypso > hg > fc-sim-tools
annotate simtool/grcard2ki.c @ 102:c2f18d7b0a1e
doc/Admin-write-commands: document write-hplmn-timer command
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 14 May 2022 23:20:38 +0000 |
parents | 9f1cc3174e45 |
children |
rev | line source |
---|---|
10
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements special commands for the grcard.cn card model |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * which is known in the Osmocom community as GrcardSIM2: |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * https://osmocom.org/projects/cellular-infrastructure/wiki/GrcardSIM2 |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * |
73
4ebd67176b73
simtool/grcard2.c: comment update for FCSIM1
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
7 * FreeCalypso Community SIM model FCSIM1 is GrcardSIM2, and so are |
4ebd67176b73
simtool/grcard2.c: comment update for FCSIM1
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
8 * historical sysmoSIM-GR2 and 30C3 cards. |
10
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 */ |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <sys/types.h> |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdio.h> |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "simresp.h" |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include "curfile.h" |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include "file_id.h" |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 static |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 select_ef_weki() |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 { |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 int rc; |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 rc = select_op(DF_GSM); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 if (rc < 0) |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 return(rc); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 rc = select_op(0x0001); /* proprietary EF */ |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 if (rc < 0) |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 return(rc); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 rc = parse_ef_select_response(); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 if (rc < 0) |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 return(rc); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 if (curfile_structure != 0x00 || curfile_total_size != 35) { |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 fprintf(stderr, |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 "error: EF_WEKI is not a transparent EF of 35 bytes\n"); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 return(-1); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 return(0); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 cmd_grcard2_set_comp128(argc, argv) |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 char **argv; |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 { |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 int rc; |
97
9f1cc3174e45
grcard2-set-comp128: allow optional setting of upper 6 bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
43 unsigned code, upper; |
10
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 u_char magic_byte; |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 if (argv[1][0] < '1' || argv[1][0] > '3' || argv[1][1]) { |
97
9f1cc3174e45
grcard2-set-comp128: allow optional setting of upper 6 bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
47 fprintf(stderr, "error: invalid COMP128 version argument\n"); |
10
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 return(-1); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 } |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 code = argv[1][0] - '1'; |
97
9f1cc3174e45
grcard2-set-comp128: allow optional setting of upper 6 bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
51 if (argv[2]) { |
9f1cc3174e45
grcard2-set-comp128: allow optional setting of upper 6 bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
52 upper = strtoul(argv[2], 0, 16); |
9f1cc3174e45
grcard2-set-comp128: allow optional setting of upper 6 bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
53 if ((upper & 3) || (upper > 0xFC)) { |
9f1cc3174e45
grcard2-set-comp128: allow optional setting of upper 6 bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
54 fprintf(stderr, "error: invalid upper bits argument\n"); |
9f1cc3174e45
grcard2-set-comp128: allow optional setting of upper 6 bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
55 return(-1); |
9f1cc3174e45
grcard2-set-comp128: allow optional setting of upper 6 bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
56 } |
9f1cc3174e45
grcard2-set-comp128: allow optional setting of upper 6 bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
57 } |
10
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 rc = select_ef_weki(); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 if (rc < 0) |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 return(rc); |
97
9f1cc3174e45
grcard2-set-comp128: allow optional setting of upper 6 bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
61 if (argv[2]) |
9f1cc3174e45
grcard2-set-comp128: allow optional setting of upper 6 bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
62 magic_byte = upper; |
9f1cc3174e45
grcard2-set-comp128: allow optional setting of upper 6 bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
63 else { |
9f1cc3174e45
grcard2-set-comp128: allow optional setting of upper 6 bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
64 rc = readbin_op(2, 1); |
9f1cc3174e45
grcard2-set-comp128: allow optional setting of upper 6 bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
65 if (rc < 0) |
9f1cc3174e45
grcard2-set-comp128: allow optional setting of upper 6 bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
66 return(rc); |
9f1cc3174e45
grcard2-set-comp128: allow optional setting of upper 6 bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
67 magic_byte = sim_resp_data[0] & 0xFC; |
9f1cc3174e45
grcard2-set-comp128: allow optional setting of upper 6 bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
68 } |
10
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 magic_byte |= code; |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 return update_bin_op(2, &magic_byte, 1); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 } |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 cmd_grcard2_set_ki(argc, argv) |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 char **argv; |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 { |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 u_char ki[16]; |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 int rc; |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 rc = decode_hex_data_from_string(argv[1], ki, 16, 16); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 if (rc < 0) |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 return(rc); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 rc = select_ef_weki(); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 if (rc < 0) |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 return(rc); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 return update_bin_op(3, ki, 16); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 } |