annotate simtool/pberase.c @ 133:f3bdefbeae38

fc-uicc-tool: readbin and readrec commands implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 04 Feb 2021 01:45:16 +0000
parents 87b34a244901
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
112
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements the pb-erase command.
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <string.h>
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <strings.h>
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <pcsclite.h>
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <winscard.h>
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "globals.h"
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 cmd_pb_erase(argc, argv)
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 char **argv;
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 {
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 int rc;
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 unsigned recno;
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 u_char record[255];
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 rc = phonebook_op_common(argv[1]);
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 if (rc < 0)
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 return(rc);
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 memset(record, 0xFF, curfile_record_len);
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 for (recno = 1; recno <= curfile_record_count; recno++) {
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 rc = update_rec_op(recno, 0x04, record, curfile_record_len);
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (rc < 0)
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 return(rc);
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 }
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 return(0);
87d459d9797a fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
115
0dcd666292e4 fc-simtool: pb-erase-one command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 112
diff changeset
32
0dcd666292e4 fc-simtool: pb-erase-one command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 112
diff changeset
33 cmd_pb_erase_one(argc, argv)
0dcd666292e4 fc-simtool: pb-erase-one command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 112
diff changeset
34 char **argv;
0dcd666292e4 fc-simtool: pb-erase-one command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 112
diff changeset
35 {
0dcd666292e4 fc-simtool: pb-erase-one command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 112
diff changeset
36 int rc;
0dcd666292e4 fc-simtool: pb-erase-one command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 112
diff changeset
37 unsigned recno;
0dcd666292e4 fc-simtool: pb-erase-one command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 112
diff changeset
38 u_char record[255];
0dcd666292e4 fc-simtool: pb-erase-one command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 112
diff changeset
39
0dcd666292e4 fc-simtool: pb-erase-one command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 112
diff changeset
40 rc = phonebook_op_common(argv[1]);
0dcd666292e4 fc-simtool: pb-erase-one command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 112
diff changeset
41 if (rc < 0)
0dcd666292e4 fc-simtool: pb-erase-one command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 112
diff changeset
42 return(rc);
0dcd666292e4 fc-simtool: pb-erase-one command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 112
diff changeset
43 recno = strtoul(argv[2], 0, 0);
0dcd666292e4 fc-simtool: pb-erase-one command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 112
diff changeset
44 if (recno < 1 || recno > curfile_record_count) {
0dcd666292e4 fc-simtool: pb-erase-one command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 112
diff changeset
45 fprintf(stderr, "error: specified record number is invalid\n");
0dcd666292e4 fc-simtool: pb-erase-one command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 112
diff changeset
46 return(-1);
0dcd666292e4 fc-simtool: pb-erase-one command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 112
diff changeset
47 }
0dcd666292e4 fc-simtool: pb-erase-one command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 112
diff changeset
48 memset(record, 0xFF, curfile_record_len);
0dcd666292e4 fc-simtool: pb-erase-one command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 112
diff changeset
49 return update_rec_op(recno, 0x04, record, curfile_record_len);
0dcd666292e4 fc-simtool: pb-erase-one command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 112
diff changeset
50 }
121
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
51
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
52 cmd_pb_erase_range(argc, argv)
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
53 char **argv;
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
54 {
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
55 int rc;
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
56 unsigned recno, startrec, endrec;
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
57 u_char record[255];
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
58
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
59 rc = phonebook_op_common(argv[1]);
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
60 if (rc < 0)
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
61 return(rc);
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
62 startrec = strtoul(argv[2], 0, 0);
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
63 if (startrec < 1 || startrec > curfile_record_count) {
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
64 fprintf(stderr,
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
65 "error: specified starting record number is invalid\n");
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
66 return(-1);
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
67 }
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
68 endrec = strtoul(argv[3], 0, 0);
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
69 if (endrec < 1 || endrec > curfile_record_count) {
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
70 fprintf(stderr,
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
71 "error: specified final record number is invalid\n");
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
72 return(-1);
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
73 }
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
74 if (startrec > endrec) {
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
75 fprintf(stderr, "error: reverse record range specified\n");
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
76 return(-1);
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
77 }
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
78 memset(record, 0xFF, curfile_record_len);
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
79 for (recno = startrec; recno <= endrec; recno++) {
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
80 rc = update_rec_op(recno, 0x04, record, curfile_record_len);
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
81 if (rc < 0)
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
82 return(rc);
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
83 }
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
84 return(0);
87b34a244901 fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
85 }