comparison simtool/smserase.c @ 10:ddd767f6e15b

fc-simtool ported over
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Mar 2021 07:11:25 +0000
parents
children
comparison
equal deleted inserted replaced
9:c9ef9e91dd8e 10:ddd767f6e15b
1 /*
2 * This module implements the sms-erase family of commands.
3 */
4
5 #include <sys/types.h>
6 #include <string.h>
7 #include <strings.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "curfile.h"
11 #include "file_id.h"
12
13 #define SMS_RECORD_LEN 176
14
15 static
16 select_ef_sms()
17 {
18 int rc;
19
20 rc = select_op(DF_TELECOM);
21 if (rc < 0)
22 return(rc);
23 rc = select_op(EF_SMS);
24 if (rc < 0)
25 return(rc);
26 rc = parse_ef_select_response();
27 if (rc < 0)
28 return(rc);
29 if (curfile_structure != 0x01) {
30 fprintf(stderr, "error: EF_SMS is not linear fixed\n");
31 return(-1);
32 }
33 if (curfile_record_len != SMS_RECORD_LEN) {
34 fprintf(stderr,
35 "error: EF_SMS has record length of %u bytes, expected 176\n",
36 curfile_record_len);
37 return(-1);
38 }
39 return(0);
40 }
41
42 cmd_sms_erase_all(argc, argv)
43 char **argv;
44 {
45 int rc;
46 unsigned recno;
47 u_char record[SMS_RECORD_LEN];
48
49 rc = select_ef_sms();
50 if (rc < 0)
51 return(rc);
52 memset(record, 0xFF, SMS_RECORD_LEN);
53 record[0] = 0;
54 for (recno = 1; recno <= curfile_record_count; recno++) {
55 rc = update_rec_op(recno, 0x04, record, SMS_RECORD_LEN);
56 if (rc < 0)
57 return(rc);
58 }
59 return(0);
60 }
61
62 cmd_sms_erase_one(argc, argv)
63 char **argv;
64 {
65 int rc;
66 unsigned recno;
67 u_char record[SMS_RECORD_LEN];
68
69 rc = select_ef_sms();
70 if (rc < 0)
71 return(rc);
72 recno = strtoul(argv[1], 0, 0);
73 if (recno < 1 || recno > curfile_record_count) {
74 fprintf(stderr, "error: specified record number is invalid\n");
75 return(-1);
76 }
77 memset(record, 0xFF, SMS_RECORD_LEN);
78 record[0] = 0;
79 return update_rec_op(recno, 0x04, record, SMS_RECORD_LEN);
80 }
81
82 cmd_sms_erase_range(argc, argv)
83 char **argv;
84 {
85 int rc;
86 unsigned recno, startrec, endrec;
87 u_char record[SMS_RECORD_LEN];
88
89 rc = select_ef_sms();
90 if (rc < 0)
91 return(rc);
92 startrec = strtoul(argv[1], 0, 0);
93 if (startrec < 1 || startrec > curfile_record_count) {
94 fprintf(stderr,
95 "error: specified starting record number is invalid\n");
96 return(-1);
97 }
98 if (!strcmp(argv[2], "end"))
99 endrec = curfile_record_count;
100 else {
101 endrec = strtoul(argv[2], 0, 0);
102 if (endrec < 1 || endrec > curfile_record_count) {
103 fprintf(stderr,
104 "error: specified final record number is invalid\n");
105 return(-1);
106 }
107 if (startrec > endrec) {
108 fprintf(stderr,
109 "error: reverse record range specified\n");
110 return(-1);
111 }
112 }
113 memset(record, 0xFF, SMS_RECORD_LEN);
114 record[0] = 0;
115 for (recno = startrec; recno <= endrec; recno++) {
116 rc = update_rec_op(recno, 0x04, record, SMS_RECORD_LEN);
117 if (rc < 0)
118 return(rc);
119 }
120 return(0);
121 }