annotate rvinterf/asyncshell/at.c @ 389:2a47a8ef860a

CHANGES: User Phone Tools addition documented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 11 Mar 2018 17:04:10 +0000
parents bbc41034f14c
children dd0247097097
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Functions for the AT-over-RVTMUX interface
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
75
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
6 #include <sys/errno.h>
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <ctype.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <string.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <strings.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
75
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
12 #include <unistd.h>
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "pktmux.h"
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "limits.h"
64
d43d82cbfb85 fc-shell: use the newly adopted exit code convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
15 #include "exitcodes.h"
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
75
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
17 extern u_char rvi_msg[];
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
18 extern int rvi_msg_len;
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
19 extern int oneshot_nowait;
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
20 extern int sock;
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
21
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 send_string_to_ati(str)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 char *str;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 unsigned len;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 u_char sendpkt[MAX_PKT_TO_TARGET+1];
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 len = strlen(str);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 if (len + 1 > MAX_PKT_TO_TARGET) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 printf("error: max pkt to target limit exceeded\n");
64
d43d82cbfb85 fc-shell: use the newly adopted exit code convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
31 return(ERROR_USAGE);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 /* fill out the packet */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 sendpkt[0] = RVT_AT_HEADER;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 strcpy(sendpkt + 1, str);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 /* send it! */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 send_pkt_to_target(sendpkt, len + 1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 return(0);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 void
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 cmd_sendat(arg)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 char *arg;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 while (isspace(*arg))
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 arg++;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (!*arg) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 printf("error: missing string argument\n");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 return;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 ati_rx_control(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 send_string_to_ati(arg);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 }
75
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
54
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
55 oneshot_at_command(cmd)
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
56 char *cmd;
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
57 {
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
58 fd_set fds;
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
59 int rc;
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
60
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
61 if (!oneshot_nowait) {
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
62 init(); /* to catch the response properly */
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
63 ati_rx_control(1);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
64 }
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
65 rc = send_string_to_ati(cmd);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
66 if (rc)
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
67 exit(rc);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
68 if (oneshot_nowait)
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
69 exit(0);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
70 /* wait for response */
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
71 for (;;) {
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
72 FD_ZERO(&fds);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
73 FD_SET(sock, &fds);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
74 rc = select(sock+1, &fds, 0, 0, 0);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
75 if (rc < 0) {
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
76 if (errno == EINTR)
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
77 continue;
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
78 perror("select");
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
79 exit(ERROR_UNIX);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
80 }
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
81 if (FD_ISSET(sock, &fds))
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
82 handle_rvinterf_input();
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
83 }
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
84 }
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
85
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
86 cmd_str_oneshot(argc, argv)
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
87 char **argv;
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
88 {
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
89 return oneshot_at_command(argv[1]);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
90 }
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
91
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
92 void
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
93 oneshot_at_check_response()
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
94 {
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
95 if (rvi_msg_len == 4 && !strncmp(rvi_msg + 2, "OK", 2))
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
96 exit(0);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
97 if (rvi_msg_len == 4 && !strncmp(rvi_msg + 2, "> ", 2))
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
98 exit(0);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
99 if (rvi_msg_len == 7 && !strncmp(rvi_msg + 2, "ERROR", 5))
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
100 exit(ERROR_TARGET);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
101 if (rvi_msg_len == 6 && !strncmp(rvi_msg + 2, "BUSY", 4))
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
102 exit(ERROR_TARGET);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
103 if (rvi_msg_len == 12 && !strncmp(rvi_msg + 2, "NO CARRIER", 10))
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
104 exit(ERROR_TARGET);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
105 if (rvi_msg_len >= 12 && !strncmp(rvi_msg + 2, "+CME ERROR", 10))
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
106 exit(ERROR_TARGET);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
107 if (rvi_msg_len >= 12 && !strncmp(rvi_msg + 2, "+CMS ERROR", 10))
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
108 exit(ERROR_TARGET);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
109 }