annotate simtool/miscadm.c @ 210:9797417ececa

fc-simtool write-acc command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Mar 2021 06:26:20 +0000
parents 2545dd27ca38
children 31cd62f91522
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>
66
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "curfile.h"
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "file_id.h"
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
181
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
13 static
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
14 write_iccid_bin(binrec)
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
15 u_char *binrec;
68
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
16 {
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
17 int rc;
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 rc = select_op(FILEID_MF);
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
20 if (rc < 0)
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
21 return(rc);
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
22 rc = select_op(EF_ICCID);
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
23 if (rc < 0)
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
24 return(rc);
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
25 rc = parse_ef_select_response();
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
26 if (rc < 0)
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
27 return(rc);
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
28 if (curfile_structure != 0x00 || curfile_total_size != 10) {
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
29 fprintf(stderr,
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
30 "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
31 return(-1);
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
32 }
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
33 return update_bin_op(0, binrec, 10);
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
181
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
36 cmd_write_iccid(argc, argv)
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
37 char **argv;
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
38 {
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
39 int rc;
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
40 u_char nibbles[20], binrec[10];
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
41
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
42 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
43 if (rc < 0)
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
44 return(rc);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
45 pack_reversed_nibbles(nibbles, binrec, 10);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
46 return write_iccid_bin(binrec);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
47 }
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
48
182
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
49 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
50 char **argv;
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
51 {
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
52 int rc;
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
53 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
54
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
55 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
56 if (rc < 0)
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
57 return(rc);
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
58 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
59 nibbles[19] = 0xF;
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
60 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
61 return write_iccid_bin(binrec);
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
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
64 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
65 char **argv;
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
66 {
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
67 int rc;
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
68 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
69
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
70 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
71 if (rc < 0)
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
72 return(rc);
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
73 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
74 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
75 return(-1);
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
76 }
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
77 nibbles[19] = 0xF;
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
78 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
79 return write_iccid_bin(binrec);
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
80 }
f4edccd4b583 fc-simtool: write-iccid-sh{18,19} commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 181
diff changeset
81
181
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
82 static
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
83 write_imsi_bin(binrec)
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
84 u_char *binrec;
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
85 {
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
86 int rc;
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 rc = select_op(DF_GSM);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
89 if (rc < 0)
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
90 return(rc);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
91 rc = select_op(EF_IMSI);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
92 if (rc < 0)
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
93 return(rc);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
94 rc = parse_ef_select_response();
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
95 if (rc < 0)
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
96 return(rc);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
97 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
98 fprintf(stderr,
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
99 "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
100 return(-1);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
101 }
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
102 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
103 }
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
104
66
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 cmd_write_imsi(argc, argv)
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 char **argv;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 {
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 int rc;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 u_char nibbles[16], binrec[9];
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 unsigned ndig;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 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
113 if (rc < 0)
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 return(rc);
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 ndig = rc;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 if (ndig & 1)
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 nibbles[0] = 9;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 else
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 nibbles[0] = 1;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 binrec[0] = (ndig + 2) >> 1;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 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
122 return write_imsi_bin(binrec);
66
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 }
183
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
124
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
125 cmd_write_imsi_sh(argc, argv)
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
126 char **argv;
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
127 {
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
128 int rc;
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
129 u_char nibbles[16], binrec[9];
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
130
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
131 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
132 if (rc < 0)
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
133 return(rc);
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
134 nibbles[0] = 9;
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
135 binrec[0] = 8;
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
136 pack_reversed_nibbles(nibbles, binrec + 1, 8);
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
137 return write_imsi_bin(binrec);
2545dd27ca38 fc-simtool write-imsi-sh command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 182
diff changeset
138 }
210
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
139
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
140 static
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
141 write_acc_bin(binrec)
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
142 u_char *binrec;
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
143 {
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
144 int rc;
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 rc = select_op(DF_GSM);
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
147 if (rc < 0)
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
148 return(rc);
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
149 rc = select_op(EF_ACC);
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
150 if (rc < 0)
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
151 return(rc);
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
152 rc = parse_ef_select_response();
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
153 if (rc < 0)
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
154 return(rc);
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
155 if (curfile_structure != 0x00 || curfile_total_size != 2) {
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
156 fprintf(stderr,
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
157 "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
158 return(-1);
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
159 }
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
160 return update_bin_op(0, binrec, 2);
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
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
163 cmd_write_acc(argc, argv)
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
164 char **argv;
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
165 {
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
166 unsigned acc;
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
167 u_char binrec[2];
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
168
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
169 acc = strtoul(argv[1], 0, 16);
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
170 if (acc > 0xFFFF) {
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
171 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
172 return(-1);
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
173 }
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
174 binrec[0] = acc >> 8;
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
175 binrec[1] = acc;
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
176 return write_acc_bin(binrec);
9797417ececa fc-simtool write-acc command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 183
diff changeset
177 }