annotate uptools/atcmd/smsend_main.c @ 369:06cf82710cca

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