view simtool/opldump.c @ 103:3477438b5706 default tip

new fc-simtool command script: oper-sim-test
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 06 Aug 2022 16:34:43 +0000
parents ddd767f6e15b
children
line wrap: on
line source

/*
 * This module implements the opl-dump command,
 * a companion command to pnn-dump.
 */

#include <sys/types.h>
#include <stdio.h>
#include "simresp.h"
#include "curfile.h"
#include "file_id.h"

select_ef_opl()
{
	int rc;

	rc = select_op(DF_GSM);
	if (rc < 0)
		return(rc);
	rc = select_op(EF_OPL);
	if (rc < 0)
		return(rc);
	rc = parse_ef_select_response();
	if (rc < 0)
		return(rc);
	if (curfile_structure != 0x01) {
		fprintf(stderr, "error: EF_OPL is not linear fixed\n");
		return(-1);
	}
	if (curfile_record_len < 8) {
		fprintf(stderr,
"error: EF_OPL record length is less than the spec minimum of 8 bytes\n");
		return(-1);
	}
	return(0);
}

static void
dump_record(recno, outf)
	unsigned recno;
	FILE *outf;
{
	char ascbuf[8];

	decode_plmn_3bytes(sim_resp_data, ascbuf, 0);
	fprintf(outf, "#%u: %s %02X%02X-%02X%02X %u\n", recno, ascbuf,
		sim_resp_data[3], sim_resp_data[4], sim_resp_data[5],
		sim_resp_data[6], sim_resp_data[7]);
}

cmd_opl_dump(argc, argv, outf)
	char **argv;
	FILE *outf;
{
	int rc;
	unsigned recno;

	rc = select_ef_opl();
	if (rc < 0)
		return(rc);
	for (recno = 1; recno <= curfile_record_count; recno++) {
		rc = readrec_op(recno, 0x04, curfile_record_len);
		if (rc < 0)
			return(rc);
		if (check_simresp_all_blank())
			continue;
		dump_record(recno, outf);
	}
	return(0);
}