FreeCalypso > hg > freecalypso-sw
comparison rvinterf/lowlevel/format_g23.c @ 175:2f214bd03119
rvtdump: heuristic decoding of G23 traces implemented,
works with Pirelli's trace output
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Fri, 22 Nov 2013 20:16:00 +0000 |
parents | rvinterf/lowlevel/format.c@3256dc6e84ae |
children | 2f285f20d617 |
comparison
equal
deleted
inserted
replaced
174:3256dc6e84ae | 175:2f214bd03119 |
---|---|
1 /* | |
2 * This module implements the decoding of G23 trace packets into | |
3 * human-readable form. Because I have not yet reached the point | |
4 * of integrating the target-side code that generates these packets, | |
5 * I do not yet have the proper understanding of their format. | |
6 * Therefore, the current decoding logic implemented here is based | |
7 * on a heuristic examination of what the packets look like to an | |
8 * uninitiated eye. | |
9 */ | |
10 | |
11 #include <sys/types.h> | |
12 #include <stdio.h> | |
13 #include <string.h> | |
14 #include <strings.h> | |
15 #include "../pktmux.h" | |
16 #include "../limits.h" | |
17 | |
18 extern u_char rxpkt[]; | |
19 extern size_t rxpkt_len; | |
20 | |
21 static int | |
22 is_well_formed() | |
23 { | |
24 int i, c; | |
25 | |
26 if (rxpkt_len < 17) | |
27 return(0); | |
28 for (i = 8; i < 16; i++) { | |
29 c = rxpkt[i]; | |
30 if (c < ' ' || c > '~') | |
31 return(0); | |
32 } | |
33 return(1); | |
34 } | |
35 | |
36 static void | |
37 print_well_formed() | |
38 { | |
39 char buf[MAX_PKT_FROM_TARGET*4]; | |
40 int i, c; | |
41 char *dp; | |
42 | |
43 dp = buf; | |
44 strcpy(dp, "G23:"); | |
45 dp += 4; | |
46 for (i = 1; i <= 7; i++) { | |
47 sprintf(dp, " %02X", rxpkt[i]); | |
48 dp += 3; | |
49 } | |
50 sprintf(dp, " \"%.4s\" \"%.4s\" ", rxpkt+8, rxpkt+12); | |
51 dp += 15; | |
52 i = 16; | |
53 if (rxpkt[i] < 0x20) { | |
54 sprintf(dp, "%02X ", rxpkt[i]); | |
55 dp += 3; | |
56 i++; | |
57 } | |
58 if (rxpkt_len - i == 5 && rxpkt[i] == '%' && | |
59 !rxpkt[i+3] && !rxpkt[i+4]) { | |
60 sprintf(dp, "%d", rxpkt[i+2] << 8 | rxpkt[i+1]); | |
61 output_line(buf); | |
62 return; | |
63 } | |
64 *dp++ = '\"'; | |
65 for (; i < rxpkt_len; i++) { | |
66 c = rxpkt[i]; | |
67 if (c & 0x80) { | |
68 *dp++ = 'M'; | |
69 *dp++ = '-'; | |
70 c &= 0x7F; | |
71 } | |
72 if (c < 0x20) { | |
73 *dp++ = '^'; | |
74 *dp++ = c + '@'; | |
75 } else if (c == 0x7F) { | |
76 *dp++ = '^'; | |
77 *dp++ = '?'; | |
78 } else | |
79 *dp++ = c; | |
80 } | |
81 *dp++ = '\"'; | |
82 *dp = '\0'; | |
83 output_line(buf); | |
84 } | |
85 | |
86 static void | |
87 print_malformed() | |
88 { | |
89 char buf[MAX_PKT_FROM_TARGET*3+6]; | |
90 int i; | |
91 char *dp; | |
92 | |
93 dp = buf; | |
94 strcpy(dp, "G23 UNK:"); | |
95 dp += 8; | |
96 for (i = 1; i < rxpkt_len; i++) { | |
97 sprintf(dp, " %02X", rxpkt[i]); | |
98 dp += 3; | |
99 } | |
100 *dp = '\0'; | |
101 output_line(buf); | |
102 } | |
103 | |
104 void | |
105 print_g23_trace() | |
106 { | |
107 if (is_well_formed()) | |
108 print_well_formed(); | |
109 else | |
110 print_malformed(); | |
111 } |