view rvinterf/etmsync/l1tmops.c @ 469:fd4af8023ce6

CHANGES: null pointer passing fixes documented
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 11 Feb 2019 22:51:17 +0000
parents 4469d73bbc60
children 4694c7686ccd
line wrap: on
line source

/*
 * In this module we implement the functions that access the L1TM operations
 * which we are going to use in fc-tmsync and fc-readcal.
 */

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "pktmux.h"
#include "tm3.h"
#include "l1tm.h"
#include "exitcodes.h"

extern u_char rvi_msg[];
extern int rvi_msg_len;

do_tms(arg)
{
	u_char cmdpkt[5];

	cmdpkt[1] = TM_MODE_SET;
	cmdpkt[2] = arg;
	cmdpkt[3] = arg >> 8;
	etm_pkt_exch(cmdpkt, 3);
	if (rvi_msg[3]) {
		fprintf(stderr, "target error %u in response to tms\n",
			rvi_msg[3]);
		return(ERROR_TARGET);
	}
	if (rvi_msg_len != 5) {
		fprintf(stderr, "target error: tms response wrong length\n");
		return(ERROR_TARGET);
	}
	return(0);
}

do_rfpr(index, retp)
	u_short *retp;
{
	u_char cmdpkt[5];

	cmdpkt[1] = RF_PARAM_READ;
	cmdpkt[2] = index;
	cmdpkt[3] = index >> 8;
	etm_pkt_exch(cmdpkt, 3);
	if (rvi_msg[3]) {
		fprintf(stderr, "target error %u in response to rfpr\n",
			rvi_msg[3]);
		return(ERROR_TARGET);
	}
	if (rvi_msg_len != 8) {
		fprintf(stderr, "target error: rfpr response wrong length\n");
		return(ERROR_TARGET);
	}
	if (rvi_msg[4] != index) {
		fprintf(stderr, "target error: rfpr response wrong index\n");
		return(ERROR_TARGET);
	}
	*retp = rvi_msg[5] | (rvi_msg[6] << 8);
	return(0);
}

do_rfpw(index, value)
{
	u_char cmdpkt[7];

	cmdpkt[1] = RF_PARAM_WRITE;
	cmdpkt[2] = index;
	cmdpkt[3] = index >> 8;
	cmdpkt[4] = value;
	cmdpkt[5] = value >> 8;
	etm_pkt_exch(cmdpkt, 5);
	if (rvi_msg[3]) {
		fprintf(stderr, "target error %u in response to rfpw\n",
			rvi_msg[3]);
		return(ERROR_TARGET);
	}
	if (rvi_msg_len != 6) {
		fprintf(stderr, "target error: rfpw response wrong length\n");
		return(ERROR_TARGET);
	}
	if (rvi_msg[4] != index) {
		fprintf(stderr, "target error: rfpw response wrong index\n");
		return(ERROR_TARGET);
	}
	return(0);
}

do_rftr(index, table, size)
	u_char *table;
{
	u_char cmdpkt[4];

	cmdpkt[1] = RF_TABLE_READ;
	cmdpkt[2] = index;
	etm_pkt_exch(cmdpkt, 2);
	if (rvi_msg[3]) {
		fprintf(stderr, "target error %u in response to rftr\n",
			rvi_msg[3]);
		return(ERROR_TARGET);
	}
	if (rvi_msg_len < size + 6) {
		fprintf(stderr, "target error: rftr response too short\n");
		return(ERROR_TARGET);
	}
	if (rvi_msg[4] != index) {
		fprintf(stderr, "target error: rftr response wrong index\n");
		return(ERROR_TARGET);
	}
	bcopy(rvi_msg + 5, table, size);
	return(0);
}

do_ttr(index, buf)
	u_char *buf;
{
	u_char cmdpkt[4];

	cmdpkt[1] = TX_TEMPLATE_READ;
	cmdpkt[2] = index;
	etm_pkt_exch(cmdpkt, 2);
	if (rvi_msg[3]) {
		fprintf(stderr, "target error %u in response to ttr\n",
			rvi_msg[3]);
		return(ERROR_TARGET);
	}
	if (rvi_msg_len != 38) {
		fprintf(stderr, "target error: ttr response wrong length\n");
		return(ERROR_TARGET);
	}
	if (rvi_msg[4] != index) {
		fprintf(stderr, "target error: ttr response wrong index\n");
		return(ERROR_TARGET);
	}
	bcopy(rvi_msg + 5, buf, 32);
	return(0);
}