comparison simtool/usersum.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 user-sum (summary info) command.
3 */
4
5 #include <sys/types.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <strings.h>
10 #include "simresp.h"
11 #include "curfile.h"
12 #include "file_id.h"
13
14 #define SST_BYTES_USED 15
15
16 static
17 read_sst(sstbuf)
18 u_char *sstbuf;
19 {
20 int rc;
21 unsigned rdlen;
22
23 rc = select_op(DF_GSM);
24 if (rc < 0)
25 return(rc);
26 rc = select_op(EF_SST);
27 if (rc < 0)
28 return(rc);
29 rc = parse_ef_select_response();
30 if (rc < 0)
31 return(rc);
32 if (curfile_structure != 0x00) {
33 fprintf(stderr, "error: EF_SST is not transparent\n");
34 return(-1);
35 }
36 if (curfile_total_size < 2) {
37 fprintf(stderr,
38 "error: EF_SST is shorter than spec minimum of 2 bytes\n");
39 return(-1);
40 }
41 rdlen = curfile_total_size;
42 if (rdlen > SST_BYTES_USED)
43 rdlen = SST_BYTES_USED;
44 rc = readbin_op(0, rdlen);
45 if (rc < 0)
46 return(rc);
47 bcopy(sim_resp_data, sstbuf, rdlen);
48 if (rdlen < SST_BYTES_USED)
49 bzero(sstbuf + rdlen, SST_BYTES_USED - rdlen);
50 return(0);
51 }
52
53 static
54 do_phonebook_file(file_id, ef_name, book_name, outf)
55 unsigned file_id;
56 char *ef_name, *book_name;
57 FILE *outf;
58 {
59 int rc;
60
61 rc = select_op(file_id);
62 if (rc < 0)
63 return(rc);
64 rc = parse_ef_select_response();
65 if (rc < 0)
66 return(rc);
67 if (curfile_structure != 0x01 && curfile_structure != 0x03) {
68 fprintf(stderr, "error: %s is not record-structured\n",
69 ef_name);
70 return(-1);
71 }
72 if (curfile_record_len < 14) {
73 fprintf(stderr,
74 "error: %s has record length of %u bytes, less than minimum 14\n",
75 ef_name, curfile_record_len);
76 return(-1);
77 }
78 fprintf(outf, "%s: %u entries, %u bytes of alpha tag\n", book_name,
79 curfile_record_count, curfile_record_len - 14);
80 return(0);
81 }
82
83 static
84 do_sms_store(outf)
85 FILE *outf;
86 {
87 int rc;
88
89 rc = select_op(EF_SMS);
90 if (rc < 0)
91 return(rc);
92 rc = parse_ef_select_response();
93 if (rc < 0)
94 return(rc);
95 if (curfile_structure != 0x01 || curfile_record_len != 176) {
96 fprintf(stderr,
97 "error: EF_SMS is not linear fixed with 176-byte records\n");
98 return(-1);
99 }
100 fprintf(outf, "SMS store: %u entries\n", curfile_record_count);
101 return(0);
102 }
103
104 static
105 do_smsp_store(outf)
106 FILE *outf;
107 {
108 int rc;
109
110 rc = select_op(EF_SMSP);
111 if (rc < 0)
112 return(rc);
113 rc = parse_ef_select_response();
114 if (rc < 0)
115 return(rc);
116 if (curfile_structure != 0x01) {
117 fprintf(stderr, "error: EF_SMSP is not linear fixed\n");
118 return(-1);
119 }
120 if (curfile_record_len < 28) {
121 fprintf(stderr,
122 "error: EF_SMSP has record length of %u bytes, less than minimum 14\n",
123 curfile_record_len);
124 return(-1);
125 }
126 fprintf(outf,
127 "SMS parameter store: %u entries, %u bytes of alpha tag\n",
128 curfile_record_count, curfile_record_len - 28);
129 return(0);
130 }
131
132 cmd_user_sum(argc, argv, outf)
133 char **argv;
134 FILE *outf;
135 {
136 int rc;
137 u_char sst[SST_BYTES_USED];
138
139 rc = read_sst(sst);
140 if (rc < 0)
141 return(rc);
142 rc = select_op(DF_TELECOM);
143 if (rc < 0)
144 return(rc);
145 if ((sst[0] & 0x0C) == 0x0C) {
146 rc = do_phonebook_file(EF_ADN, "EF_ADN", "ADN phonebook", outf);
147 if (rc < 0)
148 return(rc);
149 }
150 if ((sst[0] & 0x30) == 0x30) {
151 rc = do_phonebook_file(EF_FDN, "EF_FDN", "FDN phonebook", outf);
152 if (rc < 0)
153 return(rc);
154 }
155 if ((sst[0] & 0xC0) == 0xC0) {
156 rc = do_sms_store(outf);
157 if (rc < 0)
158 return(rc);
159 }
160 if ((sst[1] & 0x03) == 0x03)
161 fprintf(outf, "AoC service present\n");
162 if ((sst[2] & 0x03) == 0x03) {
163 rc = do_phonebook_file(EF_MSISDN, "EF_MSISDN", "MSISDN record",
164 outf);
165 if (rc < 0)
166 return(rc);
167 }
168 if ((sst[2] & 0xC0) == 0xC0) {
169 rc = do_smsp_store(outf);
170 if (rc < 0)
171 return(rc);
172 }
173 if ((sst[3] & 0x03) == 0x03) {
174 rc = do_phonebook_file(EF_LND, "EF_LND", "LND cyclic store",
175 outf);
176 if (rc < 0)
177 return(rc);
178 }
179 if ((sst[4] & 0x0C) == 0x0C) {
180 rc = do_phonebook_file(EF_SDN, "EF_SDN", "SDN phonebook", outf);
181 if (rc < 0)
182 return(rc);
183 }
184 if ((sst[13] & 0x03) == 0x03)
185 fprintf(outf, "MBDN present\n");
186 if ((sst[13] & 0x0C) == 0x0C)
187 fprintf(outf, "MWIS present\n");
188 return(0);
189 }