comparison simtool/sstlist.c @ 10:ddd767f6e15b

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