annotate rvinterf/trdump.c @ 127:f4f0c8738dcb

rvtdump: satisfactory handling of output from Pirelli's fw
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Thu, 31 Oct 2013 23:08:59 +0000
parents 811b138f1bed
children 56b53c289785
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 /*
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module implements the basic dump of any incoming packets
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdio.h>
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include "pktmux.h"
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 extern u_char rxpkt[];
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 extern size_t rxpkt_len;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 void
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 print_presumed_string(str, len)
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 u_char *str;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 size_t len;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 {
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 int i, c;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18
127
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
19 if (len >= 3 &&
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
20 (str[len-2] == '\r' && str[len-1] == '\n' ||
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
21 str[len-2] == '\n' && str[len-1] == '\r'))
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
22 len -= 2;
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 for (i = 0; i < len; i++) {
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 c = str[i];
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 if (c & 0x80) {
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 putchar('M');
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 putchar('-');
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 c &= 0x7F;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 }
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 if (c < 0x20) {
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 putchar('^');
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 putchar(c + '@');
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 } else if (c == 0x7F) {
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 putchar('^');
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 putchar('?');
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 } else
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 putchar(c);
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 }
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 }
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 void
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 print_rv_trace()
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 {
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 int i;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45
127
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
46 fputs("RV ", stdout);
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 /* the SWE static ID is sent MSB first */
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 for (i = 1; i <= 4; i++)
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 printf("%02X", rxpkt[i]);
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 /* severity level */
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 printf(" %d ", rxpkt[5]);
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 print_presumed_string(rxpkt + 6, rxpkt_len - 6);
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 putchar('\n');
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 }
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 void
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 print_l1_trace()
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 {
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 fputs("L1: ", stdout);
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 print_presumed_string(rxpkt + 1, rxpkt_len - 1);
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 putchar('\n');
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 }
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 void
127
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
65 print_g23_trace()
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
66 {
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
67 int i;
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
68
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
69 fputs("G23:", stdout);
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
70 for (i = 1; i < rxpkt_len; i++)
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
71 printf(" %02X", rxpkt[i]);
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
72 putchar('\n');
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
73 }
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
74
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
75 void
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 print_rx_packet()
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 {
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 int i;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 switch (rxpkt[0]) {
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 case RVT_RV_HEADER:
127
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
82 if (rxpkt_len < 6)
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
83 break;
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 print_rv_trace();
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 return;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 case RVT_L1_HEADER:
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 print_l1_trace();
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 return;
127
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
89 case RVT_L23_HEADER:
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
90 print_g23_trace();
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
91 return;
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 }
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 /* default case: print the whole packet in hex as an unknown */
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94 fputs("UNK:", stdout);
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 for (i = 0; i < rxpkt_len; i++)
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96 printf(" %02X", rxpkt[i]);
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97 putchar('\n');
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 }