FreeCalypso > hg > freecalypso-tools
annotate uptools/atcmd/smsend_main.c @ 983:0407d14fb854
PL-J flash PPB ops: rework for full verification of lock state
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 02 Dec 2023 08:22:00 +0000 |
parents | 6bf473f77fc4 |
children |
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) |
380
a8abaa85c378
fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents:
371
diff
changeset
|
14 #define MAX_MSG_UNI (67*255) |
365
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
15 |
966
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
965
diff
changeset
|
16 int sms_write_mode, text_mode, utf8_input, ucs2_mode, allow_escape; |
371
0bd06f481223
fcup-smsend: automatic -q (concat quiet) with -W
Mychaela Falconia <falcon@freecalypso.org>
parents:
370
diff
changeset
|
17 int concat_enable, concat_refno_set, concat_quiet; |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 u_char dest_addr[12]; |
966
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
965
diff
changeset
|
19 char msgtext[MAX_MSG_CHARS*3+2]; |
368
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
20 u_char concat_refno; |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 process_cmdline(argc, argv) |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 char **argv; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 { |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 int c; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 extern int optind; |
368
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
27 extern char *optarg; |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 |
966
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
965
diff
changeset
|
29 while ((c = getopt(argc, argv, "B:cC:enp:qRtuUwWX:")) != EOF) { |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 if (atinterf_cmdline_opt(c)) |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 continue; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 switch (c) { |
370
076d533f840d
fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
369
diff
changeset
|
33 case 'c': |
076d533f840d
fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
369
diff
changeset
|
34 concat_enable = 1; |
076d533f840d
fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
369
diff
changeset
|
35 continue; |
368
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
36 case 'C': |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
37 concat_enable = 1; |
368
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
38 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
|
39 concat_refno_set = 1; |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
40 continue; |
966
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
965
diff
changeset
|
41 case 'e': |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
965
diff
changeset
|
42 allow_escape = 1; |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
965
diff
changeset
|
43 continue; |
369
06cf82710cca
fcup-smsend: implemented -q option to suppress concat summary output
Mychaela Falconia <falcon@freecalypso.org>
parents:
368
diff
changeset
|
44 case 'q': |
371
0bd06f481223
fcup-smsend: automatic -q (concat quiet) with -W
Mychaela Falconia <falcon@freecalypso.org>
parents:
370
diff
changeset
|
45 concat_quiet = 1; |
369
06cf82710cca
fcup-smsend: implemented -q option to suppress concat summary output
Mychaela Falconia <falcon@freecalypso.org>
parents:
368
diff
changeset
|
46 continue; |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 case 't': |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 text_mode = 1; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 continue; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 case 'u': |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 utf8_input = 1; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 continue; |
380
a8abaa85c378
fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents:
371
diff
changeset
|
53 case 'U': |
a8abaa85c378
fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents:
371
diff
changeset
|
54 ucs2_mode = 1; |
a8abaa85c378
fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents:
371
diff
changeset
|
55 continue; |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 case 'w': |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 sms_write_mode = 1; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 continue; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 case 'W': |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 sms_write_mode = 2; |
371
0bd06f481223
fcup-smsend: automatic -q (concat quiet) with -W
Mychaela Falconia <falcon@freecalypso.org>
parents:
370
diff
changeset
|
61 concat_quiet = 1; |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 continue; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 default: |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 /* error msg already printed */ |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 exit(ERROR_USAGE); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 } |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
68 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
|
69 fprintf(stderr, |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
70 "%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
|
71 argv[0]); |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
72 exit(ERROR_USAGE); |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
73 } |
380
a8abaa85c378
fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents:
371
diff
changeset
|
74 if (ucs2_mode && text_mode) { |
a8abaa85c378
fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents:
371
diff
changeset
|
75 fprintf(stderr, "%s error: UCS-2 not supported in text mode\n", |
a8abaa85c378
fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents:
371
diff
changeset
|
76 argv[0]); |
a8abaa85c378
fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents:
371
diff
changeset
|
77 exit(ERROR_USAGE); |
a8abaa85c378
fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents:
371
diff
changeset
|
78 } |
966
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
965
diff
changeset
|
79 if (allow_escape && text_mode) { |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
965
diff
changeset
|
80 fprintf(stderr, |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
965
diff
changeset
|
81 "%s error: escapes not supported in text mode\n", |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
965
diff
changeset
|
82 argv[0]); |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
965
diff
changeset
|
83 exit(ERROR_USAGE); |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
965
diff
changeset
|
84 } |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 if (argc > optind + 2) { |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 fprintf(stderr, "usage: %s [options] dest-addr [message]\n", |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 argv[0]); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 exit(ERROR_USAGE); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 } |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 if (!argv[optind] || !argv[optind][0]) { |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 if (sms_write_mode == 2) { |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 dest_addr[0] = 0; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 dest_addr[1] = 0x80; |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 } else { |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 fprintf(stderr, |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 "error: destination address must be specified\n"); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 exit(ERROR_USAGE); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 } |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 } 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
|
100 fprintf(stderr, |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 "error: destination address argument is invalid\n"); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 exit(ERROR_USAGE); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 } |
405
ed9b67e7e741
fcup-smsend: fixed bug in the handling of -W with no dest address argument
Mychaela Falconia <falcon@freecalypso.org>
parents:
381
diff
changeset
|
104 if (argc < optind + 2) |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 return(0); |
966
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
965
diff
changeset
|
106 if (strlen(argv[optind+1]) > MAX_MSG_CHARS*3) { |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 fprintf(stderr, "error: message argument is too long\n"); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 exit(ERROR_USAGE); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 } |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 strcpy(msgtext, argv[optind+1]); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 return(1); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 } |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 read_msgtext_from_stdin() |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 { |
365
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
116 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
|
117 int cc; |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 |
365
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
119 pos = 0; |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
120 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
|
121 for (;;) { |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
122 if (!remain) { |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
123 fprintf(stderr, |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
124 "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
|
125 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
|
126 } |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 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
|
131 } |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
132 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
|
133 break; |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
134 pos += cc; |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
135 remain -= cc; |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 } |
365
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
137 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
|
138 } |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
139 |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
140 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
|
141 { |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
142 char *cp; |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
143 |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
144 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
|
145 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
|
146 cp--; |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
147 *cp = '\0'; |
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 |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
150 common_init() |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
151 { |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
152 atinterf_init(); |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
153 /* enable verbose error messages */ |
467
dc2fd8e6f42c
uptools/atcmd: null pointer passing fixes
Mychaela Falconia <falcon@freecalypso.org>
parents:
405
diff
changeset
|
154 atinterf_exec_cmd_needok("AT+CMEE=2", (char *) 0, (void *) 0); |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
155 } |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
156 |
380
a8abaa85c378
fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents:
371
diff
changeset
|
157 gsm7_mode_main() |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 { |
381
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
159 u_char msgtext_gsm7[MAX_MSG_CHARS]; |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
160 unsigned msgtext_gsmlen; |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 int rc; |
368
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
162 unsigned nparts, n; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
163 u_char udh[5]; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
164 unsigned pos, remain, chunk; |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 if (utf8_input && utf8_to_latin1(msgtext) < 0) { |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 fprintf(stderr, "error: invalid UTF-8 message\n"); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 exit(ERROR_USAGE); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 } |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 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
|
171 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
|
172 fprintf(stderr, |
4378d70b146b
fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
364
diff
changeset
|
173 "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
|
174 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
|
175 } |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 if (strlen(msgtext) > 160) { |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
177 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
|
178 exit(ERROR_USAGE); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 } |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
180 common_init(); |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 prep_for_text_mode(); |
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 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
|
183 if (sms_write_mode == 1) |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
184 sendafterwr_process(); |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
185 exit(0); |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
186 } |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
187 rc = latin1_to_gsm7(msgtext, msgtext_gsm7, MAX_MSG_CHARS, |
966
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
965
diff
changeset
|
188 &msgtext_gsmlen, allow_escape); |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
189 if (rc == -1) { |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
190 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
|
191 exit(ERROR_USAGE); |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
192 } |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
193 if (rc == -2) { |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
194 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
|
195 exit(ERROR_USAGE); |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
196 } |
966
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
965
diff
changeset
|
197 if (rc == -3) { |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
965
diff
changeset
|
198 fprintf(stderr, |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
965
diff
changeset
|
199 "error: message contains invalid backslash escape\n"); |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
965
diff
changeset
|
200 exit(ERROR_USAGE); |
ec7e23d5151f
fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents:
965
diff
changeset
|
201 } |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
202 if (msgtext_gsmlen <= 160) { |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
203 common_init(); |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 prep_for_pdu_mode(); |
965
2969032bdfac
fcup-smsend[mult]: fix buglet in K&R C NULL pointer passing
Mychaela Falconia <falcon@freecalypso.org>
parents:
467
diff
changeset
|
205 send_in_pdu_mode(dest_addr, msgtext_gsm7, msgtext_gsmlen, |
2969032bdfac
fcup-smsend[mult]: fix buglet in K&R C NULL pointer passing
Mychaela Falconia <falcon@freecalypso.org>
parents:
467
diff
changeset
|
206 (u_char *) 0, 0); |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
207 if (sms_write_mode == 1) |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
208 sendafterwr_process(); |
371
0bd06f481223
fcup-smsend: automatic -q (concat quiet) with -W
Mychaela Falconia <falcon@freecalypso.org>
parents:
370
diff
changeset
|
209 if (concat_enable && !concat_quiet) |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
210 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
|
211 exit(0); |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 } |
367
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
213 if (!concat_enable) |
ed1ecc249eb3
fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents:
366
diff
changeset
|
214 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
|
215 if (!concat_refno_set) |
076d533f840d
fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
369
diff
changeset
|
216 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
|
217 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
|
218 udh[0] = 0x00; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
219 udh[1] = 0x03; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
220 udh[2] = concat_refno; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
221 udh[3] = nparts; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
222 common_init(); |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
223 prep_for_pdu_mode(); |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
224 if (sms_write_mode == 0) |
467
dc2fd8e6f42c
uptools/atcmd: null pointer passing fixes
Mychaela Falconia <falcon@freecalypso.org>
parents:
405
diff
changeset
|
225 atinterf_exec_cmd_needok("AT+CMMS=1", (char *) 0, (void *) 0); |
368
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
226 pos = 0; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
227 remain = msgtext_gsmlen; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
228 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
|
229 udh[4] = n; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
230 chunk = 153; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
231 if (chunk > remain) |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
232 chunk = remain; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
233 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
|
234 pos += chunk; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
235 remain -= chunk; |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
236 } |
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
237 if (sms_write_mode == 0) |
467
dc2fd8e6f42c
uptools/atcmd: null pointer passing fixes
Mychaela Falconia <falcon@freecalypso.org>
parents:
405
diff
changeset
|
238 atinterf_exec_cmd_needok("AT+CMMS=0", (char *) 0, (void *) 0); |
368
3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents:
367
diff
changeset
|
239 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
|
240 sendafterwr_process(); |
371
0bd06f481223
fcup-smsend: automatic -q (concat quiet) with -W
Mychaela Falconia <falcon@freecalypso.org>
parents:
370
diff
changeset
|
241 if (!concat_quiet) |
369
06cf82710cca
fcup-smsend: implemented -q option to suppress concat summary output
Mychaela Falconia <falcon@freecalypso.org>
parents:
368
diff
changeset
|
242 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
|
243 exit(0); |
362
89fe66cb60f6
fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
244 } |
380
a8abaa85c378
fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents:
371
diff
changeset
|
245 |
381
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
246 ucs2_mode_main() |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
247 { |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
248 u_short msgtext_uni[MAX_MSG_UNI]; |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
249 unsigned msgtext_unilen; |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
250 int rc; |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
251 unsigned nparts, n; |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
252 u_char udh[5]; |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
253 unsigned pos, remain, chunk; |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
254 |
967
6bf473f77fc4
fcup-smsend: support backslash escapes in UCS-2 mode too
Mychaela Falconia <falcon@freecalypso.org>
parents:
966
diff
changeset
|
255 rc = utf8_to_ucs2(msgtext, msgtext_uni, MAX_MSG_UNI, &msgtext_unilen, |
6bf473f77fc4
fcup-smsend: support backslash escapes in UCS-2 mode too
Mychaela Falconia <falcon@freecalypso.org>
parents:
966
diff
changeset
|
256 allow_escape); |
381
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
257 if (rc == -1) { |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
258 fprintf(stderr, "error: invalid UTF-8 message\n"); |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
259 exit(ERROR_USAGE); |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
260 } |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
261 if (rc == -2) { |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
262 fprintf(stderr, "error: message too long for max concat SMS\n"); |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
263 exit(ERROR_USAGE); |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
264 } |
967
6bf473f77fc4
fcup-smsend: support backslash escapes in UCS-2 mode too
Mychaela Falconia <falcon@freecalypso.org>
parents:
966
diff
changeset
|
265 if (rc == -3) { |
6bf473f77fc4
fcup-smsend: support backslash escapes in UCS-2 mode too
Mychaela Falconia <falcon@freecalypso.org>
parents:
966
diff
changeset
|
266 fprintf(stderr, |
6bf473f77fc4
fcup-smsend: support backslash escapes in UCS-2 mode too
Mychaela Falconia <falcon@freecalypso.org>
parents:
966
diff
changeset
|
267 "error: message contains invalid backslash escape\n"); |
6bf473f77fc4
fcup-smsend: support backslash escapes in UCS-2 mode too
Mychaela Falconia <falcon@freecalypso.org>
parents:
966
diff
changeset
|
268 exit(ERROR_USAGE); |
6bf473f77fc4
fcup-smsend: support backslash escapes in UCS-2 mode too
Mychaela Falconia <falcon@freecalypso.org>
parents:
966
diff
changeset
|
269 } |
381
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
270 if (msgtext_unilen <= 70) { |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
271 common_init(); |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
272 prep_for_pdu_mode(); |
965
2969032bdfac
fcup-smsend[mult]: fix buglet in K&R C NULL pointer passing
Mychaela Falconia <falcon@freecalypso.org>
parents:
467
diff
changeset
|
273 send_pdu_ucs2(dest_addr, msgtext_uni, msgtext_unilen, |
2969032bdfac
fcup-smsend[mult]: fix buglet in K&R C NULL pointer passing
Mychaela Falconia <falcon@freecalypso.org>
parents:
467
diff
changeset
|
274 (u_char *) 0, 0); |
381
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
275 if (sms_write_mode == 1) |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
276 sendafterwr_process(); |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
277 if (concat_enable && !concat_quiet) |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
278 printf("Message sent as single SMS\n"); |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
279 exit(0); |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
280 } |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
281 if (!concat_enable) { |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
282 fprintf(stderr, "error: message exceeds 70 UCS-2 chars\n"); |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
283 exit(ERROR_USAGE); |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
284 } |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
285 if (!concat_refno_set) |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
286 concat_refno = get_concsms_refno_from_host_fs(); |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
287 nparts = (msgtext_unilen + 66) / 67; |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
288 udh[0] = 0x00; |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
289 udh[1] = 0x03; |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
290 udh[2] = concat_refno; |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
291 udh[3] = nparts; |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
292 common_init(); |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
293 prep_for_pdu_mode(); |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
294 if (sms_write_mode == 0) |
467
dc2fd8e6f42c
uptools/atcmd: null pointer passing fixes
Mychaela Falconia <falcon@freecalypso.org>
parents:
405
diff
changeset
|
295 atinterf_exec_cmd_needok("AT+CMMS=1", (char *) 0, (void *) 0); |
381
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
296 pos = 0; |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
297 remain = msgtext_unilen; |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
298 for (n = 1; n <= nparts; n++) { |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
299 udh[4] = n; |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
300 chunk = 67; |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
301 if (chunk > remain) |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
302 chunk = remain; |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
303 send_pdu_ucs2(dest_addr, msgtext_uni + pos, chunk, udh, 5); |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
304 pos += chunk; |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
305 remain -= chunk; |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
306 } |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
307 if (sms_write_mode == 0) |
467
dc2fd8e6f42c
uptools/atcmd: null pointer passing fixes
Mychaela Falconia <falcon@freecalypso.org>
parents:
405
diff
changeset
|
308 atinterf_exec_cmd_needok("AT+CMMS=0", (char *) 0, (void *) 0); |
381
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
309 if (sms_write_mode == 1) |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
310 sendafterwr_process(); |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
311 if (!concat_quiet) |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
312 printf("Message sent as %u SMS segments\n", nparts); |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
313 exit(0); |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
314 } |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
315 |
380
a8abaa85c378
fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents:
371
diff
changeset
|
316 main(argc, argv) |
a8abaa85c378
fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents:
371
diff
changeset
|
317 char **argv; |
a8abaa85c378
fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents:
371
diff
changeset
|
318 { |
a8abaa85c378
fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents:
371
diff
changeset
|
319 if (!process_cmdline(argc, argv)) |
a8abaa85c378
fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents:
371
diff
changeset
|
320 read_msgtext_from_stdin(); |
a8abaa85c378
fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents:
371
diff
changeset
|
321 trim_trailing_newlines(); |
381
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
322 if (ucs2_mode) |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
323 ucs2_mode_main(); |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
324 else |
40b1498ec39d
fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
380
diff
changeset
|
325 gsm7_mode_main(); |
380
a8abaa85c378
fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents:
371
diff
changeset
|
326 } |