comparison rvinterf/tmsh/pktsort.c @ 260:c146f38d2b5f

rvinterf subdir structure made a little more sensible
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Wed, 05 Feb 2014 04:02:13 +0000
parents rvinterf/etm/pktsort.c@2f285f20d617
children 40b8557b9d04
comparison
equal deleted inserted replaced
259:35113b1964d3 260:c146f38d2b5f
1 /*
2 * Here we sort out incoming packets from the target relayed via rvinterf.
3 */
4
5 #include <sys/types.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <strings.h>
9 #include <stdlib.h>
10 #include "pktmux.h"
11 #include "limits.h"
12 #include "localsock.h"
13 #include "localtypes.h"
14 #include "etm.h"
15
16 extern u_char rvi_msg[];
17 extern int rvi_msg_len;
18
19 void
20 safe_print_trace(src, srclen, dest)
21 u_char *src;
22 char *dest;
23 {
24 int i, c;
25 char *dp;
26
27 dp = dest;
28 for (i = 0; i < srclen; i++) {
29 c = src[i];
30 if (c & 0x80) {
31 *dp++ = 'M';
32 *dp++ = '-';
33 c &= 0x7F;
34 }
35 if (c < 0x20) {
36 *dp++ = '^';
37 *dp++ = c + '@';
38 } else if (c == 0x7F) {
39 *dp++ = '^';
40 *dp++ = '?';
41 } else
42 *dp++ = c;
43 }
44 *dp = '\0';
45 }
46
47 static void
48 handle_useid_0()
49 {
50 char buf[MAX_PKT_FROM_TARGET*4];
51
52 if (strncmp(rvi_msg + 7, "RVT: Lost Message", 17))
53 return;
54 safe_print_trace(rvi_msg + 7, rvi_msg_len - 7, buf);
55 async_msg_output(buf);
56 }
57
58 static void
59 print_etm_trace()
60 {
61 char buf[MAX_PKT_FROM_TARGET*4];
62
63 strcpy(buf, "ETM Tr: ");
64 safe_print_trace(rvi_msg + 7, rvi_msg_len - 7, buf + 9);
65 async_msg_output(buf);
66 }
67
68 static void
69 process_rvt()
70 {
71 u32 useid;
72
73 if (rvi_msg_len < 7) {
74 tty_cleanup();
75 fprintf(stderr, "Error: rvinterf sent us an invalid RVT msg\n");
76 exit(1);
77 }
78 useid = rvi_msg[2] << 24 | rvi_msg[3] << 16 | rvi_msg[4] << 8
79 | rvi_msg[5];
80 switch (useid) {
81 case 0:
82 handle_useid_0();
83 return;
84 case ETM_USE_ID:
85 print_etm_trace();
86 return;
87 default:
88 tty_cleanup();
89 fprintf(stderr, "unexpected fwd of USEID %08X from rvinterf\n",
90 useid);
91 exit(1);
92 }
93 }
94
95 void
96 process_pkt_from_target()
97 {
98 switch (rvi_msg[1]) {
99 case RVT_RV_HEADER:
100 process_rvt();
101 return;
102 case RVT_TM_HEADER:
103 etm_packet_rx();
104 return;
105 default:
106 tty_cleanup();
107 fprintf(stderr, "unexpected fwd of MUX %02X from rvinterf\n",
108 rvi_msg[1]);
109 exit(1);
110 }
111 }