annotate simtool/miscadm.c @ 122:c0cd0d4635bb

fc-simtool verify-sjs1-adm1 command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 20 Feb 2021 01:20:50 +0000
parents 105aa3d1a494
children 63b640562e21
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
68
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
12 cmd_write_iccid(argc, argv)
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
13 char **argv;
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
14 {
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
15 int rc;
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
16 u_char nibbles[20], binrec[10];
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 = parse_decimal_string_arg(argv[1], nibbles, 20);
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 pack_reversed_nibbles(nibbles, binrec, 10);
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
22 rc = select_op(FILEID_MF);
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 = select_op(EF_ICCID);
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 rc = parse_ef_select_response();
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
29 if (rc < 0)
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
30 return(rc);
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
31 if (curfile_structure != 0x00 || curfile_total_size != 10) {
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
32 fprintf(stderr,
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
33 "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
34 return(-1);
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
35 }
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
36 return update_bin_op(0, binrec, 10);
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
37 }
105aa3d1a494 fc-simtool write-iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
38
66
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 cmd_write_imsi(argc, argv)
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 char **argv;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 {
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 int rc;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 u_char nibbles[16], binrec[9];
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 unsigned ndig;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 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
47 if (rc < 0)
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 return(rc);
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 ndig = rc;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (ndig & 1)
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 nibbles[0] = 9;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 else
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 nibbles[0] = 1;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 binrec[0] = (ndig + 2) >> 1;
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 pack_reversed_nibbles(nibbles, binrec + 1, 8);
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 rc = select_op(DF_GSM);
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (rc < 0)
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 return(rc);
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 rc = select_op(EF_IMSI);
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (rc < 0)
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 return(rc);
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 rc = parse_ef_select_response();
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 if (rc < 0)
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 return(rc);
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 if (curfile_structure != 0x00 || curfile_total_size != 9) {
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 fprintf(stderr,
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 "error: EF_IMSI is not a transparent EF of 9 bytes\n");
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 return(-1);
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 }
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 return update_bin_op(0, binrec, 9);
3ef90bd13fbe fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 }