annotate uptools/atcmd/smdump.c @ 363:46cf847781bd

fcup-smsend: buglet in PDU mode length manipulations
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 05 Mar 2018 02:58:13 +0000
parents 3bcc56883b17
children ac311a48630e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
352
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This utility retrieves a dump of all stored SMS records in PDU mode.
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdlib.h>
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <string.h>
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <strings.h>
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <unistd.h>
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "../../rvinterf/include/exitcodes.h"
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "resp_parse.h"
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 extern char at_response[];
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
353
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
16 struct delafter {
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
17 unsigned msgid;
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
18 struct delafter *next;
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
19 };
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
20
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
21 int delete_after_flag;
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
22 struct delafter *delafter_head, **delafter_tail = &delafter_head;
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
23
352
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 int pdu_state;
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 char *msgtype;
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 u_char pbname_gsm[40];
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 unsigned pbname_len, header_len;
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 u_char pdu_bin[176];
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
353
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
30 add_delafter_record(msgid)
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
31 unsigned msgid;
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
32 {
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
33 struct delafter *rec;
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
34
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
35 rec = malloc(sizeof(struct delafter));
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
36 if (!rec)
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
37 return;
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
38 rec->msgid = msgid;
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
39 rec->next = 0;
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
40 *delafter_tail = rec;
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
41 delafter_tail = &rec->next;
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
42 }
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
43
352
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 validate_pbname_7bit()
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 {
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 unsigned n;
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 for (n = 0; n < pbname_len; n++)
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 if (pbname_gsm[n] & 0x80)
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 return(-1);
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 return(0);
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 cmgl_header()
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 {
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 struct resp_field fields[4];
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 int cc;
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 /* skip empty lines */
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (!at_response[1])
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 return;
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 /* if not empty, it MUST be +CMGL */
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 if (strncmp(at_response+1, "+CMGL: ", 7)) {
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 fprintf(stderr, "error: response from target is not +CMGL\n");
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 exit(ERROR_TARGET);
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 if (parse_structured_response(at_response+8, fields, 4) != 4) {
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 malformed: fprintf(stderr, "error: malformed +CMGL response\n");
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 exit(ERROR_TARGET);
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 }
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 if (fields[0].type != RESP_FIELD_NUMBER ||
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 fields[1].type != RESP_FIELD_NUMBER ||
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 fields[3].type != RESP_FIELD_NUMBER)
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 goto malformed;
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 if (fields[2].type != RESP_FIELD_STRING &&
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 fields[2].type != RESP_FIELD_EMPTY)
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 goto malformed;
353
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
78 if (delete_after_flag)
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
79 add_delafter_record(fields[0].num);
352
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 switch (fields[1].num) {
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 case 0:
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 case 1:
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 msgtype = "Received";
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 break;
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 case 2:
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 msgtype = "Stored unsent";
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 break;
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 case 3:
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 msgtype = "Sent";
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 break;
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 default:
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 fprintf(stderr,
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 "error: invalid message status code in +CMGL response\n");
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 exit(ERROR_TARGET);
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 }
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 if (fields[2].type == RESP_FIELD_STRING) {
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 cc = decode_hex_line(fields[2].str, pbname_gsm,
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 sizeof pbname_gsm);
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 if (cc >= 1) {
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 pbname_len = cc;
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 if (validate_pbname_7bit() < 0)
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 pbname_len = 0;
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 } else
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 pbname_len = 0;
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 } else
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 pbname_len = 0;
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 header_len = fields[3].num;
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 pdu_state = 1;
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 }
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 emit_pb_name()
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 {
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 u_char decoded_name[81];
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 gsm7_to_ascii_or_ext(pbname_gsm, pbname_len, decoded_name, 0, 0, 0, 0);
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 printf("Phonebook-Name: %s\n", decoded_name);
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 }
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 cmgl_pdu()
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 {
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 int cc;
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 unsigned sca_len;
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 cc = decode_hex_line(at_response+1, pdu_bin, sizeof pdu_bin);
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 if (cc < 1) {
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 fprintf(stderr, "error: expected PDU not received\n");
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 exit(ERROR_TARGET);
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 }
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 sca_len = pdu_bin[0];
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 if (1 + sca_len + header_len != cc) {
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 fprintf(stderr, "error: PDU length mismatch\n");
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 exit(ERROR_TARGET);
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 }
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 printf("%s message:\n", msgtype);
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 if (pbname_len)
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 emit_pb_name();
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 puts(at_response+1);
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 putchar('\n');
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 pdu_state = 0;
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 }
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 cmgl_callback()
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 {
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 if (pdu_state)
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 cmgl_pdu();
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 else
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 cmgl_header();
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 }
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149
353
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
150 delete_after_process()
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
151 {
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
152 struct delafter *rec;
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
153 char cmgd_cmd[32];
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
154
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
155 for (rec = delafter_head; rec; rec = rec->next) {
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
156 sprintf(cmgd_cmd, "AT+CMGD=%u", rec->msgid);
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
157 atinterf_exec_cmd_needok(cmgd_cmd, 0, 0);
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
158 }
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
159 }
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
160
352
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 main(argc, argv)
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 char **argv;
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 {
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 int c;
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 extern int optind;
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166
353
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
167 while ((c = getopt(argc, argv, "B:dnp:RX:")) != EOF) {
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
168 if (atinterf_cmdline_opt(c))
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
169 continue;
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
170 else if (c == 'd')
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
171 delete_after_flag = 1;
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
172 else {
352
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 /* error msg already printed */
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 exit(ERROR_USAGE);
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 }
353
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
176 }
352
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 if (argc != optind) {
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 fprintf(stderr, "usage: %s [options]\n", argv[0]);
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 exit(ERROR_USAGE);
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 }
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 atinterf_init();
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 /* put the 07.05 modem in PDU mode */
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 atinterf_exec_cmd_needok("AT+CMGF=0", 0, 0);
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 /* HEX charset for phonebook names */
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 atinterf_exec_cmd_needok("AT+CSCS=\"HEX\"", 0, 0);
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 /* main command */
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 atinterf_exec_cmd_needok("AT+CMGL=4", 0, cmgl_callback);
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 if (pdu_state) {
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 fprintf(stderr, "error: wrong state at the end of +CMGL\n");
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 exit(ERROR_TARGET);
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 }
353
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
192 if (delete_after_flag)
3bcc56883b17 fcup-smdump: -d delete-after-dump option implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 352
diff changeset
193 delete_after_process();
352
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 exit(0);
02d6c8469535 fcup-smdump implemented, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 }