FreeCalypso > hg > fc-pcsc-tools
annotate simtool/sstlist.c @ 61:633033af6fb8
fc-simtool user-sum command implemented,
a successor to telecom-sum
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 14 Feb 2021 03:27:56 +0000 |
parents | 090704d1ddc1 |
children | 9c16cf1a79af |
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 |
59
c56e63a8725d
fc-simtool sst-dump command shortened to just sst
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
13 cmd_sst() |
48
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 { |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 int rc; |
49
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
16 unsigned byte, pos, code, nserv, linelen; |
48
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 rc = select_op(DF_GSM); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 if (rc < 0) |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 return(rc); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 rc = select_op(EF_SST); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 if (rc < 0) |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 return(rc); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 rc = parse_ef_select_response(); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (rc < 0) |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 return(rc); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (curfile_structure != 0x00) { |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 fprintf(stderr, "error: EF_SST is not transparent\n"); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 return(-1); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 } |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 if (curfile_total_size < 2) { |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 fprintf(stderr, |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 "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
|
34 return(-1); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 if (curfile_total_size > 256) { |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 fprintf(stderr, |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 "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
|
39 return(-1); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 } |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 rc = readbin_op(0, curfile_total_size); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 if (rc < 0) |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 return(rc); |
49
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
44 linelen = 0; |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
45 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
|
46 for (pos = 0; pos < 8; pos += 2, nserv++) { |
48
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 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
|
48 if (!(code & 1)) |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
49 continue; |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
50 if (linelen > 73) { |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
51 putchar('\n'); |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
52 linelen = 0; |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
53 } |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
54 if (linelen) { |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
55 putchar(' '); |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
56 linelen++; |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
57 } |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
58 linelen += printf("%u", nserv); |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
59 if (!(code & 2)) { |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
60 putchar('^'); |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
61 linelen++; |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
62 } |
48
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 } |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 } |
49
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
65 if (linelen) |
bbc2821288aa
fc-simtool sst-dump: much more compact output
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
66 putchar('\n'); |
48
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 return(0); |
9a21f4353158
fc-simtool sst-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 } |