FreeCalypso > hg > fc-pcsc-tools
annotate simtool/plmnsel.c @ 99:d2e800abd257
fc-simtool plmnsel-write command implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 17 Feb 2021 22:43:18 +0000 |
parents | 4eb447be01c0 |
children | a75c0aafb367 |
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> |
99
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
7 #include <stdlib.h> |
53
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include "simresp.h" |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include "curfile.h" |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include "file_id.h" |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 static |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 select_ef_plmnsel() |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 { |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 int rc; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 rc = select_op(DF_GSM); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 if (rc < 0) |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 return(rc); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 rc = select_op(EF_PLMNsel); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 if (rc < 0) |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 return(rc); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 rc = parse_ef_select_response(); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 if (rc < 0) |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 return(rc); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 if (curfile_structure != 0x00) { |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 fprintf(stderr, "error: EF_PLMNsel is not transparent\n"); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 return(-1); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 } |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 if (curfile_total_size < 24) { |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 fprintf(stderr, |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 "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
|
33 return(-1); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 } |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 if (curfile_total_size > 255) { |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 fprintf(stderr, |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 "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
|
38 return(-1); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 } |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 if (curfile_total_size % 3) { |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 fprintf(stderr, |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 "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
|
43 return(-1); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 } |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 return(0); |
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 |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 cmd_plmnsel_dump() |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 { |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 int rc, gap_flag; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 u_char *dp, *endp; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 char ascbuf[8]; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 unsigned idx, linelen; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 rc = select_ef_plmnsel(); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 if (rc < 0) |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 return(rc); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 rc = readbin_op(0, curfile_total_size); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 if (rc < 0) |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 return(rc); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 dp = sim_resp_data; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 endp = sim_resp_data + sim_resp_data_len; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 gap_flag = 0; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 linelen = 0; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 for (idx = 0; dp < endp; idx++, dp += 3) { |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 if (dp[0] == 0xFF && dp[1] == 0xFF && dp[2] == 0xFF) { |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 gap_flag = 1; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 continue; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 } |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 if (gap_flag) { |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 if (linelen) { |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 putchar('\n'); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 linelen = 0; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 } |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 printf("GAP, continuing at index %u:\n", idx); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 gap_flag = 0; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 } |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 if (linelen >= 10) { |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 putchar('\n'); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 linelen = 0; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 } |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 decode_plmn_3bytes(dp, ascbuf, 1); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 if (linelen) |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 putchar(' '); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 fputs(ascbuf, stdout); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 linelen++; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 } |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 if (linelen) |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 putchar('\n'); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 return(0); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 } |
99
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
92 |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
93 cmd_plmnsel_write(argc, argv) |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
94 char **argv; |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
95 { |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
96 int rc; |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
97 unsigned idx; |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
98 u_char rec[3]; |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
99 |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
100 rc = select_ef_plmnsel(); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
101 if (rc < 0) |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
102 return(rc); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
103 idx = strtoul(argv[1], 0, 0); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
104 if (idx >= curfile_total_size / 3) { |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
105 fprintf(stderr, "error: specified index is out of range\n"); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
106 return(-1); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
107 } |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
108 rc = encode_plmn_3bytes(argv[2], rec); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
109 if (rc < 0) |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
110 return(rc); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
111 return update_bin_op(idx * 3, rec, 3); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
112 } |