228
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /*
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * Here we sort out incoming packets from the target relayed via rvinterf.
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <string.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <strings.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <rvinterf/pktmux.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <rvinterf/limits.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <rvinterf/localsock.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <rvinterf/localtypes.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <rvinterf/etm.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include <rvinterf/exitcodes.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 extern u_char rvi_msg[];
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 extern int rvi_msg_len;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 void
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 print_rv_trace()
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 char fmtbuf[MAX_PKT_FROM_TARGET*8]; /* size it generously */
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 int i, c;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 char *dp;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 dp = fmtbuf;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 strcpy(dp, "RV ");
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 dp += 3;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 /* the SWE static ID is sent MSB first */
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 for (i = 1; i <= 4; i++) {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 sprintf(dp, "%02X", rvi_msg[i+1]);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 dp += 2;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 }
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 /* severity level */
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 sprintf(dp, " %d ", rvi_msg[6]);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 dp = index(dp, '\0');
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 for (i = 7; i < rvi_msg_len; i++) {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 c = rvi_msg[i];
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 if (c & 0x80) {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 *dp++ = 'M';
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 *dp++ = '-';
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 c &= 0x7F;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 }
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (c < 0x20) {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 *dp++ = '^';
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 *dp++ = c + '@';
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } else if (c == 0x7F) {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 *dp++ = '^';
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 *dp++ = '?';
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 } else
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 *dp++ = c;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 }
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 *dp = '\0';
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 printf("%s\n", fmtbuf);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 }
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 void
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 rvt_packet_rx()
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 u32 useid;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 if (rvi_msg_len < 7) {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 fprintf(stderr, "Error: rvinterf sent us an invalid RVT msg\n");
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 exit(ERROR_RVINTERF);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 }
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 print_rv_trace();
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 useid = rvi_msg[2] << 24 | rvi_msg[3] << 16 | rvi_msg[4] << 8
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 | rvi_msg[5];
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 if (useid != 0x000A0010)
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 return;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 if (rvi_msg_len != 22)
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 return;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 if (strncmp(rvi_msg + 7, "IQ EXT: ADC End", 15))
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 return;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 /* ADC End handling will go here */
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 }
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 void
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 process_pkt_from_target()
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 switch (rvi_msg[1]) {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 case RVT_RV_HEADER:
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 rvt_packet_rx();
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 return;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 case RVT_TM_HEADER:
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 /* etm_packet_rx(); */
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 return;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 default:
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 fprintf(stderr, "unexpected fwd of MUX %02X from rvinterf\n",
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 rvi_msg[1]);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 exit(ERROR_RVINTERF);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 }
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 }
|