annotate uptools/atcmd/smsend_main.c @ 368:3cc79e260066

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