FreeCalypso > hg > freecalypso-sw
annotate rvinterf/etm/etmbasic.c @ 188:9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Mon, 25 Nov 2013 02:11:47 +0000 |
parents | 4714fdfca39c |
children | a95d253ef952 |
rev | line source |
---|---|
183
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * Basic ETM interaction |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <sys/types.h> |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <stdio.h> |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <string.h> |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <strings.h> |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <stdlib.h> |
184
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
10 #include "../pktmux.h" |
183
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include "../limits.h" |
188
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
12 #include "etm.h" |
183
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 extern u_char rvi_msg[]; |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 extern int rvi_msg_len; |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 void |
188
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
18 print_etm_pkt_raw(err) |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
19 char *err; |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
20 { |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
21 char buf[MAX_PKT_FROM_TARGET*3+80], *dp; |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
22 int i; |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
23 |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
24 sprintf(buf, "%s:", err); |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
25 dp = index(buf, '\0'); |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
26 for (i = 2; i < rvi_msg_len; i++) { |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
27 sprintf(dp, " %02X", rvi_msg[i]); |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
28 dp += 3; |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
29 } |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
30 async_msg_output(buf); |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
31 } |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
32 |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
33 void |
183
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 etm_packet_rx() |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 { |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 int i, c; |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 if (rvi_msg_len < 4) { |
188
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
39 runt: print_etm_pkt_raw("ETM Runt"); |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
40 return; |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
41 } |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
42 c = 0; |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
43 for (i = 2; i < rvi_msg_len; i++) |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
44 c ^= rvi_msg[i]; |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
45 if (c) { |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
46 print_etm_pkt_raw("BAD CKSUM"); |
183
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 return; |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 } |
188
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
49 switch (rvi_msg[2]) { |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
50 case ETM_CORE: |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
51 if (rvi_msg_len < 6) |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
52 goto runt; |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
53 tmcore_msg_rx(); |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
54 return; |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
55 default: |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
56 print_etm_pkt_raw("ETM Unknown"); |
183
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 } |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 } |
184
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
59 |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
60 void |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
61 cmd_etmpkt(argc, argv) |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
62 char **argv; |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
63 { |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
64 u_char pkt[MAX_PKT_TO_TARGET]; |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
65 int di, c, b; |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
66 char **ap; |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
67 |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
68 pkt[0] = RVT_TM_HEADER; |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
69 di = 1; |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
70 c = 0; |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
71 for (ap = argv + 1; *ap; ap++) { |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
72 b = strtoul(*ap, 0, 16); |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
73 pkt[di++] = b; |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
74 c ^= b; |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
75 } |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
76 pkt[di++] = c; |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
77 send_pkt_to_target(pkt, di); |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
78 } |