FreeCalypso > hg > fc-pcsc-tools
annotate simtool/miscadm.c @ 66:3ef90bd13fbe
fc-simtool write-imsi command implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 15 Feb 2021 00:28:10 +0000 |
parents | |
children | 105aa3d1a494 |
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 |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 cmd_write_imsi(argc, argv) |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 char **argv; |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 { |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 int rc; |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 u_char nibbles[16], binrec[9]; |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 unsigned ndig; |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 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
|
20 if (rc < 0) |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 return(rc); |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 ndig = rc; |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 if (ndig & 1) |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 nibbles[0] = 9; |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 else |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 nibbles[0] = 1; |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 binrec[0] = (ndig + 2) >> 1; |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 pack_reversed_nibbles(nibbles, binrec + 1, 8); |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 rc = select_op(DF_GSM); |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 if (rc < 0) |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 return(rc); |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 rc = select_op(EF_IMSI); |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 if (rc < 0) |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 return(rc); |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 rc = parse_ef_select_response(); |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 if (rc < 0) |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 return(rc); |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 if (curfile_structure != 0x00 || curfile_total_size != 9) { |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 fprintf(stderr, |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 "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
|
41 return(-1); |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 } |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 return update_bin_op(0, binrec, 9); |
3ef90bd13fbe
fc-simtool write-imsi command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 } |