annotate uptools/atcmd/smsend_main.c @ 966:ec7e23d5151f

fcup-smsend: add support for backslash escapes, new -e option
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 01 Sep 2023 15:44:52 +0000
parents 2969032bdfac
children 6bf473f77fc4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 }
ec7e23d5151f fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents: 965
diff changeset
85 if (ucs2_mode && allow_escape) {
ec7e23d5151f fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents: 965
diff changeset
86 fprintf(stderr, "%s error: UCS-2 escapes not supported yet\n",
ec7e23d5151f fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents: 965
diff changeset
87 argv[0]);
ec7e23d5151f fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents: 965
diff changeset
88 exit(ERROR_USAGE);
ec7e23d5151f fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents: 965
diff changeset
89 }
362
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 if (argc > optind + 2) {
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 fprintf(stderr, "usage: %s [options] dest-addr [message]\n",
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 argv[0]);
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 exit(ERROR_USAGE);
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 }
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 if (!argv[optind] || !argv[optind][0]) {
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 if (sms_write_mode == 2) {
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 dest_addr[0] = 0;
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 dest_addr[1] = 0x80;
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 } else {
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 must be specified\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 }
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 } 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
105 fprintf(stderr,
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 "error: destination address argument is invalid\n");
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 exit(ERROR_USAGE);
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 }
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
109 if (argc < optind + 2)
362
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 return(0);
966
ec7e23d5151f fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents: 965
diff changeset
111 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
112 fprintf(stderr, "error: message argument is too long\n");
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 exit(ERROR_USAGE);
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 }
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 strcpy(msgtext, argv[optind+1]);
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 return(1);
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 }
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 read_msgtext_from_stdin()
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 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
122 int cc;
362
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123
365
4378d70b146b fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 364
diff changeset
124 pos = 0;
4378d70b146b fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 364
diff changeset
125 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
126 for (;;) {
4378d70b146b fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 364
diff changeset
127 if (!remain) {
4378d70b146b fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 364
diff changeset
128 fprintf(stderr,
4378d70b146b fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 364
diff changeset
129 "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
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 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
133 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
134 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
135 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
136 }
4378d70b146b fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 364
diff changeset
137 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
138 break;
4378d70b146b fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 364
diff changeset
139 pos += cc;
4378d70b146b fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 364
diff changeset
140 remain -= cc;
362
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 }
365
4378d70b146b fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 364
diff changeset
142 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
143 }
4378d70b146b fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 364
diff changeset
144
4378d70b146b fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 364
diff changeset
145 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
146 {
4378d70b146b fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 364
diff changeset
147 char *cp;
4378d70b146b fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 364
diff changeset
148
4378d70b146b fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 364
diff changeset
149 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
150 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
151 cp--;
4378d70b146b fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 364
diff changeset
152 *cp = '\0';
362
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 }
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154
367
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
155 common_init()
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
156 {
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
157 atinterf_init();
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
158 /* enable verbose error messages */
467
dc2fd8e6f42c uptools/atcmd: null pointer passing fixes
Mychaela Falconia <falcon@freecalypso.org>
parents: 405
diff changeset
159 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
160 }
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
161
380
a8abaa85c378 fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents: 371
diff changeset
162 gsm7_mode_main()
362
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 {
381
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
164 u_char msgtext_gsm7[MAX_MSG_CHARS];
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
165 unsigned msgtext_gsmlen;
362
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 int rc;
368
3cc79e260066 fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents: 367
diff changeset
167 unsigned nparts, n;
3cc79e260066 fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents: 367
diff changeset
168 u_char udh[5];
3cc79e260066 fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents: 367
diff changeset
169 unsigned pos, remain, chunk;
362
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 if (utf8_input && utf8_to_latin1(msgtext) < 0) {
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 fprintf(stderr, "error: invalid UTF-8 message\n");
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 exit(ERROR_USAGE);
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 }
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 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
176 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
177 fprintf(stderr,
4378d70b146b fcup-smsend: added support for multiline messages in default PDU send mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 364
diff changeset
178 "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
179 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
180 }
362
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 if (strlen(msgtext) > 160) {
367
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
182 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
183 exit(ERROR_USAGE);
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 }
367
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
185 common_init();
362
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 prep_for_text_mode();
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 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
188 if (sms_write_mode == 1)
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
189 sendafterwr_process();
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
190 exit(0);
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
191 }
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
192 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
193 &msgtext_gsmlen, allow_escape);
367
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
194 if (rc == -1) {
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
195 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
196 exit(ERROR_USAGE);
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
197 }
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
198 if (rc == -2) {
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
199 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
200 exit(ERROR_USAGE);
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
201 }
966
ec7e23d5151f fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents: 965
diff changeset
202 if (rc == -3) {
ec7e23d5151f fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents: 965
diff changeset
203 fprintf(stderr,
ec7e23d5151f fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents: 965
diff changeset
204 "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
205 exit(ERROR_USAGE);
ec7e23d5151f fcup-smsend: add support for backslash escapes, new -e option
Mychaela Falconia <falcon@freecalypso.org>
parents: 965
diff changeset
206 }
367
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
207 if (msgtext_gsmlen <= 160) {
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
208 common_init();
362
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 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
210 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
211 (u_char *) 0, 0);
367
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
212 if (sms_write_mode == 1)
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
213 sendafterwr_process();
371
0bd06f481223 fcup-smsend: automatic -q (concat quiet) with -W
Mychaela Falconia <falcon@freecalypso.org>
parents: 370
diff changeset
214 if (concat_enable && !concat_quiet)
367
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
215 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
216 exit(0);
362
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 }
367
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
218 if (!concat_enable)
ed1ecc249eb3 fcup-smsend: prep for adding concat SMS support
Mychaela Falconia <falcon@freecalypso.org>
parents: 366
diff changeset
219 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
220 if (!concat_refno_set)
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents: 369
diff changeset
221 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
222 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
223 udh[0] = 0x00;
3cc79e260066 fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents: 367
diff changeset
224 udh[1] = 0x03;
3cc79e260066 fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents: 367
diff changeset
225 udh[2] = concat_refno;
3cc79e260066 fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents: 367
diff changeset
226 udh[3] = nparts;
3cc79e260066 fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents: 367
diff changeset
227 common_init();
3cc79e260066 fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents: 367
diff changeset
228 prep_for_pdu_mode();
3cc79e260066 fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents: 367
diff changeset
229 if (sms_write_mode == 0)
467
dc2fd8e6f42c uptools/atcmd: null pointer passing fixes
Mychaela Falconia <falcon@freecalypso.org>
parents: 405
diff changeset
230 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
231 pos = 0;
3cc79e260066 fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents: 367
diff changeset
232 remain = msgtext_gsmlen;
3cc79e260066 fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents: 367
diff changeset
233 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
234 udh[4] = n;
3cc79e260066 fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents: 367
diff changeset
235 chunk = 153;
3cc79e260066 fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents: 367
diff changeset
236 if (chunk > remain)
3cc79e260066 fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents: 367
diff changeset
237 chunk = remain;
3cc79e260066 fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents: 367
diff changeset
238 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
239 pos += chunk;
3cc79e260066 fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents: 367
diff changeset
240 remain -= chunk;
3cc79e260066 fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents: 367
diff changeset
241 }
3cc79e260066 fcup-smsend: implemented concat SMS sending with user-given refno
Mychaela Falconia <falcon@freecalypso.org>
parents: 367
diff changeset
242 if (sms_write_mode == 0)
467
dc2fd8e6f42c uptools/atcmd: null pointer passing fixes
Mychaela Falconia <falcon@freecalypso.org>
parents: 405
diff changeset
243 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
244 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
245 sendafterwr_process();
371
0bd06f481223 fcup-smsend: automatic -q (concat quiet) with -W
Mychaela Falconia <falcon@freecalypso.org>
parents: 370
diff changeset
246 if (!concat_quiet)
369
06cf82710cca fcup-smsend: implemented -q option to suppress concat summary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 368
diff changeset
247 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
248 exit(0);
362
89fe66cb60f6 fcup-smsend program put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 }
380
a8abaa85c378 fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents: 371
diff changeset
250
381
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
251 ucs2_mode_main()
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
252 {
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
253 u_short msgtext_uni[MAX_MSG_UNI];
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
254 unsigned msgtext_unilen;
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
255 int rc;
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
256 unsigned nparts, n;
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
257 u_char udh[5];
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
258 unsigned pos, remain, chunk;
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
259
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
260 rc = utf8_to_ucs2(msgtext, msgtext_uni, MAX_MSG_UNI, &msgtext_unilen);
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
261 if (rc == -1) {
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
262 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
263 exit(ERROR_USAGE);
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
264 }
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
265 if (rc == -2) {
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
266 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
267 exit(ERROR_USAGE);
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
268 }
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
269 if (msgtext_unilen <= 70) {
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
270 common_init();
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
271 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
272 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
273 (u_char *) 0, 0);
381
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
274 if (sms_write_mode == 1)
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
275 sendafterwr_process();
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
276 if (concat_enable && !concat_quiet)
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
277 printf("Message sent as single SMS\n");
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
278 exit(0);
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
279 }
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
280 if (!concat_enable) {
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
281 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
282 exit(ERROR_USAGE);
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
283 }
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
284 if (!concat_refno_set)
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
285 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
286 nparts = (msgtext_unilen + 66) / 67;
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
287 udh[0] = 0x00;
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
288 udh[1] = 0x03;
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
289 udh[2] = concat_refno;
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
290 udh[3] = nparts;
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
291 common_init();
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
292 prep_for_pdu_mode();
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
293 if (sms_write_mode == 0)
467
dc2fd8e6f42c uptools/atcmd: null pointer passing fixes
Mychaela Falconia <falcon@freecalypso.org>
parents: 405
diff changeset
294 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
295 pos = 0;
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
296 remain = msgtext_unilen;
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
297 for (n = 1; n <= nparts; n++) {
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
298 udh[4] = n;
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
299 chunk = 67;
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
300 if (chunk > remain)
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
301 chunk = remain;
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
302 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
303 pos += chunk;
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
304 remain -= chunk;
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
305 }
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
306 if (sms_write_mode == 0)
467
dc2fd8e6f42c uptools/atcmd: null pointer passing fixes
Mychaela Falconia <falcon@freecalypso.org>
parents: 405
diff changeset
307 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
308 if (sms_write_mode == 1)
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
309 sendafterwr_process();
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
310 if (!concat_quiet)
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
311 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
312 exit(0);
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
313 }
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
314
380
a8abaa85c378 fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents: 371
diff changeset
315 main(argc, argv)
a8abaa85c378 fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents: 371
diff changeset
316 char **argv;
a8abaa85c378 fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents: 371
diff changeset
317 {
a8abaa85c378 fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents: 371
diff changeset
318 if (!process_cmdline(argc, argv))
a8abaa85c378 fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents: 371
diff changeset
319 read_msgtext_from_stdin();
a8abaa85c378 fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents: 371
diff changeset
320 trim_trailing_newlines();
381
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
321 if (ucs2_mode)
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
322 ucs2_mode_main();
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
323 else
40b1498ec39d fcup-smsend: UCS-2 send mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 380
diff changeset
324 gsm7_mode_main();
380
a8abaa85c378 fcup-smsend: preparations for adding UCS-2 support
Mychaela Falconia <falcon@freecalypso.org>
parents: 371
diff changeset
325 }