view rvinterf/tmsh/etmbasic.c @ 465:003e48f8ebe1

rvinterf/etmsync/fsnew.c: cast 0 to (char *) for execl sentinel I generally don't use NULL and use plain 0 instead, based on a "NULL considered harmful" discussion on the classiccmp mailing list many aeons ago (I couldn't find it, and I reason that it must have been 2005 or earlier), but a recent complaint by a packager sent me searching, and I found this: https://ewontfix.com/11/ While I don't give a @#$% about "modern" systems and code-nazi tools, I realized that passing a plain 0 as a pointer sentinel in execl is wrong because it will break on systems where pointers are longer than the plain int type. Again, I don't give a @#$% about the abomination of x86_64 and the like, but if anyone ever manages to port my code to something like a PDP-11 (16-bit int, 32-bit long and pointers), then passing a plain 0 as a function argument where a pointer is expected most definitely won't work: if the most natural stack slot and SP alignment unit is 16 bits, fitting an int, with longs and pointers taking up two such slots, then the call stack will be totally wrong with a plain 0 passed for a pointer. Casting the 0 to (char *) ought to be the most kosher solution for the most retro systems possible.
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 11 Feb 2019 00:00:19 +0000
parents 8fac4aaec230
children 9706832b740b
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"
#include "etm.h"
#include "tm3.h"
#include "exitcodes.h"

extern u_char rvi_msg[];
extern int rvi_msg_len;

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

	sprintf(buf, "%s:", err);
	dp = index(buf, '\0');
	for (i = 2; i < rvi_msg_len; i++) {
		sprintf(dp, " %02X", rvi_msg[i]);
		dp += 3;
	}
	async_msg_output(buf);
}

void
etm_packet_rx()
{
	int i, c;

	if (rvi_msg_len < 4) {
runt:		print_etm_pkt_raw("TM runt");
		return;
	}
	c = 0;
	for (i = 2; i < rvi_msg_len; i++)
		c ^= rvi_msg[i];
	if (c) {
		print_etm_pkt_raw("BAD CKSUM");
		return;
	}
	switch (rvi_msg[2]) {
	case ETM_CORE:
		if (rvi_msg_len < 6)
			goto runt;
		tmcore_msg_rx();
		return;
	case ETM_FFS1:
		print_etm_pkt_raw("FFS1");
		return;
	case ETM_FFS2:
		if (rvi_msg_len < 5)
			goto runt;
		handle_ffs2_response();
		return;
	case ETM_AUDIO:
		if (rvi_msg_len < 6)
			goto runt;
		etm_audio_msg_rx();
		return;
	/* TM3 */
	case MEM_READ:
		if (rvi_msg_len < 5)
			goto runt;
		handle_omr_response();
		return;
	case MEM_WRITE:
		l1tm_response_nodata("omw");
		return;
	case CODEC_READ:
		if (rvi_msg_len < 5)
			goto runt;
		handle_oabbr_response();
		return;
	case CODEC_WRITE:
		l1tm_response_nodata("oabbw");
		return;
	/* L1TM */
	case TM_INIT:
		l1tm_response_nodata("tminit");
		return;
	case TM_MODE_SET:
		l1tm_response_nodata("tms");
		return;
	case VERSION_GET:
		if (rvi_msg_len < 5)
			goto runt;
		l1tm_response_index_val("tm3ver");
		return;
	case RF_ENABLE:
		l1tm_rfe_response();
		return;
	case STATS_READ:
		l1tm_stats_response();
		return;
	case STATS_CONFIG_WRITE:
		if (rvi_msg_len < 5)
			goto runt;
		l1tm_response_index("scw");
		return;
	case STATS_CONFIG_READ:
		if (rvi_msg_len < 5)
			goto runt;
		l1tm_response_index_val("scr");
		return;
	case RF_PARAM_WRITE:
		if (rvi_msg_len < 5)
			goto runt;
		l1tm_response_index("rfpw");
		return;
	case RF_PARAM_READ:
		if (rvi_msg_len < 5)
			goto runt;
		l1tm_response_index_val("rfpr");
		return;
	case RF_TABLE_WRITE:
		if (rvi_msg_len < 5)
			goto runt;
		l1tm_response_index("rftw");
		return;
	case RF_TABLE_READ:
		if (rvi_msg_len < 5)
			goto runt;
		l1tm_rftr_response();
		return;
	case RX_PARAM_WRITE:
		if (rvi_msg_len < 5)
			goto runt;
		l1tm_response_index("rxpw");
		return;
	case RX_PARAM_READ:
		if (rvi_msg_len < 5)
			goto runt;
		l1tm_response_index_val("rxpr");
		return;
	case TX_PARAM_WRITE:
		if (rvi_msg_len < 5)
			goto runt;
		l1tm_response_index("txpw");
		return;
	case TX_PARAM_READ:
		if (rvi_msg_len < 5)
			goto runt;
		l1tm_response_index_val("txpr");
		return;
	case TX_TEMPLATE_WRITE:
		if (rvi_msg_len < 5)
			goto runt;
		l1tm_ttw_response();
		return;
	case TX_TEMPLATE_READ:
		if (rvi_msg_len < 5)
			goto runt;
		l1tm_ttr_response();
		return;
	case MISC_PARAM_WRITE:
		if (rvi_msg_len < 5)
			goto runt;
		l1tm_response_index("mpw");
		return;
	case MISC_PARAM_READ:
		if (rvi_msg_len < 5)
			goto runt;
		l1tm_response_index_val("mpr");
		return;
	case MISC_ENABLE:
		if (rvi_msg_len < 5)
			goto runt;
		l1tm_response_index("me");
		return;
	default:
		print_etm_pkt_raw("TM unknown");
	}
}

cmd_tmpkt(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);
	return(0);
}

void
send_etm_cmd(buf, len)
	u_char *buf;
{
	int i, c;

	buf[0] = RVT_TM_HEADER;
	c = 0;
	for (i = 1; i <= len; i++)
		c ^= buf[i];
	buf[i] = c;
	send_pkt_to_target(buf, len + 2);
}