view rvinterf/etm/etmbasic.c @ 184:4714fdfca39c

fc-tmsh compiles!
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 24 Nov 2013 08:40:44 +0000
parents 85222710dc92
children 9f4f331ac24d
line wrap: on
line source

/*
 * Basic ETM interaction
 */

#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include "../pktmux.h"
#include "../limits.h"

extern u_char rvi_msg[];
extern int rvi_msg_len;

void
etm_packet_rx()
{
	char buf[MAX_PKT_FROM_TARGET*3+80], *dp;
	int i, c;

	if (rvi_msg_len < 4) {
		async_msg_output("!!! Short ETM Rx packet !!!");
		return;
	}
	strcpy(buf, "Pkt from ETM:");
	dp = index(buf, '\0');
	c = 0;
	for (i = 2; i < rvi_msg_len; i++) {
		sprintf(dp, " %02X", rvi_msg[i]);
		dp += 3;
		c ^= rvi_msg[i];
	}
	sprintf(dp, " chksum %s", c ? "BAD" : "OK");
	async_msg_output(buf);
}

void
cmd_etmpkt(argc, argv)
	char **argv;
{
	u_char pkt[MAX_PKT_TO_TARGET];
	int di, c, b;
	char **ap;

	pkt[0] = RVT_TM_HEADER;
	di = 1;
	c = 0;
	for (ap = argv + 1; *ap; ap++) {
		b = strtoul(*ap, 0, 16);
		pkt[di++] = b;
		c ^= b;
	}
	pkt[di++] = c;
	send_pkt_to_target(pkt, di);
}