annotate uptools/atcmd/smsend_main.c @ 370:076d533f840d

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