annotate simtool/miscadm.c @ 182:f4edccd4b583

fc-simtool: write-iccid-sh{18,19} commands implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 06 Mar 2021 05:07:46 +0000
parents 63b640562e21
children 2545dd27ca38
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
66
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements write-iccid and write-imsi commands,
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * available only in the admin programming phase after authenticating
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * with some card-vendor-dependent ADM key.
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/types.h>
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include "curfile.h"
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "file_id.h"
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
181
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
12 static
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
13 write_iccid_bin(binrec)
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
14 u_char *binrec;
68
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
15 {
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
16 int rc;
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
17
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
18 rc = select_op(FILEID_MF);
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
19 if (rc < 0)
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
20 return(rc);
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
21 rc = select_op(EF_ICCID);
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
22 if (rc < 0)
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
23 return(rc);
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
24 rc = parse_ef_select_response();
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
25 if (rc < 0)
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
26 return(rc);
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
27 if (curfile_structure != 0x00 || curfile_total_size != 10) {
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
28 fprintf(stderr,
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
29 "error: EF_ICCID is not a transparent EF of 10 bytes\n");
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
30 return(-1);
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
31 }
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
32 return update_bin_op(0, binrec, 10);
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
33 }
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
34
181
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
35 cmd_write_iccid(argc, argv)
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
36 char **argv;
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
37 {
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
38 int rc;
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
39 u_char nibbles[20], binrec[10];
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
40
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
41 rc = parse_decimal_string_arg(argv[1], nibbles, 20);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
42 if (rc < 0)
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
43 return(rc);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
44 pack_reversed_nibbles(nibbles, binrec, 10);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
45 return write_iccid_bin(binrec);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
46 }
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
47
182
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
48 cmd_write_iccid_sh18(argc, argv)
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
49 char **argv;
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
50 {
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
51 int rc;
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
52 u_char nibbles[20], binrec[10];
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
53
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
54 rc = parse_decimal_shorthand(argv[1], nibbles, 18);
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
55 if (rc < 0)
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
56 return(rc);
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
57 nibbles[18] = compute_iccid_luhn(nibbles);
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
58 nibbles[19] = 0xF;
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
59 pack_reversed_nibbles(nibbles, binrec, 10);
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
60 return write_iccid_bin(binrec);
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
61 }
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
62
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
63 cmd_write_iccid_sh19(argc, argv)
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
64 char **argv;
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
65 {
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
66 int rc;
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
67 u_char nibbles[20], binrec[10];
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
68
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
69 rc = parse_decimal_shorthand(argv[1], nibbles, 19);
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
70 if (rc < 0)
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
71 return(rc);
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
72 if (nibbles[18] != compute_iccid_luhn(nibbles)) {
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
73 fprintf(stderr, "error: Luhn check digit mismatch\n");
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
74 return(-1);
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
75 }
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
76 nibbles[19] = 0xF;
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
77 pack_reversed_nibbles(nibbles, binrec, 10);
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
78 return write_iccid_bin(binrec);
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
79 }
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
80
181
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
81 static
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
82 write_imsi_bin(binrec)
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
83 u_char *binrec;
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
84 {
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
85 int rc;
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
86
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
87 rc = select_op(DF_GSM);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
88 if (rc < 0)
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
89 return(rc);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
90 rc = select_op(EF_IMSI);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
91 if (rc < 0)
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
92 return(rc);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
93 rc = parse_ef_select_response();
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
94 if (rc < 0)
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
95 return(rc);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
96 if (curfile_structure != 0x00 || curfile_total_size != 9) {
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
97 fprintf(stderr,
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
98 "error: EF_IMSI is not a transparent EF of 9 bytes\n");
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
99 return(-1);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
100 }
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
101 return update_bin_op(0, binrec, 9);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
102 }
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
103
66
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 cmd_write_imsi(argc, argv)
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 char **argv;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 {
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 int rc;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 u_char nibbles[16], binrec[9];
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 unsigned ndig;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 rc = parse_decimal_string_arg(argv[1], nibbles + 1, 15);
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 if (rc < 0)
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 return(rc);
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 ndig = rc;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 if (ndig & 1)
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 nibbles[0] = 9;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 else
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 nibbles[0] = 1;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 binrec[0] = (ndig + 2) >> 1;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 pack_reversed_nibbles(nibbles, binrec + 1, 8);
181
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
121 return write_imsi_bin(binrec);
66
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 }