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