changeset 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 3256dc6e84ae
children 7f727aaf5cd4
files rvinterf/lowlevel/Makefile rvinterf/lowlevel/format.c rvinterf/lowlevel/format_g23.c
diffstat 3 files changed, 112 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/lowlevel/Makefile	Fri Nov 22 07:41:31 2013 +0000
+++ b/rvinterf/lowlevel/Makefile	Fri Nov 22 20:16:00 2013 +0000
@@ -3,7 +3,7 @@
 PROGS=	rvtdump
 INSTBIN=/usr/local/bin
 
-RVTDUMP_OBJS=	format.o openport.o output.o packetrx.o rvtdump.o
+RVTDUMP_OBJS=	format.o format_g23.o openport.o output.o packetrx.o rvtdump.o
 
 all:	${PROGS}
 
--- a/rvinterf/lowlevel/format.c	Fri Nov 22 07:41:31 2013 +0000
+++ b/rvinterf/lowlevel/format.c	Fri Nov 22 20:16:00 2013 +0000
@@ -96,24 +96,6 @@
 }
 
 void
-print_g23_trace()
-{
-	char buf[MAX_PKT_FROM_TARGET*3+2];
-	int i;
-	char *dp;
-
-	dp = buf;
-	strcpy(dp, "G23:");
-	dp += 4;
-	for (i = 1; i < rxpkt_len; i++) {
-		sprintf(dp, " %02X", rxpkt[i]);
-		dp += 3;
-	}
-	*dp = '\0';
-	output_line(buf);
-}
-
-void
 print_etm_output_raw()
 {
 	char buf[MAX_PKT_FROM_TARGET*3+2];
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/lowlevel/format_g23.c	Fri Nov 22 20:16:00 2013 +0000
@@ -0,0 +1,111 @@
+/*
+ * This module implements the decoding of G23 trace packets into
+ * human-readable form.  Because I have not yet reached the point
+ * of integrating the target-side code that generates these packets,
+ * I do not yet have the proper understanding of their format.
+ * Therefore, the current decoding logic implemented here is based
+ * on a heuristic examination of what the packets look like to an
+ * uninitiated eye.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include "../pktmux.h"
+#include "../limits.h"
+
+extern u_char rxpkt[];
+extern size_t rxpkt_len;
+
+static int
+is_well_formed()
+{
+	int i, c;
+
+	if (rxpkt_len < 17)
+		return(0);
+	for (i = 8; i < 16; i++) {
+		c = rxpkt[i];
+		if (c < ' ' || c > '~')
+			return(0);
+	}
+	return(1);
+}
+
+static void
+print_well_formed()
+{
+	char buf[MAX_PKT_FROM_TARGET*4];
+	int i, c;
+	char *dp;
+
+	dp = buf;
+	strcpy(dp, "G23:");
+	dp += 4;
+	for (i = 1; i <= 7; i++) {
+		sprintf(dp, " %02X", rxpkt[i]);
+		dp += 3;
+	}
+	sprintf(dp, " \"%.4s\" \"%.4s\" ", rxpkt+8, rxpkt+12);
+	dp += 15;
+	i = 16;
+	if (rxpkt[i] < 0x20) {
+		sprintf(dp, "%02X ", rxpkt[i]);
+		dp += 3;
+		i++;
+	}
+	if (rxpkt_len - i == 5 && rxpkt[i] == '%' &&
+	    !rxpkt[i+3] && !rxpkt[i+4]) {
+		sprintf(dp, "%d", rxpkt[i+2] << 8 | rxpkt[i+1]);
+		output_line(buf);
+		return;
+	}
+	*dp++ = '\"';
+	for (; 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++ = '\"';
+	*dp = '\0';
+	output_line(buf);
+}
+
+static void
+print_malformed()
+{
+	char buf[MAX_PKT_FROM_TARGET*3+6];
+	int i;
+	char *dp;
+
+	dp = buf;
+	strcpy(dp, "G23 UNK:");
+	dp += 8;
+	for (i = 1; i < rxpkt_len; i++) {
+		sprintf(dp, " %02X", rxpkt[i]);
+		dp += 3;
+	}
+	*dp = '\0';
+	output_line(buf);
+}
+
+void
+print_g23_trace()
+{
+	if (is_well_formed())
+		print_well_formed();
+	else
+		print_malformed();
+}