comparison rvinterf/old/trdump.c @ 173:f42854da4563

rvinterf: beginning of refactoring
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 22 Nov 2013 05:56:07 +0000
parents rvinterf/trdump.c@e01e3a60c858
children
comparison
equal deleted inserted replaced
172:019120585a1c 173:f42854da4563
1 /*
2 * This module implements the basic dump of any incoming packets
3 */
4
5 #include <sys/types.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <strings.h>
9 #include "pktmux.h"
10
11 extern u_char rxpkt[];
12 extern size_t rxpkt_len;
13
14 char pr_item[4096];
15
16 void
17 print_rv_trace()
18 {
19 int i, c;
20 char *dp;
21
22 dp = pr_item;
23 strcpy(dp, "RV ");
24 dp += 3;
25 /* the SWE static ID is sent MSB first */
26 for (i = 1; i <= 4; i++) {
27 sprintf(dp, "%02X", rxpkt[i]);
28 dp += 2;
29 }
30 /* severity level */
31 sprintf(dp, " %d ", rxpkt[5]);
32 dp = index(dp, '\0');
33 for (i = 6; i < rxpkt_len; i++) {
34 c = rxpkt[i];
35 if (c & 0x80) {
36 *dp++ = 'M';
37 *dp++ = '-';
38 c &= 0x7F;
39 }
40 if (c < 0x20) {
41 *dp++ = '^';
42 *dp++ = c + '@';
43 } else if (c == 0x7F) {
44 *dp++ = '^';
45 *dp++ = '?';
46 } else
47 *dp++ = c;
48 }
49 *dp = '\0';
50 print_item();
51 }
52
53 void
54 print_l1_trace()
55 {
56 int i, c;
57 char *dp;
58
59 dp = pr_item;
60 strcpy(dp, "L1: ");
61 dp += 4;
62 for (i = 1; i < rxpkt_len; i++) {
63 if ((i+1 < rxpkt_len) &&
64 (rxpkt[i] == '\r' && rxpkt[i+1] == '\n' ||
65 rxpkt[i] == '\n' && rxpkt[i+1] == '\r')) {
66 *dp = '\0';
67 print_item();
68 if (i+2 == rxpkt_len)
69 return;
70 dp = pr_item;
71 *dp++ = '+';
72 *dp++ = ' ';
73 i++;
74 continue;
75 }
76 c = rxpkt[i];
77 if (c & 0x80) {
78 *dp++ = 'M';
79 *dp++ = '-';
80 c &= 0x7F;
81 }
82 if (c < 0x20) {
83 *dp++ = '^';
84 *dp++ = c + '@';
85 } else if (c == 0x7F) {
86 *dp++ = '^';
87 *dp++ = '?';
88 } else
89 *dp++ = c;
90 }
91 /* will get here only if no newline sequence at the end */
92 *dp = '\0';
93 print_item();
94 }
95
96 void
97 print_g23_trace()
98 {
99 int i;
100 char *dp;
101
102 dp = pr_item;
103 strcpy(dp, "G23:");
104 dp += 4;
105 for (i = 1; i < rxpkt_len; i++) {
106 sprintf(dp, " %02X", rxpkt[i]);
107 dp += 3;
108 }
109 *dp = '\0';
110 print_item();
111 }
112
113 void
114 print_etm_output_raw()
115 {
116 int i;
117 char *dp;
118
119 dp = pr_item;
120 strcpy(dp, "ETM:");
121 dp += 4;
122 for (i = 1; i < rxpkt_len; i++) {
123 sprintf(dp, " %02X", rxpkt[i]);
124 dp += 3;
125 }
126 *dp = '\0';
127 print_item();
128 }
129
130 void
131 print_unknown_packet()
132 {
133 int i;
134 char *dp;
135
136 dp = pr_item;
137 strcpy(dp, "UNK:");
138 dp += 4;
139 for (i = 0; i < rxpkt_len; i++) {
140 sprintf(dp, " %02X", rxpkt[i]);
141 dp += 3;
142 }
143 *dp = '\0';
144 print_item();
145 }
146
147 void
148 print_rx_packet()
149 {
150 switch (rxpkt[0]) {
151 case RVT_RV_HEADER:
152 if (rxpkt_len < 6)
153 goto unknown;
154 print_rv_trace();
155 return;
156 case RVT_L1_HEADER:
157 print_l1_trace();
158 return;
159 case RVT_L23_HEADER:
160 print_g23_trace();
161 return;
162 case RVT_TM_HEADER:
163 print_etm_output_raw();
164 return;
165 default:
166 unknown:
167 print_unknown_packet();
168 }
169 }