comparison rvinterf/asyncshell/tchcmd.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children d43d82cbfb85
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
1 /*
2 * Commands for manipulating the experimental TCH rerouting feature
3 * of FreeCalypso GSM firmware
4 */
5
6 #include <sys/types.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include <strings.h>
10 #include <stdlib.h>
11 #include "pktmux.h"
12 #include "limits.h"
13 #include "tch_feature.h"
14
15 extern u_char rvi_msg[];
16 extern int rvi_msg_len;
17
18 static int tch_rawdump_mode;
19
20 send_tch_config_req(config)
21 {
22 u_char sendpkt[3];
23
24 sendpkt[0] = RVT_TCH_HEADER;
25 sendpkt[1] = TCH_CONFIG_REQ;
26 sendpkt[2] = config;
27 /* send it! */
28 send_pkt_to_target(sendpkt, 3);
29 return(0);
30 }
31
32 cmd_tchdl_common(argc, argv)
33 char **argv;
34 {
35 int config;
36
37 if (!strcmp(argv[0], "enable") || !strcmp(argv[0], "on") ||
38 !strcmp(argv[0], "1"))
39 config = 1;
40 else if (!strcmp(argv[0], "disable") || !strcmp(argv[0], "off") ||
41 !strcmp(argv[0], "0"))
42 config = 0;
43 else {
44 printf("error: boolean argument required\n");
45 return(1);
46 }
47 return send_tch_config_req(config);
48 }
49
50 void
51 cmd_tchdl_interactive(argstr)
52 char *argstr;
53 {
54 char *argv[2];
55 int argc, rc;
56
57 rc = parse_interactive_command_into_argv(argstr, argv, 1, 1, &argc);
58 if (rc < 0)
59 return;
60 tch_rx_control(1);
61 cmd_tchdl_common(argc, argv);
62 }
63
64 cmd_tchdl_oneshot(argc, argv)
65 char **argv;
66 {
67 return cmd_tchdl_common(argc - 1, argv + 1);
68 }
69
70 static void
71 tch_rawdump()
72 {
73 char buf[MAX_PKT_FROM_TARGET*3+5], *dp;
74 u_char *cp, *endp;
75
76 cp = rvi_msg + 2;
77 endp = rvi_msg + rvi_msg_len;
78 strcpy(buf, "TCH:");
79 dp = buf + 4;
80 while (cp < endp) {
81 sprintf(dp, " %02X", *cp++);
82 dp += 3;
83 }
84 *dp = '\0';
85 async_msg_output(buf);
86 }
87
88 void
89 tch_packet_rx()
90 {
91 char buf[128];
92
93 if (tch_rawdump_mode) {
94 tch_rawdump();
95 return;
96 }
97 if (rvi_msg_len < 3) {
98 inv: async_msg_output("Error: invalid TCH packet received");
99 return;
100 }
101 switch (rvi_msg[2]) {
102 case TCH_CONFIG_CONF:
103 if (rvi_msg_len != 4)
104 goto inv;
105 if (rvi_msg[3] & 0xFE)
106 goto inv;
107 sprintf(buf, "TCH_CONFIG_CONF: DL forwarding is %s",
108 rvi_msg[3] ? "enabled" : "disabled");
109 async_msg_output(buf);
110 return;
111 case TCH_ULBITS_CONF:
112 if (rvi_msg_len != 3)
113 goto inv;
114 tch_ulbits_conf();
115 return;
116 case TCH_DLBITS_IND:
117 if (rvi_msg_len != 43)
118 goto inv;
119 tch_dlbits_handler();
120 return;
121 default:
122 goto inv;
123 }
124 }
125
126 static void
127 cmd_tch_dumpraw(argc, argv)
128 char **argv;
129 {
130 if (argc < 2) {
131 printf("error: too few arguments\n");
132 return;
133 }
134 if (!strcmp(argv[1], "enable") || !strcmp(argv[1], "on") ||
135 !strcmp(argv[1], "1"))
136 tch_rawdump_mode = 1;
137 else if (!strcmp(argv[1], "disable") || !strcmp(argv[1], "off") ||
138 !strcmp(argv[1], "0"))
139 tch_rawdump_mode = 0;
140 else
141 printf("error: boolean argument required\n");
142 }
143
144 static void
145 cmd_tch_status(argc, argv)
146 char **argv;
147 {
148 if (argc > 1) {
149 printf("error: too many arguments\n");
150 return;
151 }
152 show_tch_record_status();
153 show_tch_play_status();
154 printf("TCH raw dump mode is %s\n",
155 tch_rawdump_mode ? "enabled" : "disabled");
156 }
157
158 void
159 cmd_tch_dispatch(argstr)
160 char *argstr;
161 {
162 char *argv[3];
163 int argc, rc;
164
165 rc = parse_interactive_command_into_argv(argstr, argv, 1, 2, &argc);
166 if (rc < 0)
167 return;
168 if (!strcmp(argv[0], "dump-raw")) {
169 cmd_tch_dumpraw(argc, argv);
170 return;
171 }
172 if (!strcmp(argv[0], "play")) {
173 cmd_tch_play(argc, argv);
174 return;
175 }
176 if (!strcmp(argv[0], "record")) {
177 cmd_tch_record(argc, argv);
178 return;
179 }
180 if (!strcmp(argv[0], "status")) {
181 cmd_tch_status(argc, argv);
182 return;
183 }
184 printf("error: invalid tch subcommand\n");
185 }