view rvinterf/tmsh/audioresp.c @ 964:a96cb97b66a2

ringtools/imy: fix duplicate definition of tdma_durations[] The bug was reported by Vadim Yanitskiy <fixeria@osmocom.org>, although the present fix is slightly different from the contributed patch: because main.c doesn't need this tdma_durations[] array at all, let's simply remove the reference to this array from main.c rather than turn it into an extern. I no longer remember my original thought flow that resulted (by mistake) in tdma_durations[] being multiply defined in main.c and durations.c. My intent might have been to define all globals in main.c and have the reference in durations.c be an extern - and I missed that extern - but without clear memory, I have no certainty. In any case, having this data array defined in the same module that fills it (durations.c) is sensible, so let's make it the new way.
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 31 Aug 2023 19:38:18 +0000
parents ce7479d28b02
children
line wrap: on
line source

/*
 * In this module we are going to implement the handling of ETM_AUDIO responses.
 */

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

extern u_char rvi_msg[];
extern int rvi_msg_len;

static void
aul_aus_response(op)
	char *op;
{
	char buf[80];

	if (rvi_msg_len != 6) {
		sprintf(buf, "%s response wrong length", op);
		print_etm_pkt_raw(buf);
		return;
	}
	if (rvi_msg[3])
		sprintf(buf, "%s error %u (0x%02X)", op,
			rvi_msg[3], rvi_msg[3]);
	else
		sprintf(buf, "%s OK", op);
	async_msg_output(buf);
}

static void
aur_response()
{
	char buf[80], *dp;
	unsigned i, j, l, size;

	if (rvi_msg_len < 7) {
tooshort:	print_etm_pkt_raw("aur response too short");
		return;
	}
	if (rvi_msg[3]) {
		if (rvi_msg_len == 7) {
			sprintf(buf, "aur %u error %u (0x%02X)", rvi_msg[5],
				rvi_msg[3], rvi_msg[3]);
			async_msg_output(buf);
		} else
			print_etm_pkt_raw("aur long error response");
		return;
	}
	if (rvi_msg_len < 8)
		goto tooshort;
	size = rvi_msg_len - 7;
	sprintf(buf, "aur %u: %u byte%s", rvi_msg[5], size,
		size != 1 ? "s" : "");
	async_msg_output(buf);
	for (i = 0; i < size; ) {
		l = size - i;
		if (l > 16)
			l = 16;
		sprintf(buf, "offset %02X:", i);
		dp = index(buf, '\0');
		for (j = 0; j < l; j++) {
			if (j == 0 || j == 8)
				*dp++ = ' ';
			sprintf(dp, " %02X", rvi_msg[i + 6]);
			i++;
			dp += 3;
		}
		async_msg_output(buf);
	}
}

static void
auw_response()
{
	char buf[80];

	if (rvi_msg_len != 7) {
		print_etm_pkt_raw("auw response wrong length");
		return;
	}
	if (rvi_msg[3])
		sprintf(buf, "auw %u error %u (0x%02X)", rvi_msg[5],
			rvi_msg[3], rvi_msg[3]);
	else
		sprintf(buf, "auw %u OK", rvi_msg[5]);
	async_msg_output(buf);
}

void
etm_audio_msg_rx()
{
	switch (rvi_msg[4]) {
	case 'L':
		aul_aus_response("aul");
		return;
	case 'S':
		aul_aus_response("aus");
		return;
	case 'R':
		aur_response();
		return;
	case 'W':
		auw_response();
		return;
	default:
	unknown:
		print_etm_pkt_raw("ETM_AUDIO");
	}
}