annotate rvinterf/asyncshell/pktsort.c @ 1022:24440bc7cee8

gsm-fw/configs: gtamodem-gsmtch-{ext,int} configurations added
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Tue, 03 May 2016 13:43:31 +0000
parents 820d34f3f3d7
children f511bbac0efa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
872
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
2 * Here we sort out incoming packets from the target relayed via rvinterf.
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
3 */
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
4
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdio.h>
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <string.h>
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <strings.h>
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <stdlib.h>
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
10 #include "pktmux.h"
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
11 #include "limits.h"
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "localsock.h"
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
13 #include "localtypes.h"
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
14
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
15 extern u_char rvi_msg[];
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
16 extern int rvi_msg_len;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
17
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
18 static void
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
19 process_rvt()
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
20 {
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
21 u32 useid;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
22
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
23 if (rvi_msg_len < 7) {
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
24 tty_cleanup();
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
25 fprintf(stderr, "Error: rvinterf sent us an invalid RVT msg\n");
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
26 exit(1);
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
27 }
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
28 useid = rvi_msg[2] << 24 | rvi_msg[3] << 16 | rvi_msg[4] << 8
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
29 | rvi_msg[5];
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
30 switch (useid) {
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
31 case 0:
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
32 handle_useid_0();
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
33 return;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
34 default:
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
35 tty_cleanup();
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
36 fprintf(stderr, "unexpected fwd of USEID %08X from rvinterf\n",
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
37 useid);
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
38 exit(1);
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
39 }
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
40 }
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
41
1011
820d34f3f3d7 fc-shell: added ability to receive and dump TCH packets
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 879
diff changeset
42 static void
872
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
43 gpf_packet_rx()
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
44 {
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
45 char fmtbuf[MAX_PKT_FROM_TARGET*8]; /* size it generously */
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
46
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
47 format_g23_packet(rvi_msg + 1, rvi_msg_len - 1, fmtbuf);
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
48 async_msg_output(fmtbuf);
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
49 }
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
50
1011
820d34f3f3d7 fc-shell: added ability to receive and dump TCH packets
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 879
diff changeset
51 static void
872
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
52 response_from_ati()
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
53 {
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
54 char buf[MAX_PKT_FROM_TARGET*4+2];
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
55
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
56 strcpy(buf, "ATI: ");
879
4661b84260a0 fc-shell: AT-over-RVTMUX command sending implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 872
diff changeset
57 safe_print_trace(rvi_msg + 2, rvi_msg_len - 2, buf + 5);
872
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
58 async_msg_output(buf);
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
59 }
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
60
1011
820d34f3f3d7 fc-shell: added ability to receive and dump TCH packets
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 879
diff changeset
61 static void
820d34f3f3d7 fc-shell: added ability to receive and dump TCH packets
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 879
diff changeset
62 dump_tch()
820d34f3f3d7 fc-shell: added ability to receive and dump TCH packets
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 879
diff changeset
63 {
820d34f3f3d7 fc-shell: added ability to receive and dump TCH packets
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 879
diff changeset
64 char buf[MAX_PKT_FROM_TARGET*3+5], *dp;
820d34f3f3d7 fc-shell: added ability to receive and dump TCH packets
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 879
diff changeset
65 u_char *cp, *endp;
820d34f3f3d7 fc-shell: added ability to receive and dump TCH packets
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 879
diff changeset
66
820d34f3f3d7 fc-shell: added ability to receive and dump TCH packets
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 879
diff changeset
67 cp = rvi_msg + 2;
820d34f3f3d7 fc-shell: added ability to receive and dump TCH packets
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 879
diff changeset
68 endp = rvi_msg + rvi_msg_len;
820d34f3f3d7 fc-shell: added ability to receive and dump TCH packets
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 879
diff changeset
69 strcpy(buf, "TCH:");
820d34f3f3d7 fc-shell: added ability to receive and dump TCH packets
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 879
diff changeset
70 dp = buf + 4;
820d34f3f3d7 fc-shell: added ability to receive and dump TCH packets
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 879
diff changeset
71 while (cp < endp) {
820d34f3f3d7 fc-shell: added ability to receive and dump TCH packets
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 879
diff changeset
72 sprintf(dp, " %02X", *cp++);
820d34f3f3d7 fc-shell: added ability to receive and dump TCH packets
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 879
diff changeset
73 dp += 3;
820d34f3f3d7 fc-shell: added ability to receive and dump TCH packets
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 879
diff changeset
74 }
820d34f3f3d7 fc-shell: added ability to receive and dump TCH packets
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 879
diff changeset
75 *dp = '\0';
820d34f3f3d7 fc-shell: added ability to receive and dump TCH packets
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 879
diff changeset
76 async_msg_output(buf);
820d34f3f3d7 fc-shell: added ability to receive and dump TCH packets
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 879
diff changeset
77 }
820d34f3f3d7 fc-shell: added ability to receive and dump TCH packets
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 879
diff changeset
78
872
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
79 void
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
80 process_pkt_from_target()
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
81 {
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
82 switch (rvi_msg[1]) {
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
83 case RVT_RV_HEADER:
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
84 process_rvt();
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
85 return;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
86 case RVT_L23_HEADER:
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
87 gpf_packet_rx();
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
88 return;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
89 case RVT_AT_HEADER:
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
90 response_from_ati();
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
91 return;
1011
820d34f3f3d7 fc-shell: added ability to receive and dump TCH packets
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 879
diff changeset
92 case RVT_TCH_HEADER:
820d34f3f3d7 fc-shell: added ability to receive and dump TCH packets
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 879
diff changeset
93 dump_tch();
820d34f3f3d7 fc-shell: added ability to receive and dump TCH packets
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 879
diff changeset
94 return;
872
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
95 default:
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
96 tty_cleanup();
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
97 fprintf(stderr, "unexpected fwd of MUX %02X from rvinterf\n",
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
98 rvi_msg[1]);
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
99 exit(1);
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
100 }
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
101 }