view loadtools/simup.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 02490e26f53d
children
line wrap: on
line source

/*
 * This module implements the stage in fc-simint where the sim-up
 * command is fed to simagent and the ATR response is parsed.
 */

#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

extern int sim_voltage_mode_1v8;

#define	MAX_ATR_BYTES	33

u_char sim_atr[MAX_ATR_BYTES];
unsigned sim_atr_len;

static
sim_up_callback(line)
	char *line;
{
	char *cp;

	puts(line);
	if (strncmp(line, "ATR:", 4))
		return(1);
	sim_atr_len = 0;
	for (cp = line + 4; *cp; cp += 3) {
		if (cp[0] != ' ' || !isxdigit(cp[1]) || !isxdigit(cp[2])) {
			fprintf(stderr,
				"error: invalid ATR line from simagent\n");
			return(1);
		}
		if (sim_atr_len >= MAX_ATR_BYTES) {
			fprintf(stderr,
				"error: ATR from simagent is too long\n");
			return(1);
		}
		sim_atr[sim_atr_len++] = decode_hex_byte(cp + 1);
	}
	return(0);
}

void
do_sim_up()
{
	char *targv[3];

	printf("Bringing up SIM interface at %s V\n",
		sim_voltage_mode_1v8 ? "1.8" : "3.0");
	targv[0] = "sim-up";
	targv[1] = sim_voltage_mode_1v8 ? "1.8" : "3";
	targv[2] = 0;
	tpinterf_make_cmd(targv);
	if (tpinterf_send_cmd() < 0)
		exit(1);
	if (tpinterf_capture_output(20, sim_up_callback))
		exit(1);
	if (!sim_atr_len) {
		fprintf(stderr, "error: no ATR returned from simagent\n");
		exit(1);
	}
}