annotate simtool/miscadm.c @ 181:63b640562e21

simtool/miscadm.c: code refactoring in preparation for adding shorthand ICCID and IMSI write commands
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 06 Mar 2021 04:51:56 +0000
parents 105aa3d1a494
children f4edccd4b583
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
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
48 static
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
49 write_imsi_bin(binrec)
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
50 u_char *binrec;
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
51 {
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
52 int rc;
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
53
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
54 rc = select_op(DF_GSM);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
55 if (rc < 0)
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
56 return(rc);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
57 rc = select_op(EF_IMSI);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
58 if (rc < 0)
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
59 return(rc);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
60 rc = parse_ef_select_response();
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
61 if (rc < 0)
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
62 return(rc);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
63 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
64 fprintf(stderr,
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
65 "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
66 return(-1);
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
67 }
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
68 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
69 }
63b640562e21 simtool/miscadm.c: code refactoring in preparation for
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
70
66
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 cmd_write_imsi(argc, argv)
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 char **argv;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 {
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 int rc;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 u_char nibbles[16], binrec[9];
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 unsigned ndig;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 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
79 if (rc < 0)
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 return(rc);
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 ndig = rc;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 if (ndig & 1)
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 nibbles[0] = 9;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 else
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 nibbles[0] = 1;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 binrec[0] = (ndig + 2) >> 1;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 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
88 return write_imsi_bin(binrec);
66
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 }