diff rvinterf/old/before-rvinterf/trdump.c @ 964:373af5f74e39

rvinterf: all retired stuff gathered under old
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Fri, 06 Nov 2015 23:22:47 +0000
parents rvinterf/old/trdump.c@f42854da4563
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/old/before-rvinterf/trdump.c	Fri Nov 06 23:22:47 2015 +0000
@@ -0,0 +1,169 @@
+/*
+ * This module implements the basic dump of any incoming packets
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include "pktmux.h"
+
+extern u_char rxpkt[];
+extern size_t rxpkt_len;
+
+char pr_item[4096];
+
+void
+print_rv_trace()
+{
+	int i, c;
+	char *dp;
+
+	dp = pr_item;
+	strcpy(dp, "RV ");
+	dp += 3;
+	/* the SWE static ID is sent MSB first */
+	for (i = 1; i <= 4; i++) {
+		sprintf(dp, "%02X", rxpkt[i]);
+		dp += 2;
+	}
+	/* severity level */
+	sprintf(dp, " %d ", rxpkt[5]);
+	dp = index(dp, '\0');
+	for (i = 6; i < rxpkt_len; i++) {
+		c = rxpkt[i];
+		if (c & 0x80) {
+			*dp++ = 'M';
+			*dp++ = '-';
+			c &= 0x7F;
+		}
+		if (c < 0x20) {
+			*dp++ = '^';
+			*dp++ = c + '@';
+		} else if (c == 0x7F) {
+			*dp++ = '^';
+			*dp++ = '?';
+		} else
+			*dp++ = c;
+	}
+	*dp = '\0';
+	print_item();
+}
+
+void
+print_l1_trace()
+{
+	int i, c;
+	char *dp;
+
+	dp = pr_item;
+	strcpy(dp, "L1: ");
+	dp += 4;
+	for (i = 1; i < rxpkt_len; i++) {
+		if ((i+1 < rxpkt_len) &&
+		    (rxpkt[i] == '\r' && rxpkt[i+1] == '\n' ||
+		     rxpkt[i] == '\n' && rxpkt[i+1] == '\r')) {
+			*dp = '\0';
+			print_item();
+			if (i+2 == rxpkt_len)
+				return;
+			dp = pr_item;
+			*dp++ = '+';
+			*dp++ = ' ';
+			i++;
+			continue;
+		}
+		c = rxpkt[i];
+		if (c & 0x80) {
+			*dp++ = 'M';
+			*dp++ = '-';
+			c &= 0x7F;
+		}
+		if (c < 0x20) {
+			*dp++ = '^';
+			*dp++ = c + '@';
+		} else if (c == 0x7F) {
+			*dp++ = '^';
+			*dp++ = '?';
+		} else
+			*dp++ = c;
+	}
+	/* will get here only if no newline sequence at the end */
+	*dp = '\0';
+	print_item();
+}
+
+void
+print_g23_trace()
+{
+	int i;
+	char *dp;
+
+	dp = pr_item;
+	strcpy(dp, "G23:");
+	dp += 4;
+	for (i = 1; i < rxpkt_len; i++) {
+		sprintf(dp, " %02X", rxpkt[i]);
+		dp += 3;
+	}
+	*dp = '\0';
+	print_item();
+}
+
+void
+print_etm_output_raw()
+{
+	int i;
+	char *dp;
+
+	dp = pr_item;
+	strcpy(dp, "ETM:");
+	dp += 4;
+	for (i = 1; i < rxpkt_len; i++) {
+		sprintf(dp, " %02X", rxpkt[i]);
+		dp += 3;
+	}
+	*dp = '\0';
+	print_item();
+}
+
+void
+print_unknown_packet()
+{
+	int i;
+	char *dp;
+
+	dp = pr_item;
+	strcpy(dp, "UNK:");
+	dp += 4;
+	for (i = 0; i < rxpkt_len; i++) {
+		sprintf(dp, " %02X", rxpkt[i]);
+		dp += 3;
+	}
+	*dp = '\0';
+	print_item();
+}
+
+void
+print_rx_packet()
+{
+	switch (rxpkt[0]) {
+	case RVT_RV_HEADER:
+		if (rxpkt_len < 6)
+			goto unknown;
+		print_rv_trace();
+		return;
+	case RVT_L1_HEADER:
+		print_l1_trace();
+		return;
+	case RVT_L23_HEADER:
+		print_g23_trace();
+		return;
+	case RVT_TM_HEADER:
+		print_etm_output_raw();
+		return;
+	default:
+	unknown:
+		print_unknown_packet();
+	}
+}