comparison rvinterf/tmsh/pktsort.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 21a79f465d6a
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
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 static void
20 print_etm_trace()
21 {
22 char buf[MAX_PKT_FROM_TARGET*4];
23
24 strcpy(buf, "ETM Tr: ");
25 safe_print_trace(rvi_msg + 7, rvi_msg_len - 7, buf + 8);
26 async_msg_output(buf);
27 }
28
29 static void
30 process_rvt()
31 {
32 u32 useid;
33
34 if (rvi_msg_len < 7) {
35 tty_cleanup();
36 fprintf(stderr, "Error: rvinterf sent us an invalid RVT msg\n");
37 exit(1);
38 }
39 useid = rvi_msg[2] << 24 | rvi_msg[3] << 16 | rvi_msg[4] << 8
40 | rvi_msg[5];
41 switch (useid) {
42 case 0:
43 handle_useid_0();
44 return;
45 case ETM_USE_ID:
46 print_etm_trace();
47 return;
48 default:
49 tty_cleanup();
50 fprintf(stderr, "unexpected fwd of USEID %08X from rvinterf\n",
51 useid);
52 exit(1);
53 }
54 }
55
56 void
57 process_pkt_from_target()
58 {
59 switch (rvi_msg[1]) {
60 case RVT_RV_HEADER:
61 process_rvt();
62 return;
63 case RVT_TM_HEADER:
64 etm_packet_rx();
65 return;
66 default:
67 tty_cleanup();
68 fprintf(stderr, "unexpected fwd of MUX %02X from rvinterf\n",
69 rvi_msg[1]);
70 exit(1);
71 }
72 }