annotate uicc/pbdump.c @ 156:6d9d0cfc9ed8

fc-simtool: grcard2-set-adm command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Feb 2021 02:40:28 +0000
parents a21d348e01db
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
136
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements the pb-dump command.
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <string.h>
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <strings.h>
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <pcsclite.h>
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <winscard.h>
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "globals.h"
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 static char gsm_address_digits[16] =
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 {'0','1','2','3','4','5','6','7','8','9','*','#','a','b','c','?'};
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 static
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 check_all_blank()
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 {
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 u_char *dp, *endp;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 dp = sim_resp_data;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 endp = sim_resp_data + sim_resp_data_len;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 while (dp < endp)
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 if (*dp++ != 0xFF)
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 return(0);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 return(1);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 }
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 static
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 decode_number(data, nbytes, out)
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 u_char *data;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 unsigned nbytes;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 char *out;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 {
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 u_char *dp, *endp;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 int c;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 dp = data;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 endp = data + nbytes;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 while (dp < endp) {
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 c = *dp & 0xF;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 if (c == 0xF)
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 return(-1);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 *out++ = gsm_address_digits[c];
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 c = *dp >> 4;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (c == 0xF) {
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (dp + 1 == endp)
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 break;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 else
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 return(-1);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 *out++ = gsm_address_digits[c];
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 dp++;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 *out = '\0';
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 return(0);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 }
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 static
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 check_blank_area(dp, endp)
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 u_char *dp, *endp;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 {
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 while (dp < endp)
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 if (*dp++ != 0xFF)
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 return(-1);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 return(0);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 }
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 static void
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 dump_record(recno, record_len, outf)
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 unsigned recno, record_len;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 FILE *outf;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 {
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 int rc;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 unsigned textlen;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 u_char *fixp;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 char digits[21];
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 fprintf(outf, "#%u: ", recno);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 if (record_len > 14) {
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 rc = validate_alpha_field(sim_resp_data,
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 record_len - 14,
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 &textlen);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 if (rc < 0) {
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 malformed: fprintf(outf, "malformed record\n");
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 return;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 }
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 } else
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 textlen = 0;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 fixp = sim_resp_data + sim_resp_data_len - 14;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 if (fixp[0] < 2 || fixp[0] > 11)
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 goto malformed;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 rc = decode_number(fixp + 2, fixp[0] - 1, digits);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 if (rc < 0)
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 goto malformed;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 rc = check_blank_area(fixp + 1 + fixp[0], fixp + 12);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 if (rc < 0)
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 goto malformed;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 /* all checks passed */
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 fprintf(outf, "%s,0x%02X ", digits, fixp[1]);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 if (fixp[12] != 0xFF)
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 fprintf(outf, "CCP=%u ", fixp[12]);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 if (fixp[13] != 0xFF)
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 fprintf(outf, "EXT=%u ", fixp[13]);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 print_alpha_field(sim_resp_data, textlen, outf);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 putc('\n', outf);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 }
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 cmd_pb_dump(argc, argv)
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 char **argv;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 {
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 int rc;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 FILE *outf;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 unsigned recno;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 unsigned record_len, record_count;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 rc = phonebook_op_common(argv[1], &record_len, &record_count);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 if (rc < 0)
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 return(rc);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 if (argv[2]) {
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 outf = fopen(argv[2], "w");
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 if (!outf) {
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 perror(argv[2]);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 return(-1);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 }
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 } else
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 outf = stdout;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 for (recno = 1; recno <= record_count; recno++) {
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 rc = readrec_op(recno, 0x04, record_len);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 if (rc < 0) {
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 if (argv[2])
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 fclose(outf);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 return(rc);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 }
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 if (check_all_blank())
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 continue;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 dump_record(recno, record_len, outf);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 }
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 if (argv[2])
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 fclose(outf);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 return(0);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 }
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 cmd_pb_dump_rec(argc, argv)
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 char **argv;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 {
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 int rc;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 unsigned recno, startrec, endrec;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 unsigned record_len, record_count;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 rc = phonebook_op_common(argv[1], &record_len, &record_count);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 if (rc < 0)
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 return(rc);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 startrec = strtoul(argv[2], 0, 0);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 if (startrec < 1 || startrec > record_count) {
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 fprintf(stderr,
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 "error: specified starting record number is invalid\n");
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 return(-1);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 }
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 if (argv[3]) {
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 endrec = strtoul(argv[3], 0, 0);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 if (endrec < 1 || endrec > record_count) {
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 fprintf(stderr,
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 "error: specified final record number is invalid\n");
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 return(-1);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 }
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 if (startrec > endrec) {
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 fprintf(stderr,
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 "error: reverse record range specified\n");
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 return(-1);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 }
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 } else
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 endrec = startrec;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 for (recno = startrec; recno <= endrec; recno++) {
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 rc = readrec_op(recno, 0x04, record_len);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 if (rc < 0)
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 return(rc);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 if (check_all_blank())
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 continue;
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 dump_record(recno, record_len, stdout);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 }
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 return(0);
a21d348e01db fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 }