diff pircharge/pktsort.c @ 228:fec90990f613

pirchgdbg started
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 19 Dec 2017 02:58:38 +0000
parents
children 84a4f6ef2d28
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pircharge/pktsort.c	Tue Dec 19 02:58:38 2017 +0000
@@ -0,0 +1,94 @@
+/*
+ * Here we sort out incoming packets from the target relayed via rvinterf.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include <rvinterf/pktmux.h>
+#include <rvinterf/limits.h>
+#include <rvinterf/localsock.h>
+#include <rvinterf/localtypes.h>
+#include <rvinterf/etm.h>
+#include <rvinterf/exitcodes.h>
+
+extern u_char rvi_msg[];
+extern int rvi_msg_len;
+
+void
+print_rv_trace()
+{
+	char fmtbuf[MAX_PKT_FROM_TARGET*8];	/* size it generously */
+	int i, c;
+	char *dp;
+
+	dp = fmtbuf;
+	strcpy(dp, "RV ");
+	dp += 3;
+	/* the SWE static ID is sent MSB first */
+	for (i = 1; i <= 4; i++) {
+		sprintf(dp, "%02X", rvi_msg[i+1]);
+		dp += 2;
+	}
+	/* severity level */
+	sprintf(dp, " %d ", rvi_msg[6]);
+	dp = index(dp, '\0');
+	for (i = 7; i < rvi_msg_len; i++) {
+		c = rvi_msg[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';
+	printf("%s\n", fmtbuf);
+}
+
+void
+rvt_packet_rx()
+{
+	u32 useid;
+
+	if (rvi_msg_len < 7) {
+		fprintf(stderr, "Error: rvinterf sent us an invalid RVT msg\n");
+		exit(ERROR_RVINTERF);
+	}
+	print_rv_trace();
+	useid = rvi_msg[2] << 24 | rvi_msg[3] << 16 | rvi_msg[4] << 8
+		| rvi_msg[5];
+	if (useid != 0x000A0010)
+		return;
+	if (rvi_msg_len != 22)
+		return;
+	if (strncmp(rvi_msg + 7, "IQ EXT: ADC End", 15))
+		return;
+	/* ADC End handling will go here */
+}
+
+void
+process_pkt_from_target()
+{
+	switch (rvi_msg[1]) {
+	case RVT_RV_HEADER:
+		rvt_packet_rx();
+		return;
+	case RVT_TM_HEADER:
+		/* etm_packet_rx(); */
+		return;
+	default:
+		fprintf(stderr, "unexpected fwd of MUX %02X from rvinterf\n",
+			rvi_msg[1]);
+		exit(ERROR_RVINTERF);
+	}
+}