annotate simtool/miscadm.c @ 217:52c0da56e979

simtool code: select_ef_opl() factored out
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Mar 2021 18:18:29 +0000
parents 31cd62f91522
children
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>
210
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
9 #include <stdlib.h>
211
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
10 #include <string.h>
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
11 #include <strings.h>
66
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "curfile.h"
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "file_id.h"
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
181
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
15 static
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
16 write_iccid_bin(binrec)
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
17 u_char *binrec;
68
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
18 {
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
19 int rc;
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
20
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
21 rc = select_op(FILEID_MF);
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 = select_op(EF_ICCID);
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 rc = parse_ef_select_response();
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
28 if (rc < 0)
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
29 return(rc);
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
30 if (curfile_structure != 0x00 || curfile_total_size != 10) {
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
31 fprintf(stderr,
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
32 "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
33 return(-1);
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
34 }
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
35 return update_bin_op(0, binrec, 10);
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
36 }
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
37
181
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
38 cmd_write_iccid(argc, argv)
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
39 char **argv;
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 int rc;
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
42 u_char nibbles[20], binrec[10];
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
43
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
44 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
45 if (rc < 0)
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
46 return(rc);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
47 pack_reversed_nibbles(nibbles, binrec, 10);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
48 return write_iccid_bin(binrec);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
49 }
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
50
182
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
51 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
52 char **argv;
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 int rc;
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
55 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
56
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
57 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
58 if (rc < 0)
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
59 return(rc);
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
60 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
61 nibbles[19] = 0xF;
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
62 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
63 return write_iccid_bin(binrec);
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
64 }
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 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
67 char **argv;
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 int rc;
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
70 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
71
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
72 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
73 if (rc < 0)
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
74 return(rc);
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
75 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
76 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
77 return(-1);
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
78 }
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
79 nibbles[19] = 0xF;
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
80 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
81 return write_iccid_bin(binrec);
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
82 }
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
83
181
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
84 static
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
85 write_imsi_bin(binrec)
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
86 u_char *binrec;
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
87 {
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
88 int rc;
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
89
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
90 rc = select_op(DF_GSM);
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 = select_op(EF_IMSI);
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 rc = parse_ef_select_response();
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
97 if (rc < 0)
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
98 return(rc);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
99 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
100 fprintf(stderr,
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
101 "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
102 return(-1);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
103 }
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
104 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
105 }
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
106
66
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 cmd_write_imsi(argc, argv)
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 char **argv;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 {
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 int rc;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 u_char nibbles[16], binrec[9];
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 unsigned ndig;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 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
115 if (rc < 0)
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 return(rc);
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 ndig = rc;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 if (ndig & 1)
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 nibbles[0] = 9;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 else
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 nibbles[0] = 1;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 binrec[0] = (ndig + 2) >> 1;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 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
124 return write_imsi_bin(binrec);
66
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 }
183
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
126
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
127 cmd_write_imsi_sh(argc, argv)
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
128 char **argv;
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
129 {
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
130 int rc;
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
131 u_char nibbles[16], binrec[9];
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
132
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
133 rc = parse_decimal_shorthand(argv[1], nibbles + 1, 15);
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
134 if (rc < 0)
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
135 return(rc);
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
136 nibbles[0] = 9;
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
137 binrec[0] = 8;
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
138 pack_reversed_nibbles(nibbles, binrec + 1, 8);
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
139 return write_imsi_bin(binrec);
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
140 }
210
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
141
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
142 static
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
143 write_acc_bin(binrec)
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
144 u_char *binrec;
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
145 {
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
146 int rc;
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
147
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
148 rc = select_op(DF_GSM);
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
149 if (rc < 0)
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
150 return(rc);
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
151 rc = select_op(EF_ACC);
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
152 if (rc < 0)
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
153 return(rc);
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
154 rc = parse_ef_select_response();
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
155 if (rc < 0)
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
156 return(rc);
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
157 if (curfile_structure != 0x00 || curfile_total_size != 2) {
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
158 fprintf(stderr,
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
159 "error: EF_ACC is not a transparent EF of 2 bytes\n");
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
160 return(-1);
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
161 }
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
162 return update_bin_op(0, binrec, 2);
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
163 }
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
164
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
165 cmd_write_acc(argc, argv)
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
166 char **argv;
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
167 {
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
168 unsigned acc;
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
169 u_char binrec[2];
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
170
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
171 acc = strtoul(argv[1], 0, 16);
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
172 if (acc > 0xFFFF) {
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
173 fprintf(stderr, "error: ACC argument is out of range\n");
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
174 return(-1);
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
175 }
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
176 binrec[0] = acc >> 8;
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
177 binrec[1] = acc;
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
178 return write_acc_bin(binrec);
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
179 }
211
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
180
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
181 static
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
182 write_spn_bin(binrec)
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
183 u_char *binrec;
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
184 {
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
185 int rc;
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
186
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
187 rc = select_op(DF_GSM);
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
188 if (rc < 0)
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
189 return(rc);
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
190 rc = select_op(EF_SPN);
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
191 if (rc < 0)
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
192 return(rc);
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
193 rc = parse_ef_select_response();
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
194 if (rc < 0)
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
195 return(rc);
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
196 if (curfile_structure != 0x00 || curfile_total_size != 17) {
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
197 fprintf(stderr,
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
198 "error: EF_SPN is not a transparent EF of 17 bytes\n");
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
199 return(-1);
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
200 }
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
201 return update_bin_op(0, binrec, 17);
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
202 }
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
203
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
204 cmd_write_spn(argc, argv)
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
205 char **argv;
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
206 {
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
207 u_char binrec[17];
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
208 int rc;
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
209
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
210 binrec[0] = strtoul(argv[1], 0, 16);
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
211 memset(binrec + 1, 0xFF, 16);
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
212 rc = qstring_arg_to_gsm7(argv[2], binrec + 1, 16);
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
213 if (rc < 0)
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
214 return(rc);
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
215 return write_spn_bin(binrec);
31cd62f91522 fc-simtool write-spn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 210
diff changeset
216 }