annotate rvinterf/lowlevel/format_g23.c @ 306:81bee6125882

DAR integration: header cleanup
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 16 Mar 2014 06:50:26 +0000
parents 2f285f20d617
children 05874f1ddacb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
175
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
2 * This module implements the decoding of G23 trace packets into
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
3 * human-readable form. Because I have not yet reached the point
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
4 * of integrating the target-side code that generates these packets,
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
5 * I do not yet have the proper understanding of their format.
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
6 * Therefore, the current decoding logic implemented here is based
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
7 * on a heuristic examination of what the packets look like to an
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
8 * uninitiated eye.
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 */
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <sys/types.h>
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include <stdio.h>
133
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
13 #include <string.h>
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
14 #include <strings.h>
256
2f285f20d617 rvinterf: *.h moved into include subdir
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 175
diff changeset
15 #include "../include/pktmux.h"
2f285f20d617 rvinterf: *.h moved into include subdir
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 175
diff changeset
16 #include "../include/limits.h"
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 extern u_char rxpkt[];
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 extern size_t rxpkt_len;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20
175
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
21 static int
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
22 is_well_formed()
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
23 {
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
24 int i, c;
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
25
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
26 if (rxpkt_len < 17)
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
27 return(0);
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
28 for (i = 8; i < 16; i++) {
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
29 c = rxpkt[i];
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
30 if (c < ' ' || c > '~')
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
31 return(0);
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
32 }
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
33 return(1);
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
34 }
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
35
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
36 static void
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
37 print_well_formed()
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 {
174
3256dc6e84ae rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
39 char buf[MAX_PKT_FROM_TARGET*4];
133
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
40 int i, c;
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
41 char *dp;
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42
174
3256dc6e84ae rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
43 dp = buf;
175
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
44 strcpy(dp, "G23:");
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
45 dp += 4;
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
46 for (i = 1; i <= 7; i++) {
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
47 sprintf(dp, " %02X", rxpkt[i]);
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
48 dp += 3;
133
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
49 }
175
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
50 sprintf(dp, " \"%.4s\" \"%.4s\" ", rxpkt+8, rxpkt+12);
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
51 dp += 15;
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
52 i = 16;
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
53 if (rxpkt[i] < 0x20) {
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
54 sprintf(dp, "%02X ", rxpkt[i]);
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
55 dp += 3;
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
56 i++;
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
57 }
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
58 if (rxpkt_len - i == 5 && rxpkt[i] == '%' &&
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
59 !rxpkt[i+3] && !rxpkt[i+4]) {
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
60 sprintf(dp, "%d", rxpkt[i+2] << 8 | rxpkt[i+1]);
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
61 output_line(buf);
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
62 return;
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
63 }
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
64 *dp++ = '\"';
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
65 for (; i < rxpkt_len; i++) {
133
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
66 c = rxpkt[i];
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
67 if (c & 0x80) {
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
68 *dp++ = 'M';
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
69 *dp++ = '-';
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
70 c &= 0x7F;
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
71 }
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
72 if (c < 0x20) {
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
73 *dp++ = '^';
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
74 *dp++ = c + '@';
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
75 } else if (c == 0x7F) {
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
76 *dp++ = '^';
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
77 *dp++ = '?';
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
78 } else
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
79 *dp++ = c;
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
80 }
175
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
81 *dp++ = '\"';
133
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
82 *dp = '\0';
174
3256dc6e84ae rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
83 output_line(buf);
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 }
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85
175
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
86 static void
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
87 print_malformed()
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 {
175
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
89 char buf[MAX_PKT_FROM_TARGET*3+6];
127
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
90 int i;
133
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
91 char *dp;
127
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
92
174
3256dc6e84ae rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
93 dp = buf;
175
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
94 strcpy(dp, "G23 UNK:");
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
95 dp += 8;
133
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
96 for (i = 1; i < rxpkt_len; i++) {
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
97 sprintf(dp, " %02X", rxpkt[i]);
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
98 dp += 3;
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
99 }
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
100 *dp = '\0';
174
3256dc6e84ae rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
101 output_line(buf);
133
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
102 }
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
103
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
104 void
175
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
105 print_g23_trace()
169
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
106 {
175
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
107 if (is_well_formed())
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
108 print_well_formed();
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
109 else
2f214bd03119 rvtdump: heuristic decoding of G23 traces implemented,
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
110 print_malformed();
169
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
111 }