FreeCalypso > hg > freecalypso-tools
annotate uptools/atcmd/smsend_main.c @ 371:0bd06f481223
fcup-smsend: automatic -q (concat quiet) with -W
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 08 Mar 2018 17:57:36 +0000 |
parents | 076d533f840d |
children | a8abaa85c378 |
rev | line source |
---|---|
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This is the main module for the basic fcup-smsend utility. |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdlib.h> |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <string.h> |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <strings.h> |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <unistd.h> |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "../../rvinterf/include/exitcodes.h" |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
13 #define MAX_MSG_CHARS (153*255) |
365
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
14 |
371
0bd06f481223
fcup-smsend: automatic -q (concat quiet) with -W
Mychaela Falconia <falcon@freecalypso.org>
parents:
370
diff
changeset
|
15 int sms_write_mode, text_mode, utf8_input; |
0bd06f481223
fcup-smsend: automatic -q (concat quiet) with -W
Mychaela Falconia <falcon@freecalypso.org>
parents:
370
diff
changeset
|
16 int concat_enable, concat_refno_set, concat_quiet; |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 u_char dest_addr[12]; |
365
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
18 char msgtext[MAX_MSG_CHARS*2+2]; |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
19 u_char msgtext_gsm7[MAX_MSG_CHARS]; |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 unsigned msgtext_gsmlen; |
368
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
21 u_char concat_refno; |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 process_cmdline(argc, argv) |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 char **argv; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 { |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 int c; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 extern int optind; |
368
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
28 extern char *optarg; |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 |
370
076d533f840d
fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
369
diff
changeset
|
30 while ((c = getopt(argc, argv, "B:cC:np:qRtuwWX:")) != EOF) { |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 if (atinterf_cmdline_opt(c)) |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 continue; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 switch (c) { |
370
076d533f840d
fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
369
diff
changeset
|
34 case 'c': |
076d533f840d
fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
369
diff
changeset
|
35 concat_enable = 1; |
076d533f840d
fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
369
diff
changeset
|
36 continue; |
368
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
37 case 'C': |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
38 concat_enable = 1; |
368
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
39 concat_refno = strtoul(optarg, 0, 0); |
370
076d533f840d
fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
369
diff
changeset
|
40 concat_refno_set = 1; |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
41 continue; |
369
06cf82710cca
fcup-smsend: implemented -q option to suppress concat summary output
Mychaela Falconia <falcon@freecalypso.org>
parents:
368
diff
changeset
|
42 case 'q': |
371
0bd06f481223
fcup-smsend: automatic -q (concat quiet) with -W
Mychaela Falconia <falcon@freecalypso.org>
parents:
370
diff
changeset
|
43 concat_quiet = 1; |
369
06cf82710cca
fcup-smsend: implemented -q option to suppress concat summary output
Mychaela Falconia <falcon@freecalypso.org>
parents:
368
diff
changeset
|
44 continue; |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 case 't': |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 text_mode = 1; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 continue; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 case 'u': |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 utf8_input = 1; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 continue; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 case 'w': |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 sms_write_mode = 1; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 continue; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 case 'W': |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 sms_write_mode = 2; |
371
0bd06f481223
fcup-smsend: automatic -q (concat quiet) with -W
Mychaela Falconia <falcon@freecalypso.org>
parents:
370
diff
changeset
|
56 concat_quiet = 1; |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 continue; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 default: |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 /* error msg already printed */ |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 exit(ERROR_USAGE); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 } |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 } |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
63 if (concat_enable && text_mode) { |
368
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
64 fprintf(stderr, |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
65 "%s error: cannot send concat SMS in text mode\n", |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
66 argv[0]); |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
67 exit(ERROR_USAGE); |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
68 } |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 if (argc > optind + 2) { |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 fprintf(stderr, "usage: %s [options] dest-addr [message]\n", |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 argv[0]); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 exit(ERROR_USAGE); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 } |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 if (!argv[optind] || !argv[optind][0]) { |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 if (sms_write_mode == 2) { |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 dest_addr[0] = 0; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 dest_addr[1] = 0x80; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 } else { |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 fprintf(stderr, |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 "error: destination address must be specified\n"); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 exit(ERROR_USAGE); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 } |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 } else if (parse_and_encode_dest_addr(argv[optind], dest_addr) < 0) { |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 fprintf(stderr, |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 "error: destination address argument is invalid\n"); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 exit(ERROR_USAGE); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 } |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 if (!argv[optind+1]) |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 return(0); |
365
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
90 if (strlen(argv[optind+1]) > MAX_MSG_CHARS*2) { |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 fprintf(stderr, "error: message argument is too long\n"); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 exit(ERROR_USAGE); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 } |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 strcpy(msgtext, argv[optind+1]); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 return(1); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 } |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 read_msgtext_from_stdin() |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 { |
365
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
100 unsigned pos, remain; |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
101 int cc; |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 |
365
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
103 pos = 0; |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
104 remain = sizeof(msgtext); |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
105 for (;;) { |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
106 if (!remain) { |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
107 fprintf(stderr, |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
108 "error: message on stdin is too long\n"); |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
109 exit(ERROR_USAGE); |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
110 } |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
111 cc = read(0, msgtext + pos, remain); |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
112 if (cc < 0) { |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
113 fprintf(stderr, "error reading message from stdin\n"); |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
114 exit(ERROR_USAGE); |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
115 } |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
116 if (cc == 0) |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
117 break; |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
118 pos += cc; |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
119 remain -= cc; |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 } |
365
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
121 msgtext[pos] = '\0'; |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
122 } |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
123 |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
124 trim_trailing_newlines() |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
125 { |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
126 char *cp; |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
127 |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
128 cp = index(msgtext, '\0'); |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
129 while (cp > msgtext && cp[-1] == '\n') |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
130 cp--; |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
131 *cp = '\0'; |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 } |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
134 common_init() |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
135 { |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
136 atinterf_init(); |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
137 /* enable verbose error messages */ |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
138 atinterf_exec_cmd_needok("AT+CMEE=2", 0, 0); |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
139 } |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
140 |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 main(argc, argv) |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 char **argv; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 { |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 int rc; |
368
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
145 unsigned nparts, n; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
146 u_char udh[5]; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
147 unsigned pos, remain, chunk; |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 if (!process_cmdline(argc, argv)) |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 read_msgtext_from_stdin(); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 if (utf8_input && utf8_to_latin1(msgtext) < 0) { |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 fprintf(stderr, "error: invalid UTF-8 message\n"); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 exit(ERROR_USAGE); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 } |
365
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
155 trim_trailing_newlines(); |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 if (text_mode) { |
365
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
157 if (index(msgtext, '\n')) { |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
158 fprintf(stderr, |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
159 "error: multiline messages not supported in text mode\n"); |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
160 exit(ERROR_USAGE); |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
161 } |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 if (strlen(msgtext) > 160) { |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
163 too_long_for_one_sms: fprintf(stderr, "error: message exceeds 160 chars\n"); |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 exit(ERROR_USAGE); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 } |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
166 common_init(); |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 prep_for_text_mode(); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 send_in_text_mode(dest_addr, msgtext); |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
169 if (sms_write_mode == 1) |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
170 sendafterwr_process(); |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
171 exit(0); |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
172 } |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
173 rc = latin1_to_gsm7(msgtext, msgtext_gsm7, MAX_MSG_CHARS, |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
174 &msgtext_gsmlen); |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
175 if (rc == -1) { |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
176 fprintf(stderr, "error: message not valid for GSM7 charset\n"); |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
177 exit(ERROR_USAGE); |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
178 } |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
179 if (rc == -2) { |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
180 fprintf(stderr, "error: message too long for max concat SMS\n"); |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
181 exit(ERROR_USAGE); |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
182 } |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
183 if (msgtext_gsmlen <= 160) { |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
184 common_init(); |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 prep_for_pdu_mode(); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 send_in_pdu_mode(dest_addr, msgtext_gsm7, msgtext_gsmlen, 0, 0); |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
187 if (sms_write_mode == 1) |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
188 sendafterwr_process(); |
371
0bd06f481223
fcup-smsend: automatic -q (concat quiet) with -W
Mychaela Falconia <falcon@freecalypso.org>
parents:
370
diff
changeset
|
189 if (concat_enable && !concat_quiet) |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
190 printf("Message sent as single SMS\n"); |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
191 exit(0); |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 } |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
193 if (!concat_enable) |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
194 goto too_long_for_one_sms; |
370
076d533f840d
fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
369
diff
changeset
|
195 if (!concat_refno_set) |
076d533f840d
fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
369
diff
changeset
|
196 concat_refno = get_concsms_refno_from_host_fs(); |
368
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
197 nparts = (msgtext_gsmlen + 152) / 153; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
198 udh[0] = 0x00; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
199 udh[1] = 0x03; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
200 udh[2] = concat_refno; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
201 udh[3] = nparts; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
202 common_init(); |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
203 prep_for_pdu_mode(); |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
204 if (sms_write_mode == 0) |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
205 atinterf_exec_cmd_needok("AT+CMMS=1", 0, 0); |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
206 pos = 0; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
207 remain = msgtext_gsmlen; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
208 for (n = 1; n <= nparts; n++) { |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
209 udh[4] = n; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
210 chunk = 153; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
211 if (chunk > remain) |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
212 chunk = remain; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
213 send_in_pdu_mode(dest_addr, msgtext_gsm7 + pos, chunk, udh, 5); |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
214 pos += chunk; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
215 remain -= chunk; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
216 } |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
217 if (sms_write_mode == 0) |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
218 atinterf_exec_cmd_needok("AT+CMMS=0", 0, 0); |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
219 if (sms_write_mode == 1) |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
220 sendafterwr_process(); |
371
0bd06f481223
fcup-smsend: automatic -q (concat quiet) with -W
Mychaela Falconia <falcon@freecalypso.org>
parents:
370
diff
changeset
|
221 if (!concat_quiet) |
369
06cf82710cca
fcup-smsend: implemented -q option to suppress concat summary output
Mychaela Falconia <falcon@freecalypso.org>
parents:
368
diff
changeset
|
222 printf("Message sent as %u SMS segments\n", nparts); |
368
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
223 exit(0); |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 } |