comparison uicc/pberase.c @ 147:43463dc91431

fc-uicc-tool: pb-erase commands ported over
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 06 Feb 2021 02:54:16 +0000
parents
children
comparison
equal deleted inserted replaced
146:ce2a880ab704 147:43463dc91431
1 /*
2 * This module implements the pb-erase command.
3 */
4
5 #include <sys/types.h>
6 #include <string.h>
7 #include <strings.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10
11 cmd_pb_erase(argc, argv)
12 char **argv;
13 {
14 int rc;
15 unsigned recno;
16 u_char record[255];
17 unsigned pb_record_len, pb_record_count;
18
19 rc = phonebook_op_common(argv[1], &pb_record_len, &pb_record_count);
20 if (rc < 0)
21 return(rc);
22 memset(record, 0xFF, pb_record_len);
23 for (recno = 1; recno <= pb_record_count; recno++) {
24 rc = update_rec_op(recno, 0x04, record, pb_record_len);
25 if (rc < 0)
26 return(rc);
27 }
28 return(0);
29 }
30
31 cmd_pb_erase_one(argc, argv)
32 char **argv;
33 {
34 int rc;
35 unsigned recno;
36 u_char record[255];
37 unsigned pb_record_len, pb_record_count;
38
39 rc = phonebook_op_common(argv[1], &pb_record_len, &pb_record_count);
40 if (rc < 0)
41 return(rc);
42 recno = strtoul(argv[2], 0, 0);
43 if (recno < 1 || recno > pb_record_count) {
44 fprintf(stderr, "error: specified record number is invalid\n");
45 return(-1);
46 }
47 memset(record, 0xFF, pb_record_len);
48 return update_rec_op(recno, 0x04, record, pb_record_len);
49 }
50
51 cmd_pb_erase_range(argc, argv)
52 char **argv;
53 {
54 int rc;
55 unsigned recno, startrec, endrec;
56 u_char record[255];
57 unsigned pb_record_len, pb_record_count;
58
59 rc = phonebook_op_common(argv[1], &pb_record_len, &pb_record_count);
60 if (rc < 0)
61 return(rc);
62 startrec = strtoul(argv[2], 0, 0);
63 if (startrec < 1 || startrec > pb_record_count) {
64 fprintf(stderr,
65 "error: specified starting record number is invalid\n");
66 return(-1);
67 }
68 endrec = strtoul(argv[3], 0, 0);
69 if (endrec < 1 || endrec > pb_record_count) {
70 fprintf(stderr,
71 "error: specified final record number is invalid\n");
72 return(-1);
73 }
74 if (startrec > endrec) {
75 fprintf(stderr, "error: reverse record range specified\n");
76 return(-1);
77 }
78 memset(record, 0xFF, pb_record_len);
79 for (recno = startrec; recno <= endrec; recno++) {
80 rc = update_rec_op(recno, 0x04, record, pb_record_len);
81 if (rc < 0)
82 return(rc);
83 }
84 return(0);
85 }