annotate uptools/atcmd/smsend_pduin.c @ 816:b3724fe6c581

fc-tmsh bsim commands implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 14 May 2021 17:16:43 +0000
parents dc2fd8e6f42c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
384
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This is the main module for the fcup-smsendpdu utility.
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <ctype.h>
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <string.h>
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <strings.h>
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <unistd.h>
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "../../rvinterf/include/exitcodes.h"
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 int sms_write_mode;
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 char input_line[176*2+2];
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 int lineno;
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 int initdone, cmms_done;
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 process_cmdline(argc, argv)
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 char **argv;
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 {
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 int c;
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 extern int optind;
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 while ((c = getopt(argc, argv, "B:np:RwWX:")) != EOF) {
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (atinterf_cmdline_opt(c))
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 continue;
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 switch (c) {
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 case 'w':
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 sms_write_mode = 1;
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 continue;
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 case 'W':
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 sms_write_mode = 2;
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 continue;
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 default:
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 /* error msg already printed */
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 exit(ERROR_USAGE);
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 if (argc != optind) {
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 fprintf(stderr, "usage: %s [options]\n", argv[0]);
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 exit(ERROR_USAGE);
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 }
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 return(0);
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 }
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 more_input()
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 {
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 int c;
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 c = getc(stdin);
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (c == EOF)
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 return(0);
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 ungetc(c, stdin);
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 return(1);
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 }
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 init_send_process()
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 {
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (initdone)
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 return(0);
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 atinterf_init();
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 /* enable verbose error messages */
467
dc2fd8e6f42c uptools/atcmd: null pointer passing fixes
Mychaela Falconia <falcon@freecalypso.org>
parents: 384
diff changeset
64 atinterf_exec_cmd_needok("AT+CMEE=2", (char *) 0, (void *) 0);
384
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 /* set PDU mode */
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 prep_for_pdu_mode();
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 if (sms_write_mode == 0 && more_input()) {
467
dc2fd8e6f42c uptools/atcmd: null pointer passing fixes
Mychaela Falconia <falcon@freecalypso.org>
parents: 384
diff changeset
68 atinterf_exec_cmd_needok("AT+CMMS=1", (char *) 0, (void *) 0);
384
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 cmms_done = 1;
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 }
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 initdone = 1;
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 return(1);
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 }
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 process_line()
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 {
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 char *cp;
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 u_char pdubin[176];
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 int cc, scalen;
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 cp = index(input_line, '\n');
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 if (!cp) {
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 fprintf(stderr, "input line %d: too long or unterminated\n",
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 lineno);
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 exit(ERROR_USAGE);
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 }
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 *cp = '\0';
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 cc = decode_hex_line(input_line, pdubin, sizeof pdubin);
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 if (cc < 1) {
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 inv: fprintf(stderr, "input line %d: not a valid PDU\n", lineno);
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 exit(ERROR_USAGE);
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 }
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 if (pdubin[0] == 1 || pdubin[0] > 11)
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 goto inv;
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 scalen = pdubin[0] + 1;
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 if (cc < scalen + 1)
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 goto inv;
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 /* good to go */
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 init_send_process();
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 send_pdu_out(input_line, cc - scalen);
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 }
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 main(argc, argv)
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 char **argv;
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 {
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 process_cmdline(argc, argv);
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 for (lineno = 1; fgets(input_line, sizeof input_line, stdin); lineno++)
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 process_line();
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 if (!initdone)
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 exit(0);
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 if (cmms_done)
467
dc2fd8e6f42c uptools/atcmd: null pointer passing fixes
Mychaela Falconia <falcon@freecalypso.org>
parents: 384
diff changeset
112 atinterf_exec_cmd_needok("AT+CMMS=0", (char *) 0, (void *) 0);
384
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 if (sms_write_mode == 1)
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 sendafterwr_process();
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 exit(0);
3eb92855f7b9 fcup-smsendpdu program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 }