comparison simtool/smserase.c @ 42:2714d379edc2

fc-simtool sms-erase-* command family implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 12 Feb 2021 23:02:09 +0000
parents simtool/smsp_erase.c@4c240a37e7c4
children 10030acba82f
comparison
equal deleted inserted replaced
41:8cb269f5a902 42:2714d379edc2
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 endrec = strtoul(argv[2], 0, 0);
99 if (endrec < 1 || endrec > curfile_record_count) {
100 fprintf(stderr,
101 "error: specified final record number is invalid\n");
102 return(-1);
103 }
104 if (startrec > endrec) {
105 fprintf(stderr, "error: reverse record range specified\n");
106 return(-1);
107 }
108 memset(record, 0xFF, SMS_RECORD_LEN);
109 record[0] = 0;
110 for (recno = startrec; recno <= endrec; recno++) {
111 rc = update_rec_op(recno, 0x04, record, SMS_RECORD_LEN);
112 if (rc < 0)
113 return(rc);
114 }
115 return(0);
116 }