FreeCalypso > hg > fc-pcsc-tools
annotate simtool/sstlist.c @ 183:2545dd27ca38
fc-simtool write-imsi-sh command implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 06 Mar 2021 05:24:26 +0000 |
parents | 9c16cf1a79af |
children |
rev | line source |
---|---|
48
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
59
c56e63a8725d
fc-simtool sst-dump command shortened to just sst
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
2 * This module implements the sst command, listing the SIM Service Table |
c56e63a8725d
fc-simtool sst-dump command shortened to just sst
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
3 * in a human-readable, yet very compact form: just a list of activated |
c56e63a8725d
fc-simtool sst-dump command shortened to just sst
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
4 * (or allocated but not activated, specially marked) service numbers. |
48
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/types.h> |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include "simresp.h" |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include "curfile.h" |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "file_id.h" |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
116
9c16cf1a79af
fc-simtool sst: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
13 cmd_sst(argc, argv, outf) |
9c16cf1a79af
fc-simtool sst: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
14 char **argv; |
9c16cf1a79af
fc-simtool sst: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
15 FILE *outf; |
48
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 { |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 int rc; |
49
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
18 unsigned byte, pos, code, nserv, linelen; |
48
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 rc = select_op(DF_GSM); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 if (rc < 0) |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 return(rc); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 rc = select_op(EF_SST); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 if (rc < 0) |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 return(rc); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 rc = parse_ef_select_response(); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (rc < 0) |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 return(rc); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 if (curfile_structure != 0x00) { |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 fprintf(stderr, "error: EF_SST is not transparent\n"); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 return(-1); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 } |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 if (curfile_total_size < 2) { |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 fprintf(stderr, |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 "error: EF_SST is shorter than spec minimum of 2 bytes\n"); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 return(-1); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 if (curfile_total_size > 256) { |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 fprintf(stderr, |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 "error: EF_SST is longer than our 256 byte limit\n"); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 return(-1); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 } |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 rc = readbin_op(0, curfile_total_size); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 if (rc < 0) |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 return(rc); |
49
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
46 linelen = 0; |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
47 for (byte = 0, nserv = 1; byte < curfile_total_size; byte++) { |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
48 for (pos = 0; pos < 8; pos += 2, nserv++) { |
48
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 code = (sim_resp_data[byte] >> pos) & 3; |
49
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
50 if (!(code & 1)) |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
51 continue; |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
52 if (linelen > 73) { |
116
9c16cf1a79af
fc-simtool sst: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
53 putc('\n', outf); |
49
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
54 linelen = 0; |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
55 } |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
56 if (linelen) { |
116
9c16cf1a79af
fc-simtool sst: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
57 putc(' ', outf); |
49
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
58 linelen++; |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
59 } |
116
9c16cf1a79af
fc-simtool sst: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
60 linelen += fprintf(outf, "%u", nserv); |
49
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
61 if (!(code & 2)) { |
116
9c16cf1a79af
fc-simtool sst: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
62 putc('^', outf); |
49
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
63 linelen++; |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
64 } |
48
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } |
49
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
67 if (linelen) |
116
9c16cf1a79af
fc-simtool sst: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
68 putc('\n', outf); |
48
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 return(0); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 } |