comparison simtool/plmnsel.c @ 53:4eb447be01c0

fc-simtool plmnsel-dump implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 13 Feb 2021 06:26:52 +0000
parents
children d2e800abd257
comparison
equal deleted inserted replaced
52:2f697a8c5196 53:4eb447be01c0
1 /*
2 * This module implements commands for working with EF_PLMNsel.
3 */
4
5 #include <sys/types.h>
6 #include <stdio.h>
7 #include "simresp.h"
8 #include "curfile.h"
9 #include "file_id.h"
10
11 static
12 select_ef_plmnsel()
13 {
14 int rc;
15
16 rc = select_op(DF_GSM);
17 if (rc < 0)
18 return(rc);
19 rc = select_op(EF_PLMNsel);
20 if (rc < 0)
21 return(rc);
22 rc = parse_ef_select_response();
23 if (rc < 0)
24 return(rc);
25 if (curfile_structure != 0x00) {
26 fprintf(stderr, "error: EF_PLMNsel is not transparent\n");
27 return(-1);
28 }
29 if (curfile_total_size < 24) {
30 fprintf(stderr,
31 "error: EF_PLMNsel is shorter than spec minimum of 24 bytes\n");
32 return(-1);
33 }
34 if (curfile_total_size > 255) {
35 fprintf(stderr,
36 "error: EF_PLMNsel is longer than our 255 byte limit\n");
37 return(-1);
38 }
39 if (curfile_total_size % 3) {
40 fprintf(stderr,
41 "error: EF_PLMNsel length is not a multiple of 3 bytes\n");
42 return(-1);
43 }
44 return(0);
45 }
46
47 cmd_plmnsel_dump()
48 {
49 int rc, gap_flag;
50 u_char *dp, *endp;
51 char ascbuf[8];
52 unsigned idx, linelen;
53
54 rc = select_ef_plmnsel();
55 if (rc < 0)
56 return(rc);
57 rc = readbin_op(0, curfile_total_size);
58 if (rc < 0)
59 return(rc);
60 dp = sim_resp_data;
61 endp = sim_resp_data + sim_resp_data_len;
62 gap_flag = 0;
63 linelen = 0;
64 for (idx = 0; dp < endp; idx++, dp += 3) {
65 if (dp[0] == 0xFF && dp[1] == 0xFF && dp[2] == 0xFF) {
66 gap_flag = 1;
67 continue;
68 }
69 if (gap_flag) {
70 if (linelen) {
71 putchar('\n');
72 linelen = 0;
73 }
74 printf("GAP, continuing at index %u:\n", idx);
75 gap_flag = 0;
76 }
77 if (linelen >= 10) {
78 putchar('\n');
79 linelen = 0;
80 }
81 decode_plmn_3bytes(dp, ascbuf, 1);
82 if (linelen)
83 putchar(' ');
84 fputs(ascbuf, stdout);
85 linelen++;
86 }
87 if (linelen)
88 putchar('\n');
89 return(0);
90 }