view simtool/opldump.c @ 119:0ac0aee0df11

fc-uicc-tool: remaining PIN commands from fc-simtool
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 19 Feb 2021 23:42:18 +0000
parents 440a4582d2a5
children 52c0da56e979
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"

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_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);
	}
	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);
}